2 Replies Latest reply on Aug 26, 2015 9:24 AM by Patrick Jensen

    .UserAssigned Not Working

    Patrick Jensen

      I have an assembly and I want to find all the parts in it that have assigned mass properties via API. I know it has assigned mass parts, but they do not show up with this code:

       

      Sub AssignedMassProperties()

       

      Dim swApp As SldWorks.SldWorks

      Dim swModel As SldWorks.ModelDoc2

      Dim swSelMgr As ISelectionMgr

      Dim swComp  As SldWorks.Component2

      Dim swCompModel As ModelDoc2

      Dim swGroup As Variant

      Dim swMass As SldWorks.MassProperty

      Set swApp = GetObject(, "SldWorks.Application")

      Set swModel = swApp.ActiveDoc

      Set swSelMgr = swModel.SelectionManager

       

      swGroup = swModel.GetComponents(False)

       

      For i = 0 To swModel.GetComponentCount(False) - 1

          Set swComp = swGroup(i)

          If swComp.IsHidden(True) = False Then

              Set swCompModel = swComp.GetModelDoc2

              Set swMass = swCompModel.Extension.CreateMassProperty

              If swMass.UserAssigned = True Then

                  Debug.Print swComp.Name

              End If

          End If

          Debug.Print swComp.Name

      Next i

       

       

      End Sub

       

      All the forums I have looked through, this method has seemed to work for them but its is not showing anything for me. I have Solidworks 2012. Any help is appreciated. Thanks