Hi there,
I'm adding configurations to some parts, during which I'm trying to insert a configuration-specific "Description" custom property depending on the value of Description in the code below. However, the correct values are not being written to the new configuration, and instead it's as if the first configuration's property is being added to all of the configurations. I've inserted the bolded lines to try and connect to the active configuration after it's created. I'm not really sure if the problem lies here.
I'd appreciate any help.
On a side note, when I comment out the first lines and uncomment the next two I get a host of weird errors. Does anyone know the reason for this?
Many thanks,
Chris
Dim swApp As Object
Dim swModel As Object
'Dim swApp As SldWorks.SldWorks
'Dim swModel As SldWorks.ModelDoc2
Dim swConfigMgr As SldWorks.ConfigurationManager
Dim swConfig As SldWorks.Configuration
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim retVal As Long
Dim boolstatus As Boolean
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Dim myModelView As Object
Dim Description() As String
Set swConfigMgr = swModel.ConfigurationManager
Set swConfig = swConfigMgr.ActiveConfiguration
Set swCustPropMgr = swConfig.CustomPropertyManager
' Get File Name without grade as first part of Description text
Dim PartName As String
PartName = Left(swModel.GetTitle, InStrRev(swModel.GetTitle, ",")) & " "
' Apply new configurations
ReDim Description(3)
Description(0) = "Grade A4"
Description(1) = "Grade 8.8"
Description(2) = "Grade 10.9"
Description(3) = "Grade 12.9"
Dim i As Integer
For i = 0 To UBound(Description)
boolstatus = swModel.AddConfiguration2(Description(i), "", "-", False, False, False, True, 1048833)
Set swConfig = swConfigMgr.ActiveConfiguration
Set swCustPropMgr = swConfig.CustomPropertyManager
Debug.Print PartName & Description(i) ' <--- should be configuration "Description" text
swCustPropMgr.Add2 "Description", swCustomInfoText, PartName & Description(i)
Next i
swModel.DeleteConfiguration2 "Default"
End Sub
SolidworksApi macros