9 Replies Latest reply on Nov 27, 2015 12:54 PM by Yusuf Dabhiya

    How to get cut list property from body selection

    Dariusz Karcz

      Hello,

       

      I'm trying to write a macro that will do the following:

       

      While working in drawing environment:

       

      1. Select face in view

      2. Open Part that face is belonging

      3. Get the body that own this face

      4. Get Description property for this body (and few other properties) from folder in which this body resides

      5. Export selected face with cutlist properties from step 4.

       

      Currently I'm stuck with: how to get cutlist properties of folder which contains body that is selected by its face.

       

      How to back-traverse from children in cutlist tree up to folder that can have properties pre-written?

       

      Do i need to use IbodyFolder interface? or maybe CustomProperties interface? or maybe I need to traverse whole Design tree by FeatureManager?

        • Re: How to get cut list property from body selection
          Viktor Bovzdarenko

          Firstly all bodies from the cut list should be taken (2014 SOLIDWORKS API Help - Get Solid Bodies from Cut-list Folders and Get Custom Properties Example (VBA) ) and then compare each body name from the cut list with selected body:

          if swCutListBody(i).Name = SelectedBody.Name Then

          • Re: How to get cut list property from body selection
            Raghvendra Bhargava

            you can use something like..

                Set Part = swApp.ActiveDoc

                boolstatus = Part.Extension.SelectByID2("Cut-List-Item1", "SUBWELDFOLDER", 0, 0, 0, False, 0, Nothing, 0)

                Dim feat As Feature

               

                Set feat = Part.SelectionManager.GetSelectedObject6(1, -1)

               

                Dim CustomPropMgr As SldWorks.CustomPropertyManager

                Set CustomPropMgr = feat.CustomPropertyManager

               

                Dim vCustomPropNames As Variant

                vCustomPropNames = CustomPropMgr.GetNames

             

            you can provide loop and can select every cut list folder as feature.

             

            I think it is clear for you..!

            • Re: How to get cut list property from body selection
              Dariusz Karcz

              Thank you for quick response, however:

               

              @ Viktor Bovzdarenko

               

              Ok, i can take all the bodies from cutlist, i can compare theirs names with body that is pre-selected, but it doesn't solve problem with selecting cutlist folder to which selected body belongs, by your method i will get cut list body with same name as selected one, but how to get name of cutlist folder?

               

              @ Raghvendra Bhargava

               

              Yes, it is clear, however, thing is:

               

              By using SelectByID2 I am forced to use names for selecting a feature, in this case its "Cut-List-Item1" and so on, but still, how to get "Cut-List-Item(number)" that contains pre-selected body?

               

              Question remains: how to GET that Cut-List-Item(number) by its children?

               

               

               

               

                • Re: How to get cut list property from body selection
                  Viktor Bovzdarenko

                  CutList body is taken from cutlist folder during traversing; therefore, if conditional statement (swCutListBody(i).Name = SelectedBody.Name) is true then active cutlist folder can be received.

                  Here is an example in C#:

                   

                                 if (swFeat.GetTypeName() == "CutListFolder")

                                  {

                                      object[] swCutListBody = (object[])((IBodyFolder)swFeat.GetSpecificFeature2()).GetBodies();

                                      if (swCutListBody != null)

                                      {

                                          for (int i = 0; i < swCutListBody.Length; i++)

                                          {

                                             if (((IBody2)swCutListBody[i]).Name == SelectedBody.Name)

                                              {

                                                 string CutlistFolderName = swFeat.Name //<=== Cutlist folder name!!!                             

                                              }

                                          }

                                      }

                                  }

                  • Re: How to get cut list property from body selection
                    Raghvendra Bhargava

                    I am adding one exapmle ..

                     

                    Capture.JPG

                     

                    Above Picture is mine Feature manager Tree..and i am going to select Boss-Extrude1 and Boss-Extrude2 and getting Cutlist folder name.

                     

                    Sub main()

                    Dim swApp As Object

                    Dim Part As ModelDoc2

                    Dim boolstatus As Boolean

                    Dim longstatus As Long, longwarnings As Long

                     

                    Set swApp = Application.SldWorks

                    Set Part = swApp.ActiveDoc

                     

                    Dim swmodel As PartDoc

                    Set swmodel = Part

                     

                    Dim vBody As Variant

                    vBody = swmodel.GetBodies2(swAllBodies, False)

                     

                    Dim swBody As Body2

                    Dim i As Integer

                     

                    For i = 0 To UBound(vBody)

                        Set swBody = vBody(i)

                        swBody.Select2 False, Nothing '<<<<<<<<<<<<SELECTING BODY

                       

                        Dim Feat As Feature

                        Set Feat = Part.FirstFeature

                       

                        While Not Feat Is Nothing

                            If Feat.GetTypeName2 = "SolidBodyFolder" Then

                           

                                Dim subfeat As SldWorks.Feature

                                Set subfeat = Feat.GetFirstSubFeature

                       

                                    While Not subfeat Is Nothing

                                        Dim BodyFolder As SldWorks.BodyFolder

                                        Set BodyFolder = subfeat.GetSpecificFeature2

                               

                                        Dim BodyFolderTypeE As Long

                                        BodyFolderTypeE = BodyFolder.Type

                                            If BodyFolderTypeE = swWeldmentCutListFolder Then

                                                Dim vBodies As Variant

                                                vBodies = BodyFolder.GetBodies

                                               

                                                Dim CutListBdy As Body2

                                               

                                                Dim j  As Integer

                                               

                                                For j = 0 To UBound(vBodies)

                                                    Set CutListBdy = vBodies(j)

                                                    Dim CutListFldNme  As String

                                                    If CutListBdy.Name = swBody.Name Then CutListFldNme = subfeat.Name: GoTo line1 '<<GETTING CUTLIST FOLDER NAME

                                                Next j

                                            End If

                                       

                                            Set subfeat = subfeat.GetNextFeature

                                        Wend

                                End If

                       

                                 Set Feat = Feat.GetNextFeature()

                           Wend

                    line1:

                    Next i

                    End Sub

                     

                    Hope this will help you..i wrote this in hurry.please let me know if you have any other query....