6 Replies Latest reply on Jun 18, 2013 11:20 AM by Vincent Piazza

    Getting Configuration Specific Description Instead of Default Part Description

    Vincent Piazza

      Hello,

       

      As the title says, I have a macro that, among other things, gets the description for the part. The only problem is that sometimes one of the parts will have a different description under one of the referenced configurations tab than the one that appears on the default tab. The macro is getting the default part description when I would like it to get the desciption that is under the referenced configuration tab.

       

      Here is the function that is currently getting me the descriptions:

       

       

      Private Function GetCustomProperty(myComp As IComponent2, myProp As String) As String

          Dim myDoc As ModelDoc2

          Dim sa As Variant

          Dim i As Integer

          Dim myVal As String

          Dim myValOut As String

          Dim myMgr As ICustomPropertyManager

          Dim retB As Boolean

       

          Set myDoc = myComp.GetModelDoc2

          If myDoc Is Nothing Then Exit Function 'This will happen if you load your assembly lightweight

          Set myMgr = myDoc.Extension.CustomPropertyManager("")

          GetCustomProperty = ""

          sa = myMgr.GetNames

          If IsEmpty(sa) Then Exit Function

          For i = 0 To UBound(sa)

              If sa(i) = myProp Then

                  retB = myMgr.Get4(sa(i), False, myVal, myValOut)

                  

                  GetCustomProperty = myValOut

                  Exit Function

              End If

          Next

      End Function

       

      I can post more code if need be.

        • Re: Getting Configuration Specific Description Instead of Default Part Description
          Simon Turner

          Change

          Set myMgr = myDoc.Extension.CustomPropertyManager("")

          to

          Set myMgr = myDoc.Extension.CustomPropertyManager(refConfigName)

            • Re: Getting Configuration Specific Description Instead of Default Part Description
              Vincent Piazza

              Thanks for your reply. When I replace

              Set myMgr = myDoc.Extension.CustomPropertyManager("")

              to

              Set myMgr = myDoc.Extension.CustomPropertyManager(refConfigName)

              I get the variable not set error.

               

              If I Dim refConfigName as string, the code executes, but it's still not getting the correct description. I tried the same with ConfigName and I get the same results.

               

              If it helps at at all, I'm exporting this data to excel and here is the line that does this:

               

              xlsheet.Range("E" & xlCurRow).value = GetCustomProperty(swComp, "Description")

                • Re: Getting Configuration Specific Description Instead of Default Part Description
                  Simon Turner

                  You need to set refConfigName to the name of the configuration you are interested in.

                  For example:

                  Dim refConfigName as string

                   

                  refConfigName = myComp.ReferencedConfiguration

                    • Re: Getting Configuration Specific Description Instead of Default Part Description
                      Vincent Piazza

                      I'm trying to retrofit it, but it still isn't working as intended. It runs, but nothing populates for description. Hopefully you can help. I'm calling this function within a loop like so:

                       

                       

                      Components = swAssembly.GetComponents(0)

                       

                       

                      'Loop to populate excel spreadsheet

                      For Each Component In Components

                          Set swComp = Component

                       

                          If swComp.GetSuppression <> 0 Then 'And Not swComp.IsHidden(True)

                       

                                  Bodies = swComp.GetBodies2(0)

                                  RetBool = MassProp.AddBodies(Bodies)

                                  CenOfM = MassProp.CenterOfMass

                                  path = swComp.GetPathName  'Grabs whole path name of part to later be edited

                                  extensionLen = Len(".sldxxx") 'Used to get the part name (meant to exclude the part extension from name

                                  Name = Mid(path, InStrRev(path, "\") + 1, Len(path) - InStrRev(path, "\") - extensionLen)

                                  refConf = Mid(swComp.ReferencedConfiguration, 1, 4)  'Used to get the referenced configuration name

                                  refConfigName = swComp.ReferencedConfiguration

                       

                       

                       

                                  xlsheet.Range("B" & xlCurRow).value = Name

                                  xlsheet.Range("E" & xlCurRow).value = GetCustomProperty(swComp, refConfigName)

                                  xlsheet.Range("F" & xlCurRow).value = GetCustomProperty(swComp, "Material")

                        End If

                       

                      Next Component

                       

                       

                      Note that I've deleted some irrelavent parts of the code.

                       

                      And here's the function:

                       

                       

                      'This function is used to get access to the custom property manager in order to get the part description, number, etc. to be used in the subroutine SwExtractData

                       

                      Private Function GetCustomProperty(swComp As IComponent2, swProp As String) As String

                          Dim myDoc As ModelDoc2

                          Dim sa As Variant

                          Dim i As Integer

                          Dim myVal As String

                          Dim myValOut As String

                          Dim myMgr As ICustomPropertyManager

                          Dim retB As Boolean

                          Dim ConfigName As String

                          Dim refConfigName As String

                       

                          'Set refConfigName = swComp.ReferencedConfiguration

                       

                          Set myDoc = swComp.GetModelDoc2

                          If myDoc Is Nothing Then Exit Function 'This will happen if you load your assembly lightweight

                          Set myMgr = myDoc.Extension.CustomPropertyManager(refConfigName)

                          GetCustomProperty = ""

                          sa = myMgr.GetNames

                          If IsEmpty(sa) Then Exit Function

                          For i = 0 To UBound(sa)

                              If sa(i) = swProp Then

                                  retB = myMgr.Get4(sa(i), False, myVal, myValOut)

                       

                                  GetCustomProperty = myValOut

                                  Exit Function

                              End If

                          Next

                      End Function