3 Replies Latest reply on Oct 12, 2016 6:56 AM by Nilesh Patel

    Show properties of selected part configuration in assembly..

    Hrituc Alexandru

      Hi,

      How can modify this macro written by Keith Rice to work only for selected part configuration?

        • Re: Show properties of selected part configuration in assembly..
          Keith Rice

          I don't understand what you mean by "selected part configuration". Are you saying you only want the message box to display the custom properties of the current configuration? Or that you only want it to display configuration-specific custom properties? Or something else?

           

          Keith Rice

          SolidWorks API Training and Services

          • Re: Show properties of selected part configuration in assembly..
            Nilesh Patel

            Hi Hrituc,

             

            Are you trying to get configuration specific properties of the part configuration referenced in the assembly document? If yes, then try following codes:

             

            Dim swApp As SldWorks.SldWorks

            Dim swModel As SldWorks.ModelDoc2

            Dim swSelMgr As SldWorks.SelectionMgr

            Dim SelObj As Object

            Dim swComp As SldWorks.Component2

            Dim swCompModel As SldWorks.ModelDoc2

            Dim swCustPropMgr As SldWorks.CustomPropertyManager

            Dim sActiveConfigName As String

            Dim nProp As Integer

            Dim vPropNames As Variant

            Dim valOut As String

            Dim resValOut As String

            Dim i As Integer

             

             

            Sub main()

             

                Set swApp = Application.SldWorks

                Set swModel = swApp.ActiveDoc

              

                If swModel Is Nothing Then

                    swApp.SendMsgToUser "No document open."

                    Exit Sub

                End If

              

                Set swSelMgr = swModel.SelectionManager

              

                If swSelMgr.GetSelectedObjectCount2(-1) = 0 Then

                    swApp.SendMsgToUser "Please select a component or face of the component."

                    Exit Sub

                End If

              

                If swSelMgr.GetSelectedObjectType3(1, -1) <> swSelFACES And swSelMgr.GetSelectedObjectType3(1, -1) <> swSelCOMPONENTS Then

                    swApp.SendMsgToUser "Please select a component or face of the component."

                    Exit Sub

                End If

              

                Set SelObj = swSelMgr.GetSelectedObject6(1, -1)

                If TypeOf SelObj Is SldWorks.Component2 Then Set swComp = swSelMgr.GetSelectedObject6(1, -1)

                If TypeOf SelObj Is SldWorks.Face2 Then Set swComp = swSelMgr.GetSelectedObjectsComponent3(1, -1)

              

                sActiveConfigName = swComp.ReferencedConfiguration

                Set swCompModel = swComp.GetModelDoc2

                Set swCustPropMgr = swCompModel.Extension.CustomPropertyManager(sActiveConfigName)

                nProp = swCustPropMgr.Count

                vPropNames = swCustPropMgr.GetNames

              

                For i = 0 To nProp - 1

                    swCustPropMgr.Get4 vPropNames(i), False, valOut, resValOut

                    If vPropNames(i) <> "UNIT_OF_MEASURE" Then

                        Debug.Print vPropNames(i) + ": " + resValOut

                    End If

                Next i

              

            End Sub

             

            If you just want to get the custom properties (not configuration properties) of the part then replace "Set swCustPropMgr = swCompModel.Extension.CustomPropertyManager(sActiveConfigName)" with "Set swCustPropMgr = swCompModel.Extension.CustomPropertyManager(Empty)"

             

            I have tried it and works OK for me.

             

            Regards,