Page 1 of 1

Select cut lists folder and insert 3D bounding box.

Posted: Fri Dec 23, 2022 11:26 am
by Hansjoerg
Hello all,

I am trying to select the cutting list folder as parts of a larger macro and run the function to create the 3D bounding boxes. Exactly the way I have been doing it by hand.
Image

Probably due to lack of sufficient knowledge I don't manage to select with the macro the cutlists folder

In the old Solidworks forum I found the following macro https://forum.solidworks.com/thread/201686

The macro works after a few minor adjustments, but with the difference to the manual execution that the bounding box is inserted in all cutting list elements, even in the structural elements where it is not required.

When executed manually over the topmost cut list folder, the bounding box is added only to the elements that do not contain structural elements.
Image

Does anyone have a tip for me on how to program the macro to achieve the same result as when executed manually.

Re: Select cut lists folder and insert 3D bounding box.

Posted: Fri Dec 23, 2022 12:30 pm
by JSculley
Here's a minimal example that will put a bounding box around every cut list item that isn't a structural member.

Code: Select all

Dim swApp As SldWorks.SldWorks
Dim fMgr As FeatureManager
Dim mDoc As ModelDoc2
Dim mExt As ModelDocExtension
Dim fCount As Integer
Dim retval As Boolean
Sub main()
    Set swApp = Application.SldWorks
    Set mDoc = swApp.ActiveDoc
    Set mExt = mDoc.Extension
    Set fMgr = mDoc.FeatureManager
    fCount = fMgr.GetFeatureCount(False)
    Dim nextFeature As Feature
    Dim featureObjectArray As Variant
    featureObjectArray = fMgr.GetFeatures(False)
    For i = 0 To fCount - 1
        Set nextFeature = featureObjectArray(i)
        If nextFeature.GetTypeName2() = "CutListFolder" Then
            Dim folder As BodyFolder
            Set folder = nextFeature.GetSpecificFeature2
            If (folder.GetCutListType <> swCutListType_e.swWeldmentCutlist) Then
                retval = nextFeature.Select2(False, -1)
                mExt.Create3DBoundingBox
            End If
        End If
    Next
End Sub

Re: Select cut lists folder and insert 3D bounding box.

Posted: Tue Dec 27, 2022 5:22 am
by Hansjoerg
@JSculley
thank you very much, that's exactly what I was looking for