2 Replies Latest reply: Dec 13, 2012 1:05 AM by Chris Day

    Adding configuration-specific custom properties

    Chris Day

      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

        • Re: Adding configuration-specific custom properties
          Artem Taturevych

          Try this modified macro:

           

          Dim swApp As SldWorks.SldWorks

          Dim swModel As SldWorks.ModelDoc2

          Dim swCustPropMgr As SldWorks.CustomPropertyManager

           

          Sub main()

             

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Dim Description() As String

                 

              ' 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)

                  swModel.AddConfiguration3 Description(i), "", "-", 0

                  Set swCustPropMgr = swModel.Extension.CustomPropertyManager(Description(i))

                  Debug.Print PartName & Description(i)

                  swCustPropMgr.Add2 "Description", swCustomInfoText, PartName & Description(i)

                  swCustPropMgr.Set "Description", PartName & Description(i)

             Next i

            

              swModel.DeleteConfiguration2 "Default"

          End Sub

          ______________________

          Regards,

          Artem Taturevych

          Application Engineer at Intercad

          http://intercad.com.au/

          Tel: +61 2 9454 4444