|
. @: b, o* x5 x# h3 G' y无法打开装配体文件,是因为你把文件类型判定的语句放在循环外了,挪到do...loop内即可,那个call语句调用了什么?用不上可以先屏蔽。( Y/ X( N: [- D: G
经过测试,下面的程序可正常打开零件和装配体
X6 E, x! M' H3 H" e! }+ l& i; K& v* c9 g& r5 T# L+ f- d5 ~
' ******************************************************************************; }8 y, A P4 \/ E# A5 l
' 读取指定目录下的Prt/asm文件,关闭, M/ F% l* A0 h- C
' ******************************************************************************: N3 r) X5 b( F) j
Dim swApp As Object+ ~8 f, r4 Y" f
& U. `0 b# Y+ @1 \, M9 w/ Q! M, |Dim Part As Object
2 j. b1 ?$ [8 a/ fDim boolstatus As Boolean
% y' b7 r& _+ e, U+ J& M& c5 lDim longstatus As Long, longwarnings As Long. [. m8 C1 m) P, ~' T, U3 l5 B
'Dim sldPath As String
3 {8 V. _2 M& Y! U% L! U" x kConst sldPath As String = "E:\3Dtest\BOM1\" '设定目录' H3 @$ D6 R3 f: h7 ]# m
4 m4 Q5 b& n2 @4 d$ u7 L3 cSub main()
8 l4 R1 Q9 ~! o, X5 E' P" \8 t; [$ D4 P( L1 p
Set swApp = _% _: R4 {( d& \: g% W+ i( I3 L
Application.SldWorks
4 A7 ]3 Q. l k* q4 r* c# o Set Part = swApp.ActiveDoc; B; b' o( [6 j3 S/ F% I
3 c/ f0 j& u; F! }) M
swFileName = Dir(sldPath & "*.sld*") $ X5 n* w P' ~2 x' @
/ d' ?% w4 n! M- y0 Y) ]$ R
Do While swFileName <> ""% ^( c u. g, Q0 ] n4 F
Set swApp = Application.SldWorks
, @$ K+ z$ ^) U% C If UCase(Right(swFileName, 3)) = "PRT" Then swFileTYpe = 1
: f. Q- ~# ]5 J4 v) x6 M If UCase(Right(swFileName, 3)) = "ASM" Then swFileTYpe = 2
+ l. N/ s/ T' H
3 i% g" h; F3 @# Q& M Set swModel = swApp.OpenDoc6(sldPath & swFileName, swFileTYpe, swOpenDocOptions_Silent, "", longstatus, longwarnings)" c5 K/ G8 \+ s3 T6 \
Set Part = swApp.ActiveDoc& J, [! b0 E3 ^) k
'Call plmain/ n+ u5 e) k) R5 ` j$ J4 o
'Part.Save '保存1 R& Y# M; n8 n+ e: d) A6 c- h* R
swApp.CloseDoc (swFileName) '关闭零件
. R; F% s$ m, v2 c8 {5 o# X: v* v If swFileName = "" Then Exit Do:! {% r/ ]- \# \& ?; n- `
swFileName = Dir '搜寻下一个零件档案名称( d# U3 Y7 Z3 g- t1 ?
Loop '循环搜寻
6 [! U3 L) a Q4 _8 c4 O4 v y+ }# i0 @8 y; [5 v
End Sub' [% v* t6 u, i: f
. ~* I# X# f8 U1 H* l0 P
) @8 \0 K: }4 i0 X" S8 B; D
|
|