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
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..!
Thank you for quick response, however:
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?
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?
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!!!
I am adding one exapmle ..
Above Picture is mine Feature manager Tree..and i am going to select Boss-Extrude1 and Boss-Extrude2 and getting Cutlist folder name.
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
Set subfeat = subfeat.GetNextFeature
Set Feat = Feat.GetNextFeature()
Hope this will help you..i wrote this in hurry.please let me know if you have any other query....
I tried to use the macro you wrote, when I select a face or feature in a weldment part the Cutlist folder containing that body is not highlighted. Can you explain the work flow that needs to be followed in order to get the expected result.
P.S: I dont have any experience with macros or VB although would like to learn it. Any help in this regards too will be much appreciated.
Please try this macro
When you select a body in the part and run the macro corresponding cutlist folder is highlighted in feature tree of the part
CutListFolderFromBody.swp.zip 10.4 KB
Thank you very much guys, both answers were correct by its own way, from both of them I've learned much about traversing cutlist items.
Thanks a lot for the macro, it does a great job. I wanted to know one more thing, can the same macro be modified to identify the cutlist folder when a body or face of the body is selected in GA. I understand that the selection in the feature manager cannot point towards the cutlist folder since a single weldment feature can contain multiple length weldment members grouped in different cutlist folder.
Thanks in advance.