Split macro

Library for macros
Monstrum Mathias
Posts: 8
Joined: Mon Apr 15, 2024 2:03 am
Answers: 0
x 5
x 3

Split macro

Unread post by Monstrum Mathias »

Hi all.

I've been struggling with a library feature for some time now that can split 80mm, 120mm, 160mm, 200mm etc shapes in to 40mm thick bodies we feed to a router. They need to be precisely 40mm for the nesting program to work. While library features works like a charm for cutting and numbering our router parts, it's just impossible to work with for this splitting purpose, due to the features working on other bodies than intended and only "non boolean features" allowed. Does anyone have any experience with using macros for splitting? I can only see examples of splitting and saving to new parts but I need the bodies to stay in the document. Is macro the way to go you think?
image.png
image.png
by AlexB » Mon Nov 18, 2024 8:52 am
Monstrum Mathias wrote: Mon Nov 18, 2024 6:34 am Hi Alex

Just out of curiosity, how does the macro in fact split? There doesn't seem to be any split-feature involved in the code. It does produce some strange results from time to time, like extra identically named split-bodies. Unfortunately it also seems to do a complete rebuilt renaming all faces making further features down the line full of errors(cant find face). Apart from that it's extremely useful:)
It uses the IModeler interface to create a plane that is parallel to the initially selected face. Then, there is a call to the IModeler to perform an operation on the provided input bodies and I chose to use it to cut the input body with the input surface. Using this method is much faster than using the built in split feature because it works directly with the bodies without any of the overhead that the built in split feature creates.

Since it's creating bodies inside the macro feature, it's likely necessary to assign an ID to the edges/faces that are new or changed. I didn't go as far as to do that with my initial example code though so it may behave a bit odd. I've added a bit of code based on an example to add an ID to all faces and edges.

Edit: Was able to modify and attach macro
Go to full post
User avatar
Dwight
Posts: 274
Joined: Thu Mar 18, 2021 7:02 am
Answers: 2
x 2
x 220

Re: Split macro

Unread post by Dwight »

Maybe you could do this with an "Intersect" feature. To do that, you'd make a stack of blocks for every other layer then run Intersect. One does have to select which bodies to delete manually.

It would be nice if using the Combine feature with the "common" operation type had the option of not merging bodies. That could be closer to what you want.

It would also be nice if every cut operation had the option to retain all the bodies.

The Split feature always did seem to me to be a bad implementation. Why complicate it with part export? I don't understand what the check boxes mean; I just check them all and it seems to work.

Dwight
User avatar
AlexB
Posts: 501
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 28
x 269
x 445

Re: Split macro

Unread post by AlexB »

I could see this working as a macro feature, but that is probably one of the more complex things to develop with the API.
My thought is that you could take the the starting face and the thickness as an input and it could copy/cut the body to create the desired features. This is certainly an interesting proposal.
User avatar
SPerman
Posts: 2056
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 14
x 2227
x 1878
Contact:

Re: Split macro

Unread post by SPerman »

What about using an Extrude Cut, Thin Feature? I don't use library features, so I'm not sure if this is feasible or not.

image.png
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
chancegarrison
Posts: 16
Joined: Wed Feb 01, 2023 5:10 pm
Answers: 0
x 1

Re: Split macro

Unread post by chancegarrison »

In SW2025 this will be much easier because you can then pattern reference geometry. Attached is a library feature to help automate this a bit in the meantime.

Drag the feature into your part, select the top plane or face of the part, then the bottom plane or face, then any plane that runs through the entirety of the part you are trying to split. Usually one of the three primary planes will be fine. Run the split command and control select all planes, done.
Attachments
split planes.SLDLFP
(154.39 KiB) Downloaded 66 times
JUNK.SLDPRT
(147.27 KiB) Downloaded 64 times
User avatar
AlexB
Posts: 501
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 28
x 269
x 445

Re: Split macro

Unread post by AlexB »

I put something together as a proof of concept. It's still buggy and needs work but it shows about how this can function. I'm not going to have time to work on it for some time so it's here for anyone else that wants to tinker.

There isn't currently an edit for the control, you'd have to delete and re-add the feature to change the settings and face selection.

The feature copies the body that the selected face belongs to and slices it in the normal direction of that face using the thickness setting to determine how many bodies to make. The original body isn't modified, but the new sliced bodies are created in place along with it.

Disclaimer: It's not clean code, I got it to the point where it functions.
Slice Macro Feature.gif
Attachments
SliceMacroFeature.swp
(157 KiB) Downloaded 65 times
Monstrum Mathias
Posts: 8
Joined: Mon Apr 15, 2024 2:03 am
Answers: 0
x 5
x 3

