跳到主要内容

将SOLIDWORKS文件特定的自定义属性复制到配置

该宏使用SOLIDWORKS API将所有文件特定的自定义属性复制到活动配置的属性中。

文件的自定义选项卡中的属性{ width=640 }

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swCustPrpMgr As SldWorks.CustomPropertyManager
Dim swConfCustPrpMgr As SldWorks.CustomPropertyManager

Sub main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

If Not swModel Is Nothing Then

Set swCustPrpMgr = swModel.Extension.CustomPropertyManager("")

Dim vNames As Variant
Dim vTypes As Variant
Dim vValues As Variant
swCustPrpMgr.GetAll vNames, vTypes, vValues

Dim activeConfName As String
activeConfName = swModel.ConfigurationManager.ActiveConfiguration.Name

Set swConfCustPrpMgr = swModel.Extension.CustomPropertyManager(activeConfName)

Dim i As Integer

For i = 0 To UBound(vNames)
swConfCustPrpMgr.Add2 vNames(i), vTypes(i), vValues(i)
swConfCustPrpMgr.Set vNames(i), vValues(i)
Next

Else

MsgBox "请打开零件或装配体"

End If

End Sub