Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
Undoing operations
Hi,
I have flat parts where I extrude / offset edges for splitting.
The image below shows a typical part which started as a solid, where the holes have been cut by extruding the outer edges, offsetting them, splitting the original part with the offset edges and then deleting the inner bodies created by the split to form the holes and then adding fillets.
Depending on how the parts are constructed, the required directions of the extrudes and offsets vary, currently I have two Boolean UI parameters for selecting the correct combination which is a bit clunky.
Ideally I'd like to be able to step through the four direction combinations in code until I hit the one which is correct.
My question is, is it possible to undo an operation(s) so I can retry or would I need to create duplicate parts on which to test the directions? Or is there another way?
Thank you.
Best Answers
-
NeilCooke Moderator, Onshape Employees Posts: 5,696
Yes, you can use startFeature and abortFeature/endFeature. You can see a really good example in the Fill pattern feature which check that a pattern does not self-intersect before applying the pattern.
Senior Director, Technical Services, EMEAI0 -
Caden_Armstrong Member Posts: 188 PRO
@graham_lock You could check a qcreatedby("splitPart") → isQueryEmpty
If the split happens, the query shouldn't be empty.www.smartbenchsoftware.com --- fs.place --- Renaissance
Custom FeatureScript and Onshape Integrated Applications0 -
NeilCooke Moderator, Onshape Employees Posts: 5,696
All arrow notation does is replace the first parameter in the following function. So it won’t work in this case.
Senior Director, Technical Services, EMEAI0 -
Caden_Armstrong Member Posts: 188 PRO
my bad, I was typing on a phone and assumed you wouldn't literally copy paste the code. I left syntax as homework for the reader.
isQueryEmpty(context, qCreatedBy(featureId + state + "splitPart1"));www.smartbenchsoftware.com --- fs.place --- Renaissance
Custom FeatureScript and Onshape Integrated Applications0
Answers
Yes, you can use startFeature and abortFeature/endFeature. You can see a really good example in the Fill pattern feature which check that a pattern does not self-intersect before applying the pattern.
https://cad.onshape.com/documents/57361ad4e4b00e5012c3857c/w/afc99caf9d2bcd4451843939/e/2262facc4328a254dd7deb6a
Thank you, this should be exactly what I was looking for.
I'm running into problems with scoping and not sure how to resolve them.
Also when trying to determine whether the split has worked I'm comparing body counts before / after the split which is pretty ugly! I tried qSplitBy but couldn't get it to give a unique result upon successful completion of the split?
I've put together a test document showing the problem:
https://cad.onshape.com/documents/38e858c78f7e1cb2331da497/w/6915ba29ec08cfa14b2598ba/e/7f7051573aa0404f8773666e
Any further help appreciated.
I've resolved the scoping issue - I had a missing abortFeature;
So my only remaining question is, is there a better way to know the opSplitPart has worked?
I currently have the following:
var countBodiesBeforeSplit = size(evaluateQuery(context, qEverything(EntityType.BODY)));
I'm counting the number of bodies before and after the split - I'm sure there must be a more efficient way?
Thank you.
@graham_lock You could check a qcreatedby("splitPart") → isQueryEmpty
If the split happens, the query shouldn't be empty.
Custom FeatureScript and Onshape Integrated Applications
Thank you that works fine.
When I tested this I didn't use arrow notation as I've never tried it before.
I'm using:
qCreatedBy(featureId + state + "splitPart1") -> isQueryEmpty()
How do I get context to be the first parameter of isQueryEmpty?
Thank you.
All arrow notation does is replace the first parameter in the following function. So it won’t work in this case.
my bad, I was typing on a phone and assumed you wouldn't literally copy paste the code. I left syntax as homework for the reader.
isQueryEmpty(context, qCreatedBy(featureId + state + "splitPart1"));
Custom FeatureScript and Onshape Integrated Applications
Thanks, I didn’t actually copy the code, I tested it using non arrow syntax, but since I hadn’t tried arrow syntax before I though I’d give it a go.