|
本帖最后由 zqzwhj111 于 2020-4-12 11:38 编辑 5 k9 B4 j8 D( a p
* w! S2 i! Z6 ?- `- O8 z* ~
有大佬知道这个程序哪里出问题了吗,替换不了,用visual studio写的,VB语言,SolidWorks版本是2012的; F2 l! t( I+ H5 p2 j+ w
* l+ F& Q; s! p
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click# x+ p- f4 `- l0 Y3 J$ K
Dim swapp As SldWorks.SldWorks6 M3 v8 O" n+ N, _8 {- q* f
Dim modle As SldWorks.ModelDoc2: k9 V7 Y5 B: X$ J
Dim sheet As SldWorks.Sheet* _ X5 `3 Z( @* u! f/ q
Dim sheetpr() As Double8 T4 N+ t1 P8 Y) V1 i" R8 |
swapp = CreateObject("Sldworks.application")' t) S1 g, M `) r8 L, r
6 e" x2 Q) u& A5 E' E J6 l1 I
Dim pathname As String
% k" h, a0 h; E/ R- G pathname = TextBox1.Text '获得文件夹路径
! m4 `; Z. S5 c Dim swpath() As String
' p# q# I+ I4 O* L' ]( E swpath = IO.Directory.GetFiles(pathname, "*.SLDDRW") '筛选图纸文件名' K: t& `* r% Y4 P9 C2 \" Q
For Each strname As String In swpath '列出所有图纸文件名
m7 z. V" B# E, c& i- }- ^% l modle = swapp.OpenDoc(strname, 3) '打开模型+ v& ^4 l4 D4 j$ \6 `) U; \5 i; D
sheet = modle.GetCurrentSheet() '获得当前图纸
2 d/ Z: s+ ~' [- ~- K, L, ? sheetpr = sheet.GetProperties() '获得图纸属性( B- o } E: i* C" [, ? u, S
sheetpr(1) = 12. l; a* r: B) h" u
sheetpr(1) = 122 V$ l O: W2 ?- ~
sheet.SetProperties(sheetpr(0), sheetpr(1), sheetpr(2), sheetpr(3), sheetpr(4), sheetpr(5), sheetpr(6))
1 V/ z O$ ]& ?& l3 V2 [ If sheetpr(5) = 210 / 1000 Then
, x' @- _7 Q; l& \8 I/ b sheet.SetTemplateName("E:\图纸格式文件替换工程图模板时使用\A4替换.slddrt")
# h% ]; U. F) L7 i+ d ElseIf sheetpr(5) = 420 / 1000 Then
! V0 e5 ~7 e! L$ H! ^ sheet.SetTemplateName("E:\图纸格式文件替换工程图模板时使用\A3替换.slddrt")/ }8 d1 y) L& q
End If/ n4 k5 o! L9 V5 F2 X) J$ ^/ ]! ]
modle.Save3(1, swerrors, swwarings) w/ p6 v, M3 o7 h
swapp.CloseDoc(strname.Substring(InStrRev(strname, "\"), Len(strname) - InStrRev(strname, "\")))
$ I: {/ i% Y. y, U, q! I Next
3 [5 U3 {$ T% ]) r. K9 ]0 VEnd Sub
& w" k: _1 r! r& O# Q' G1 Q8 S J3 m+ r7 Z6 |
|
|