1 Reply Latest reply on Jun 9, 2017 3:36 PM by Samantha Szkirpan

    Get body from Cut List

    Samantha Szkirpan

      Hello

      I am using VBA to program this macro.

      I am trying to navigate the feature tree of a part that has a cut list folder. This folder contains a subweldments folder which contains more cut list folders which each contain what I believe are solid bodies. What I want to do is access the solid bodies in these cut list folders and save them as a parasolid. However I am running into an issue accessing the bodies and I'm not sure what I am doing wrong.

       

      Here is my code, and I would appreciate any help.

       

      Sub weldments()

          Dim swApp As SldWorks.SldWorks

          Dim swModel As SldWorks.ModelDoc2

          Dim swSelMgr As SldWorks.SelectionMgr

          Dim swselObject As Object

          Dim swEnt As SldWorks.Entity

          Dim swComp As SldWorks.Component2

          Dim modelName As String

          Dim material As String

          Dim featName As String

          Dim subName As String

          Dim sub2Name As String

          Dim sub3name As String

          Dim bodyCount As Integer

          Dim swFeat As SldWorks.Feature

          Dim subFeat As SldWorks.Feature

          Dim sub2Feat As SldWorks.Feature

          Dim sub3Feat As Object

          Dim swCustPropMgr As SldWorks.CustomPropertyManager

          Dim dash As String

         

         

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc

          modelName = swModel.GetTitle

          boolstatus = swModel.Extension.SelectByID2("Description", "SUBWELDFOLDER", 0, 0, 0, False, 0, Nothing, 0)

          Set swSelMgr = swModel.SelectionManager

          Set swFeat = swSelMgr.GetSelectedObject(1)

          featName = swFeat.Name

         

          Set subFeat = swFeat.GetFirstSubFeature

          subName = subFeat.Name

          If subFeat.Name = "Sub-weldment1" Then

              Set sub2Feat = subFeat.GetFirstSubFeature

              sub2Name = sub2Feat.GetTypeName

              Do While Not subFeat Is Nothing

              If sub2Feat.Name = "Cut-List-Item2" Then

                  Set swCustPropMgr = sub2Feat.CustomPropertyManager

                  swCustPropMgr.Get4 "DASH", False, Empty, dash

                  swCustPropMgr.Get4 "MATERIAL", False, Empty, material

                  Dim folder As SldWorks.bodyFolder

                  Set folder = sub2Feat.GetSpecificFeature2

                 sub3Feat = sub2Feat.GetBodies

                    ......

       

      Thanks

        • Re: Get body from Cut List
          Samantha Szkirpan

          Update: I have figured out the issue.

           

          Change:

          Dim sub3Feat As Object          to

                         Dim sub3Feat as Variant

          sub3Feat = sub2Feat.GetBodies         to

                         sub3Feat = folder.GetBodies()

           

          I wanted the name of the body so to the end I added:

          sun3name = sub3Feat(0).Name

           

           

          In this case, the "sub3Feat" variable is an array containing the bodies within the cut list folder. In order to access either of those bodies or the properties of them, "sub3Feat" must support an array which is why I changed that variable to a variant, and you need to access the different components within that array by using the traditional numbering at the end ("sub3Feat(0)" accesses the first element of the array. You can use the Locals window within VBA to access the array more thoroughly and see how many elements there are and what information you can get from them.

           

          I hope this helps anyone who has this question.