|
|
发表于 2016-4-29 16:39:54
|
显示全部楼层
来自: 中国台湾
/ w, i$ Z" B3 ?( z要達到批量新增的話,如下代碼:, \) x1 L5 j5 ^; |* y* f- P
% L( O3 j) z: M, h$ t* z5 e. J
- Dim swApp As SldWorks.SldWorks4 F ?, E; H- \9 n+ v* X* n
- Dim swModel As SldWorks.ModelDoc
5 ]6 x2 O, d% y7 u u - Dim sFileName As String
' b# \9 w- G6 y2 ] - Dim path As String. W- h1 K7 L+ a5 T4 l. ^) \4 ~
- Dim nErrors As Long
5 A @/ K, h. | - Dim nWarnings As Long9 b2 Y+ ^. K4 Z; e
- Sub main()6 e5 ~" i8 o, ?* d& L
- Set swApp = Application.SldWorks0 m L# y$ ~- y$ e: C" W
- path = InputBox("Enter a folder path containing any Solidworks files (For example '' C:\test '' )", "Parts path location") '鍵入路徑
: j, [& s& Y2 R" e4 ~! Z8 F - If Right(path, 1) <> "" Then path = path & ""
6 ^' [$ p! T, z+ a& U - sFileName = Dir(path & "*.sldprt") '可以換成 *.sldasm or *.slddrw f% {3 V9 ~2 g {+ b1 ^3 F
- Do Until sFileName = ""3 u7 y. ?5 s- e, v* b/ e: M, D& m
-
I) E/ N+ A9 }6 @, a. g5 B. W - Set swModel = swApp.OpenDoc6(path + sFileName, swDocPART, swOpenDocOptions_Silent, "", nErrors, nWarnings) '可以換成 swDocASSEMBLY or swDocDRAWING
, U( J, G2 y8 L0 P5 I3 g - Set swModel = swApp.ActiveDoc
% M0 r8 P+ D. w7 A -
/ H8 Y0 o. U0 a+ a1 A5 e- S - retva6 = swModel.DeleteCustomInfo("Number")
0 b0 `) D3 d1 s M' Y: ] - retva6 = swModel.AddCustomInfo3("", "Number", swCustomInfoText, Left(sFileName, 10))' l0 D) V1 ]0 t% _6 j
- retva6 = swModel.DeleteCustomInfo("Name")+ F! O& i8 \8 x7 ^1 \
- retva6 = swModel.AddCustomInfo3("", "Name", swCustomInfoText, Right(sFileName, Len(sFileName) - 10))9 q6 L R( E) b8 _
- $ M, b8 p3 z( q5 ]$ ^
- swModel.Save
# l# n g6 _% f1 t$ A! D - swApp.CloseDoc (sFileName)
3 G8 J- M$ ~+ g Y+ { - sFileName = Dir
- h* R9 n" @# @8 ` - Loop
8 B: D/ z* T; B6 Y' s - MsgBox "DONE!"' g; J, a/ v" ]3 k2 S/ b
- End Sub6 P' e4 d+ Z$ U) F, g
复制代码 4 z% \+ {5 X1 j3 b0 V( r1 w
* _( P% `* C6 i! { \+ h5 f0 g, o5 g( t- z; q
|
|