Changing Part's configuration properties macros code.

Library for macros
sandile942@gmail.com
Posts: 1
Joined: Mon Feb 20, 2023 8:21 am
Answers: 0

Changing Part's configuration properties macros code.

Unread post by sandile942@gmail.com »

This is the code to change configuration properties of every part in an assemby. But the code doesn't seem to make any changes to the parts, what could be the problem?

Sub AddConfigPropertyToAssembly(filePath As String, propertyName As String, propertyValue As String)
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim longstatus As Long
Dim longwarnings As Long

Set swApp = Application.SldWorks
Set swModel = swApp.OpenDoc6(filePath, swDocASSEMBLY, swOpenDocOptions_Silent, "", longstatus, longwarnings)

If longstatus <> 0 Then
Dim swAssembly As SldWorks.AssemblyDoc
Set swAssembly = swModel

Dim vChildComp As Variant
vChildComp = swAssembly.GetComponents(False)

For i = 0 To UBound(vChildComp)
Dim swChildComp As SldWorks.Component2
Set swChildComp = vChildComp(i)

Dim swChildModel As SldWorks.ModelDoc2
Set swChildModel = swChildComp.GetModelDoc2

Dim swCustPropMgr As SldWorks.CustomPropertyManager
Set swCustPropMgr = swChildModel.Extension.CustomPropertyManager("")

swCustPropMgr.Add2 propertyName, swCustomInfoType_Part, propertyValue

swChildModel.EditRebuild3
swChildModel.Save
Next

MsgBox "Custom property added successfully to all parts in the assembly."
Else
MsgBox "Could not open file. Check the file path." & vbNewLine & _
"Status: " & longstatus & vbNewLine & _
"Warnings: " & longwarnings
End If
End Sub

Sub Main()
Dim filePath As String
filePath = InputBox("Enter the path of the SolidWorks assembly file:")

Dim propertyName As String
propertyName = InputBox("Enter the property name:")

Dim propertyValue As String
propertyValue = InputBox("Enter the property value:")

Call AddConfigPropertyToAssembly(filePath, propertyName, propertyValue)
End Sub
Post Reply