Split macro
-
- Posts: 9
- Joined: Mon Apr 15, 2024 2:03 am
- x 5
- x 3
Split macro
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?
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?
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.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:)
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
Re: Split macro
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
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
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.
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
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.
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
-
- Posts: 16
- Joined: Wed Feb 01, 2023 5:10 pm
- x 1
Re: Split macro
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.
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 81 times
-
- JUNK.SLDPRT
- (147.27 KiB) Downloaded 75 times
Re: Split macro
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.
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.
- Attachments
-
- SliceMacroFeature.swp
- (157 KiB) Downloaded 80 times
-
- Posts: 9
- Joined: Mon Apr 15, 2024 2:03 am
- x 5
- x 3
Re: Split macro
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
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
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
Replace with this
I've added the default values and made it modify the current body. Macro is attached.
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)
Code: Select all
Set swCopyBody = swBody
- Attachments
-
- SliceMacroFeature.swp
- (122 KiB) Downloaded 47 times
-
- Posts: 9
- Joined: Mon Apr 15, 2024 2:03 am
- x 5
- x 3
Re: Split macro
Thanks again. Absolutely brilliant!
-
- Posts: 9
- Joined: Mon Apr 15, 2024 2:03 am
- x 5
- x 3
Re: Split macro
Hi AlexAlexB 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 thisReplace with thisCode: Select all
Set swCopyBody = swBody.Copy2(False)
I've added the default values and made it modify the current body. Macro is attached.Code: Select all
Set swCopyBody = swBody
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:)
Re: Split macro
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.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:)
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 37 times
-
- Posts: 9
- Joined: Mon Apr 15, 2024 2:03 am
- x 5
- x 3
Re: Split macro
Impressive Sir, very impressive!
@AlexB We owe you several cold beers, should you ever come to Denmark.
@AlexB We owe you several cold beers, should you ever come to Denmark.
Re: Split macro
Happy to help. And Denmark has been on the long list of places I'd like to visitMonstrum 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.
-
- Posts: 9
- Joined: Mon Apr 15, 2024 2:03 am
- x 5
- x 3
Re: Split macro
@AlexB Just a thought: Instead of making the macro "intelligent" enough to know the right direction to split, wouldn't it be easier to just split in both directions? I suppose it wouldn't make the macro that much slower. It works quite fast already.