安装第三方插件:
" d7 Z7 J5 j! Z+ r( P8 I( p例如,使用SolidKits BOMs高级BOM工具或SWTDO插件。
5 x3 k- u% u2 ]' E' q5 s下载并安装插件,按照插件的安装指南进行操作。5 H% }( h2 Z- r0 l( B0 D' Q
使用插件功能:
! O8 S) @0 r* t4 P( K9 s& u* K2 T打开插件,选择“批量写入属性”功能。, h$ f% y; B. J
选择需要处理的零件文件或文件夹,设置需要添加的属性名称和值。
: B ?4 E }- s7 \- N$ {5 _+ ^$ r0 E; M( d8 }0 o2 y# H% q
还有这个宏命令是AI生成的,不保证有用。
! x& j' Z4 @5 r0 m$ U- qDim swApp As SldWorks.SldWorks
" n+ E4 D, |9 e1 o% ^- E rDim swModel As SldWorks.ModelDoc2
?* k$ M7 i6 D8 S' S& r/ r) cDim swPart As SldWorks.Part
3 B, R/ a3 h" @) }9 gDim massprops As Variant
. u4 B- \ ~: b* XDim status As Long
& b5 G i- c& X# v$ J! ^9 dDim length As Double
) {; j/ ^9 ~# j. P) EDim width As Double
' @! l- O- D f- UDim height As Double2 `5 N3 ~' t! d" L
& G/ G1 @4 l0 }6 b
Sub main()
6 i& j& k1 }6 a% U0 E) _" H) b Set swApp = Application.SldWorks+ O7 S. E% h7 G" v! L/ P: m
Set swModel = swApp.ActiveDoc
, M5 @, O5 ]% m& j$ T W Set swPart = swModel.Part
: Z; L: k; U1 ]8 I, `) X7 Z7 n& H
' 获取零件的外形尺寸
$ p" B2 M) K( ]$ t" p) L massprops = swPart.GetMassProperties(1, status, True)
$ X$ s0 \, h1 |$ R length = massprops(0)1 W/ o* C$ h1 {! z w7 F1 M. A1 ^, H
width = massprops(1)$ F. e) u; I# {
height = massprops(2)
3 f1 i- q/ c1 Q' }% F/ V0 M* `! H q& S& G5 j
' 添加自定义属性
8 I( @3 k- j0 Z9 o) x$ [ swModel.Extension.AddCustomProperty3("长度", swCustomInfoText, CStr(length), swCustomPropertyReplaceValue)
E: [" y. y: J! W+ Z; T% t swModel.Extension.AddCustomProperty3("宽度", swCustomInfoText, CStr(width), swCustomPropertyReplaceValue)
! \5 r5 V% b! [% F5 f4 j O2 c swModel.Extension.AddCustomProperty3("高度", swCustomInfoText, CStr(height), swCustomPropertyReplaceValue)
- h1 J# w+ ~4 i; w- ^; B, P# |
* w0 z3 N: t0 k% @ t7 E; H. k ' 保存文件, q% p) j/ Y! {
swModel.Save% @: G; C2 F/ L+ w7 L
End Sub. @7 t9 W/ j0 r
点击“执行”按钮,开始批量处理文件。 |