4 Replies Latest reply on Aug 16, 2016 8:02 AM by Deepak Gupta

    BOM Quantity - cannot set!

    Aaron Torberg

      Hey all I am trying to write a simple macro to prompt a user for a BOM quatity value, create the property and set the BOM Quantity drop down to the newly created field.  So here is what I have:

       

      Sub main()

       

       

          Dim swApp As Object

          Dim swModel As Object

          Dim ModelTitle As String

          Dim ModelPath As String

          Dim UserQTY As Integer

          Dim Longstatus As Long

         

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc

         

          UserQTY = 8

          ModelTitle = Left(swModel.GetTitle, (InStr(1, swModel.GetTitle, ".") - 1)) & "_QTY" & UserQTY

          ModelPath = Replace(swModel.GetPathName(), swModel.GetTitle, "")

          Longstatus = swModel.AddCustomInfo("BOM QTY", "Number", UserQTY)

          swModel.Extension.CustomPropertyManager.Set "UNIT_OF_MEASURE", "BOM QTY"

       

       

      End Sub

       

      but I cannot get it to set "unit_of_measure" to the property BOM QTY!  What am I doing wrong...?  TIA!

        • Re: BOM Quantity - cannot set!
          Peter Brinkhuis

          The first clue that I found is that the AddCustomInfo method is superseded, even though it still works. Maybe you should be creating an extension variable and then a custom property manager variable and use that to get or set custom properties. Now you're skipping a few steps, I don't know if that matters or not.

           

          I'll keep you posted if I have anything that works.

           

          Edit: I'm starting to understand what you want to do and I found the topic you got your code from. I am still unable to set this protected custom property called UNIT_OF_MEASURE, although I am getting a zero returned which would mean the value is set. Setting a non-existent custom property also returns a zero though, that should return a -1.

           

          I am also have trouble setting the value by hand. I can't seem to change its value from " - none - " to something else.

            • Re: BOM Quantity - cannot set!
              Aaron Torberg

              Peter - Thanks for setting me on the correct path!  This ended up being to working solution.  Thanks for the help!

               

              Sub main()

               

               

                  Dim swApp As Object

                  Dim swModel As Object

                  Dim ModelTitle As String

                  Dim ModelPath As String

                  Dim UserQTY As Integer

                  Dim Longstatus As Long

                  Dim swModelDocExt As ModelDocExtension

                  Dim swCustProp As CustomPropertyManager

                  Dim bool As Boolean

                  Dim val As String

                  Dim valout As String

                 

                  Set swApp = Application.SldWorks

                  Set swModel = swApp.ActiveDoc

                  Set swModelDocExt = swModel.Extension

                 

                  val = ""

                  valout = ""

                  UserQTY = 12

                  ModelTitle = Left(swModel.GetTitle, (InStr(1, swModel.GetTitle, ".") - 1)) & "_QTY" & UserQTY

                  ModelPath = Replace(swModel.GetPathName(), swModel.GetTitle, "")

                  Set swCustProp = swModelDocExt.CustomPropertyManager("")

                  Longstatus = swCustProp.Add3("BOM QTY", 3, UserQTY, 1)

                  bool = swCustProp.Get4("UNIT_OF_MEASURE", False, val, valout)

               

               

                  Debug.Print "Value:                    " & val

                  Debug.Print "Evaluated value:          " & valout

                  Debug.Print "Up-to-date data:          " & bool

                  Debug.Print "Title:                    " & ModelTitle

                  Debug.Print "Path:                     " & ModelPath

                 

                  Longstatus = swCustProp.Add3("UNIT_OF_MEASURE", 30, "BOM QTY", 1)

                  bool = swCustProp.Get4("UNIT_OF_MEASURE", False, val, valout)

                 

                  Debug.Print "Value:                    " & val

                  Debug.Print "Evaluated value:          " & valout

                  Debug.Print "Up-to-date data:          " & bool

                 

              End Sub

                • Re: BOM Quantity - cannot set!
                  Peter Brinkhuis

                  Glad you were able to get it working. So you actually have to add the custom property, even though it theoretically already exists?

                   

                  There used to be a reply from Deepak here that said there was no API code available to set this.

                   

                  Edit: Got it to work as well I had to define both custom properties as text though. It still feels inconsistent when I look at the returned Longstatus value. Sometimes it returns 1 after the unit_of_measure property is added, sometimes zero. It seems to remember the value, even though the custom property that is refers to is removed.