3 Replies Latest reply on Oct 29, 2013 7:52 AM by Deepak Gupta

    Check if a custom properties is there and end macro if empty

    Steven Smith

      Hi folks,

       

      I’m looking for a line of code that will check to see if a specific custom property is there and if it’s not end the macro process.

      I already have the macro I want set up, but just need this last line (it's actually going to be the first line) that will check to see if the field exists, if not then the macro doesnt need to run.

        • Re: Check if a custom properties is there and end macro if empty
          Deepak Gupta

          Try this:

           

          Option Explicit

              Dim swApp               As SldWorks.SldWorks

              Dim swModel             As SldWorks.ModelDoc2

             

          Sub main()

           

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

           

              If swModel.CustomInfo("Description") = "" Then

           

              MsgBox "Property Doesn't Exists OR No Value is Assigned"

              End If

           

          End Sub

           

          This will check if there is property or not. And if there is property but no value has been assigned then also will pop up a message. In case there is space in the value, then macro will no show any message.

            • Re: Check if a custom properties is there and end macro if empty
              Steven Smith

              Sorry Deepak, I had ment to ask if the "Property Name" Existed not the "Value/Expression".

               

              Sorry for the confusion.

                • Re: Check if a custom properties is there and end macro if empty
                  Deepak Gupta

                  Ok, sorry for misunderstanding. Try this:

                   

                  Sub main()

                   

                      Dim swApp                           As SldWorks.SldWorks

                      Dim swModel                         As SldWorks.ModelDoc2

                      Dim vCustInfoNameArr                As Variant

                      Dim vCustInfoName                   As Variant

                   

                      Set swApp = Application.SldWorks

                      Set swModel = swApp.ActiveDoc

                   

                         vCustInfoNameArr = swModel.GetCustomInfoNames2("")

                         For Each vCustInfoName In vCustInfoNameArr       

                          If vCustInfoName <> "Description" Then        ' Change property name here

                          Debug.Print  "Description property doesn't exists"

                          End If       

                          Next      

                  End Sub