1 Reply Latest reply on Apr 2, 2014 2:17 PM by Jesse Seger

    Opening each part of an assembly?

    Todd Bennett

      From an assembly, I need to get the bounding box information from each part and place it into a custom property (i.e. Xdim, Ydim, Zdim).  The assemblies are imported files and will not have any property values; the custom properties do exist but the value will be 0.  Not being much of a programmer, I will glean as much as I can from other macros and "Frankenstein" them together.

       

      The first hurdle is how to open each part one by one.  I have this snippet (below) that finds the mass properties of each part.   One problem is it only looks at the active configuration of each part.

       

      How do I get this to look at the configuration active in the assembly?

       

       

      - - - - - - - - - - - - - -

      Dim swApp As SldWorks.SldWorks
      Dim swAssy As SldWorks.AssemblyDoc

       

      - - - - - - - - - - - - - -

      Sub main()

       

          Set swApp = Application.SldWorks
         
          Set swAssy = swApp.ActiveDoc
         
          Dim vComps As Variant
          Dim swComp As SldWorks.Component2
          Dim swCompModel As SldWorks.ModelDoc2
          Dim swMassProps As SldWorks.MassProperty
          Dim i As Integer
         
          vComps = swAssy.GetComponents(False)
         
          For i = 0 To UBound(vComps)
             
              Set swComp = vComps(i)
              Debug.Print swComp.Name2
              Debug.Print swComp.GetPathName
              Set swCompModel = swComp.GetModelDoc2
             
              If Not swCompModel Is Nothing Then
                  Set swMassProps = swCompModel.Extension.CreateMassProperty()
                  'swMassProps.AddBodies (swComp.GetBodies2(swBodyType_e.swSolidBody))
                  Debug.Print swMassProps.Mass
              Else
                  Debug.Print "Failed to get model doc"
              End If
             
              Debug.Print "- - - - - - - - - - - - - - - - - -"
          Next
         
      End Sub
      - - - - - - - - - - - - - -