Select cut lists folder and insert 3D bounding box.

Programming and macros
User avatar
Hansjoerg
Posts: 108
Joined: Thu Apr 01, 2021 4:17 pm
Answers: 3
x 72
x 55

Select cut lists folder and insert 3D bounding box.

Unread post 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.
by JSculley » Fri Dec 23, 2022 12:30 pm
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
Go to full post
All the "good" news about SWX makes me feel like I'm driving a truck with two trailers straight into a dead end.
User avatar
JSculley
Posts: 586
Joined: Tue May 04, 2021 7:28 am
Answers: 54
x 7
x 821

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

Unread post 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
User avatar
Hansjoerg
Posts: 108
Joined: Thu Apr 01, 2021 4:17 pm
Answers: 3
x 72
x 55

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

Unread post by Hansjoerg »

@JSculley
thank you very much, that's exactly what I was looking for
All the "good" news about SWX makes me feel like I'm driving a truck with two trailers straight into a dead end.
Post Reply