Re: Split macro

Unread post by Monstrum Mathias »

Thanks everybody for taking an interest to my niche problem.
And thank you AlexB. You hit the nail on the head with this one! SliceMacroFeature does exactly what I'm after. Though there is no edit it seems to function really well with construction history, so it's not really needed, I guess. Also It only slices the selected body so no need for isolating anything.
This could be a real time saver in my company. I'd be really happy to modify it slightly, if there is another kind soul out there with a better understanding of programming language than me:
Get rid of the dialog box and the reverse direction option, set it to 40mm by default and delete the original body.
That would be AWESOME!
Thanks again Alex
User avatar
AlexB
Posts: 501
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 28
x 269
x 445

Re: Split macro

Unread post by AlexB »

The reverse direction button was put in because there are scenarios where it tries to start splitting things in the wrong direction. I didn't make it smart enough to determine the direction itself but it's possible to do that.

To set a default value, you can modify the form in the VBA editor to set the text box value and radio button selections so that they start at the ones you want.

To cut the current body and not make a new body, you can change the following line in the BuildMacroFeature function
Remove this

Code: Select all

Set swCopyBody = swBody.Copy2(False)
Replace with this

Code: Select all

Set swCopyBody = swBody
I've added the default values and made it modify the current body. Macro is attached.
Attachments
SliceMacroFeature.swp
(122 KiB) Downloaded 36 times
Monstrum Mathias
Posts: 8
Joined: Mon Apr 15, 2024 2:03 am
Answers: 0
x 5
x 3

Re: Split macro

Unread post by Monstrum Mathias »

Thanks again. Absolutely brilliant!
Monstrum Mathias
Posts: 8
Joined: Mon Apr 15, 2024 2:03 am
Answers: 0
x 5
x 3

Re: Split macro

Unread post by Monstrum Mathias »

AlexB wrote: Tue Nov 12, 2024 8:24 am The reverse direction button was put in because there are scenarios where it tries to start splitting things in the wrong direction. I didn't make it smart enough to determine the direction itself but it's possible to do that.

To set a default value, you can modify the form in the VBA editor to set the text box value and radio button selections so that they start at the ones you want.

To cut the current body and not make a new body, you can change the following line in the BuildMacroFeature function
Remove this

Code: Select all

Set swCopyBody = swBody.Copy2(False)
Replace with this

Code: Select all

Set swCopyBody = swBody
I've added the default values and made it modify the current body. Macro is attached.
Hi Alex

Just out of curiosity, how does the macro in fact split? There doesn't seem to be any split-feature involved in the code. It does produce some strange results from time to time, like extra identically named split-bodies. Unfortunately it also seems to do a complete rebuilt renaming all faces making further features down the line full of errors(cant find face). Apart from that it's extremely useful:)
User avatar
AlexB
Posts: 501
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 28
x 269
x 445

Re: Split macro

Unread post by AlexB »

Monstrum Mathias wrote: Mon Nov 18, 2024 6:34 am Hi Alex

Just out of curiosity, how does the macro in fact split? There doesn't seem to be any split-feature involved in the code. It does produce some strange results from time to time, like extra identically named split-bodies. Unfortunately it also seems to do a complete rebuilt renaming all faces making further features down the line full of errors(cant find face). Apart from that it's extremely useful:)
It uses the IModeler interface to create a plane that is parallel to the initially selected face. Then, there is a call to the IModeler to perform an operation on the provided input bodies and I chose to use it to cut the input body with the input surface. Using this method is much faster than using the built in split feature because it works directly with the bodies without any of the overhead that the built in split feature creates.

Since it's creating bodies inside the macro feature, it's likely necessary to assign an ID to the edges/faces that are new or changed. I didn't go as far as to do that with my initial example code though so it may behave a bit odd. I've added a bit of code based on an example to add an ID to all faces and edges.

Edit: Was able to modify and attach macro
Attachments
SliceMacroFeature.swp
(155.5 KiB) Downloaded 27 times
Monstrum Mathias
Posts: 8
Joined: Mon Apr 15, 2024 2:03 am
Answers: 0
x 5
x 3

Re: Split macro

Unread post by Monstrum Mathias »

Impressive Sir, very impressive!
@AlexB We owe you several cold beers, should you ever come to Denmark.
User avatar
AlexB
Posts: 501
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 28
x 269
x 445

Re: Split macro

Unread post by AlexB »

Monstrum Mathias wrote: Fri Nov 22, 2024 2:09 am Impressive Sir, very impressive!
@AlexB We owe you several cold beers, should you ever come to Denmark.
Happy to help. And Denmark has been on the long list of places I'd like to visit UU
Post Reply