2 Replies Latest reply on Apr 14, 2016 8:09 AM by Tim Lewis

    Get Custom Property of Selected Part

    Tim Lewis

      I'm trying to get a specific custom property of a selected part.  I found this discussion that claims to provide the answer, but when I try to use that in my code, I get errors: Use API to obtain custom properties of currently selected part in an assembly.

       

      Here's the code I'm currently using:

       

      Sub OpenSource()     Dim lSuccess As Long, swModel As ModelDoc2, SourceURL As String         Dim selMgr As SelectionMgr, Path As String         With Application.SldWorks.ActiveDoc         With .SelectionManager             If .GetSelectedObjectCount2(-1) <> 0 And _                .GetSelectedObjectType3(1, -1) <> 0 Then                 SourceURL = .GetSelectedObjectsComponent4(1, -1).GetModelDoc2.Extension.CustomPropertyManager("").Get("Source URL")             End If         End With     End With End Sub

       

      This produces the following error on line 10:

       

      Screenshot_7.jpg

       

      Also, it would be very beneficial to know if the properties of a part set to lightweight are visible to the API.

       

      Any help anyone can provide would be greatly appreciated.  I'm using SolidWork Professional 2015 on a Windows 7 machine.

        • Re: Get Custom Property of Selected Part
          Viktor Bovzdarenko

          Hi Tim

          The code works perfectly. Make sure that you work in assembly environment and select a component before running this code.

          Also, the code had quite many not used variables, which I deleted to simplify the macro:

          Sub main()

              With Application.SldWorks.ActiveDoc.SelectionManager

                  If .GetSelectedObjectCount2(-1) <> 0 And .GetSelectedObjectType3(1, -1) <> 0 Then

                      Dim SourceURL As String

                      SourceURL = .GetSelectedObjectsComponent4(1, -1).GetModelDoc2.Extension.CustomPropertyManager("").Get("DrawnBy")

                      Debug.Print SourceURL

                  End If

              End With

          End Sub

           

          Regards

          Viktor