Page 1 of 1

Split macro

Posted: Tue Oct 29, 2024 3:38 am
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

Re: Split macro

Posted: Fri Nov 01, 2024 10:15 am
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

Re: Split macro

Posted: Fri Nov 01, 2024 10:22 am
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.

Re: Split macro

Posted: Fri Nov 01, 2024 10:35 am
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

Re: Split macro

Posted: Mon Nov 11, 2024 1:16 pm
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.

Re: Split macro

Posted: Mon Nov 11, 2024 4:04 pm
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

Re: Split macro

Posted: Tue Nov 12, 2024 3:39 am
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

Re: Split macro

Posted: Tue Nov 12, 2024 8:24 am
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.

Re: Split macro

Posted: Tue Nov 12, 2024 8:46 am
by Monstrum Mathias
Thanks again. Absolutely brilliant!