第一步:将后缀为“.slddrt”的图纸格式文件放入此文件夹内,此图纸格式文件是自己需要的新图框。
7 W/ }& ]' Q' O5 f第二步:将要替换模板的文件放入一个文件夹,将文件夹地址粘贴到相应的地方(程序中有备注)* d% }. I' [" d2 O# O$ |" D6 e
第三步:用宏命令运行程序:; B/ r( ~) g) S% q
5 N2 `# H- C: j7 ]" [1 N1 C* V' _8 s第一步的附图:
" Y% \. ?# G8 Y/ X! G
i6 O+ ^. ^+ e$ u( q: @" j程序:
5 b9 R7 K$ Y4 |# N) Y' ******************************************************************************! A9 t; ~9 Z0 X8 d- D7 k/ i- j2 D
' C:\Users\Administrator\AppData\Local\Temp\swx8592\Macro1.swb - macro recorded on 06/26/19 by Administrator& I/ E% l8 d$ ^" D
' ******************************************************************************
: F @; v ]0 {! KDim swApp As Object
' N# n* ]% G2 Y. o, S0 f! }8 a9 D# k8 I
Dim Part As Object$ ?- s3 h+ N% W- L# y+ `8 [# q
Dim boolstatus As Boolean
/ @+ g, G$ Z# g2 @0 n* W/ v* t- L3 J
8 _2 i0 J4 ~( R, @! E) r( Z1 d" r* o( b. z
/ {" W9 K; ]# M% [6 e
8 ~& ` Y- x/ e$ R0 m" k
$ |" U1 y, g& o" V$ DDim longstatus As Long, longwarnings As Long, myPath$, myFile$# G0 q9 V0 R! O) w: J! p; w
Dim i As Integer
/ o4 }4 o9 F; w; a, e6 W3 s l- c6 N, O& b1 Y" s" y
Sub Main()
" n* p) A* s) x/ M" z0 ~* Y# J1 F: ]# k7 v
3 _( H, D7 k7 J4 ^- f- M. k
' I( b0 J, Z6 Y$ O" Q/ y! iSet swApp = _
; x" W3 ?! \% L- S4 y+ I/ `Application.SldWorks8 M4 v0 j5 l) g% k' x
myPath = "C:\Users\Administrator\Desktop\新建文件夹 (2)\" '把文件路径定义给变量,第二步中的路径填到此处。# e6 h+ j. T8 X0 {/ e& \: f) _
myFile = Dir(myPath & "*.slddrw") '依次找寻指定路径中的*.文件2 g0 W9 w( ~4 W3 k5 c
i = 0
, B# C: q3 j8 N; u% R$ IDo While myFile <> ""
* b. _, Y. u$ T1 m0 H6 WSet Part = swApp.OpenDoc6(myPath & myFile, 3, 0, "", longstatus, longwarnings)
9 Q/ k; P& p' V4 E) M! r5 C$ {; W- z9 W: ^: C5 t: { L6 y
Set Drawing = swApp.ActiveDoc
8 J1 ~' I- i/ l# TIf Drawing.GetType <> 3 Then Exit Sub
5 z3 t% H ]- x/ YRetoreSheetName = Drawing.GetCurrentSheet.GetName
) q! b9 `, P9 }1 ^SheetName = Drawing.GetSheetNames
7 f1 R/ z& f: ^+ j% T8 r4 m% USheetCount = Drawing.GetSheetCount9 J1 R, a) T) r0 y& c; n! _& P7 K
For i = 0 To SheetCount - 1
! G8 Y) ~4 F B Drawing.ActivateSheet SheetName(i)9 o$ J' Q C0 Q
swTemplate = Drawing.GetCurrentSheet.GetTemplateName/ \3 i) i* `+ A" h# n
swTemplatePath = Split(swTemplate, "")" V6 }7 X* F- w0 [; M& ?
swTemplate = swTemplatePath(UBound(swTemplatePath))
- a6 y* l$ G' A4 y vSheetProps = Drawing.GetCurrentSheet.GetProperties()
0 P- Q* Q* V$ ^) F& L% w9 Y Drawing.SetupSheet4 Drawing.GetCurrentSheet.GetName, 0, 0, vSheetProps(2), vSheetProps(3), vSheetProps(4), "", 1, 1, ""7 \# r' h. ?# X2 o
Drawing.SetupSheet4 Drawing.GetCurrentSheet.GetName, 12, 12, vSheetProps(2), vSheetProps(3), vSheetProps(4), swTemplate, 0, 0, ""
& \1 D Z, k. l vSheetProps = Drawing.GetCurrentSheet.GetProperties()
9 |5 d1 p) I. l2 JNext
# p5 w# x5 R5 o! u/ E) t% tDrawing.ActivateSheet RetoreSheetName) z: ]7 O T# v7 m; l( z0 I
. N; q8 u; W8 w: T) }: J! V$ E0 o7 \$ {Part.Save+ I% C; m* |3 X0 ~3 ?
swApp.CloseDoc myPath & myFile* J5 e+ _4 D1 n4 u K) e& m6 P
: K: i6 W9 {7 F+ J! o9 @! smyFile = Dir '找寻下一个*.文件, D+ h. J4 ^# k! r0 b: q6 u
2 \7 L4 [8 |$ V0 `
Loop
6 J( r& Y4 @" u6 R
, U9 b' F8 U( E: b9 L8 W; U! \, pEnd Sub |