Split macro

Library for macros
Monstrum Mathias
Posts: 6
Joined: Mon Apr 15, 2024 2:03 am
Answers: 0
x 4
x 2

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 » 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.
Go to full post
User avatar
Dwight
Posts: 273
Joined: Thu Mar 18, 2021 7:02 am
Answers: 2
x 2
x 219

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: 498
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 28
x 266
x 444

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: 2040
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 14
x 2212
x 1863
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: 9
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 46 times
JUNK.SLDPRT
(147.27 KiB) Downloaded 45 times
User avatar
AlexB
Posts: 498
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 28
x 266
x 444

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 46 times
Monstrum Mathias
Posts: 6
Joined: Mon Apr 15, 2024 2:03 am
Answers: 0
x 4
x 2

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: 498
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 28
x 266
x 444

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 17 times
Monstrum Mathias
Posts: 6
Joined: Mon Apr 15, 2024 2:03 am
Answers: 0
x 4
x 2

Re: Split macro

Unread post by Monstrum Mathias »

Thanks again. Absolutely brilliant!
Post Reply