|
本帖最后由 zqzwhj111 于 2020-4-12 11:38 编辑 7 p- w$ g6 A; a
" x% ]7 Y7 O9 h- r& R9 I% Q* K 有大佬知道这个程序哪里出问题了吗,替换不了,用visual studio写的,VB语言,SolidWorks版本是2012的
6 Y2 c! L- H2 U) T5 H' |; O9 |" z! }$ r; i
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click1 ~; P7 Q% o. M
Dim swapp As SldWorks.SldWorks
/ ~/ s/ y: c2 r2 [5 m Dim modle As SldWorks.ModelDoc2
- p! V* d3 J, o Dim sheet As SldWorks.Sheet
6 P* C; ]3 ^# z: e$ X$ V% D Dim sheetpr() As Double
6 F; y/ d+ T/ Y- i# C swapp = CreateObject("Sldworks.application"). t; `2 q' R+ T( ]& u" x7 D) E, J
! x0 W& c, u! C V4 @. v7 I/ o
Dim pathname As String- Q3 A0 C7 r0 ?
pathname = TextBox1.Text '获得文件夹路径
/ h$ t% p, n1 }* t/ W$ p" J' O Dim swpath() As String- d2 ?( o4 V: s9 G! B) d3 a% [
swpath = IO.Directory.GetFiles(pathname, "*.SLDDRW") '筛选图纸文件名. E# |6 N2 l! _' \
For Each strname As String In swpath '列出所有图纸文件名
2 Y4 M' f0 i6 `9 Z7 S. W# \5 ` modle = swapp.OpenDoc(strname, 3) '打开模型
1 \7 P/ G2 k, L1 Y1 ]- v sheet = modle.GetCurrentSheet() '获得当前图纸
- P. k4 G4 B4 A1 G% T sheetpr = sheet.GetProperties() '获得图纸属性3 X8 l* C* j E( X# l7 i+ d/ }* v
sheetpr(1) = 12! G6 C, x7 | p- H6 O1 v1 D
sheetpr(1) = 12
5 a% q. v/ a9 o; y0 x sheet.SetProperties(sheetpr(0), sheetpr(1), sheetpr(2), sheetpr(3), sheetpr(4), sheetpr(5), sheetpr(6))
, X% q: Q+ ^# i3 h! F6 l6 M4 B3 K2 y If sheetpr(5) = 210 / 1000 Then
i. |& _* L( g sheet.SetTemplateName("E:\图纸格式文件替换工程图模板时使用\A4替换.slddrt")
5 k8 v! `# h: P2 ~! o" x0 l2 B1 z ElseIf sheetpr(5) = 420 / 1000 Then7 Z0 b- I" a( A( r! m# l5 R
sheet.SetTemplateName("E:\图纸格式文件替换工程图模板时使用\A3替换.slddrt")
" G. |# |% c$ a1 ] End If5 L- b/ @8 T9 @# e
modle.Save3(1, swerrors, swwarings)
! v. ^6 x _) |) K( v( X# E swapp.CloseDoc(strname.Substring(InStrRev(strname, "\"), Len(strname) - InStrRev(strname, "\")))
' B5 w! J+ P$ v/ ], n Next
" l- T: R0 @% D! \. tEnd Sub
1 p( X- c R% [, n
* D2 g: I4 U- {% h |
|