Option Explicit
% r+ f2 w- @2 s* cDim swApp As SldWorks.SldWorks
4 J% @' l' _& G/ R+ \Dim swModel As ModelDoc2
% `: O- z- F+ T9 ~7 _9 R0 RDim cpm As CustomPropertyManager5 R6 L2 u: s# q# P5 u
Sub main(), n4 V6 K+ ^* A0 v, ?5 O( Q# R+ k
Set swApp = Application.SldWorks
+ [4 L( R$ Z, V! v; D& mSet swModel = swApp.ActiveDoc: z2 I6 l5 F( \+ k8 \" k9 n4 \$ J
Set cpm = swModel.Extension.CustomPropertyManager("")
4 P+ Q$ Z2 ~3 j0 [% {$ kDim path As String, filename As String, partno As String, partname As String, beizhu As String( u. o& n; _/ S2 N- a5 a+ w: U
path = swModel.GetPathName '获得文件路径和文件名称
$ D. A# E9 ~2 H8 [9 M( \5 T, }filename = Mid$(path, InStrRev(path, "\") + 1) ' 获得文件名称及扩展名
. j; M3 \. ?. H3 F3 m$ \filename = Left$(filename, InStrRev(filename, ".") - 1) '移除扩展名- M# p+ c/ `3 y; @" x' y
partno = Left(filename, 10) ' 定义partno等于文件名的前9位; Q5 j' S1 |3 w- T( [
partname = Right(filename, Len(filename) - 10) ' 定义partname等于文件名剩下若干位8 X0 S, W. u" w' ]
cpm.Delete "编码" ' 删除自定义属性“编码”! c( h1 [4 |4 ]* s! n
cpm.Delete "名称" ' 删除自定义属性“名称”
* H3 @+ k7 C" t6 Z g. `1 vcpm.Delete "路径" ' 删除自定义属性“路径”! D' m7 b4 ]' _, ?- F
cpm.Add2 "编码", swCustomInfoText, partno ' 增加自定义属性“编码”: H( p! n' a2 I) j$ f
cpm.Add2 "名称", swCustomInfoText, partname ' 增加自定义属性“名称”: v' x+ U* k! g* D; k
'cpm.Add2 "路径", swCustomInfoText, path '增加自定义属性“路径”
1 t# A* w! V3 @3 x5 P8 V- D+ H ?swModel.Save ' 保存文件6 m6 N! g0 m z( y% [+ I
'swApp.CloseDoc (filename) ' 关闭当前激活文件, N% G: s0 {- F# P( [6 B% F
End Sub
$ c+ k6 c( |; A) L6 v$ k* l以上 是一种宏的利用 你看看吧 |