4 Replies Latest reply on Oct 2, 2014 10:44 AM by Fabrizio Todaro

    Read Custom Property of selected component

    Fabrizio Todaro

      Hello everyone.

      I need a routine to read a property of a selected part in an assembly.

       

      Thanks in advance!

        • Re: Read Custom Property of selected component
          Deepak Gupta

          Try these

           

          Option Explicit

          Sub main()

              Dim swApp                   As SldWorks.SldWorks

              Dim swModel                 As SldWorks.ModelDoc2

              Dim swSelMgr                As SldWorks.SelectionMgr

              Dim swComp                  As SldWorks.Component2

              Dim swCompModel             As SldWorks.ModelDoc2

             

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Set swSelMgr = swModel.SelectionManager

              Set swComp = swSelMgr.GetSelectedObjectsComponent3(1, 0)

              Set swCompModel = swComp.GetModelDoc

             

              Debug.Print "Description = " & swCompModel.CustomInfo("Description") 'Change Property Name here

              swModel.ClearSelection2 True  

             

          End Sub

            • Re: Read Custom Property of selected component
              Fabrizio Todaro

              Hello Gupta,

              the routine does its job.

               

              Thanks!

               

              Now, however, I was born a little problem:

              the property that I have to read to help me must be a number.

              In SolidWorks, however, has this value "CUT@MISURE@ARO-02-210-1001.SLDPRT", which gives me the length of the cut.

              How do I read the number instead of the name of the dimension?

                • Re: Read Custom Property of selected component
                  Deepak Gupta

                  Option Explicit

                  Sub main()

                      Dim swApp                   As SldWorks.SldWorks

                      Dim swModel                 As SldWorks.ModelDoc2

                      Dim swSelMgr                As SldWorks.SelectionMgr

                      Dim swComp                  As SldWorks.Component2

                      Dim swCompModel             As SldWorks.ModelDoc2

                      Dim swCustProp              As CustomPropertyManager

                      Dim val                     As String

                      Dim valout                  As String

                   

                      Set swApp = Application.SldWorks

                      Set swModel = swApp.ActiveDoc

                      Set swSelMgr = swModel.SelectionManager

                      Set swComp = swSelMgr.GetSelectedObjectsComponent3(1, 0)

                      Set swCompModel = swComp.GetModelDoc

                     

                      Set swCustProp = swCompModel.Extension.CustomPropertyManager("")

                      swCustProp.Get4 "Description", False, val, valout 'Change property name here

                     

                      Debug.Print "Value:                    " & val

                      Debug.Print "Evaluated value:          " & valout

                   

                      swModel.ClearSelection2 True

                     

                     

                  End Sub