Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. 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

graham_lockgraham_lock Member Posts: 158 PRO

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

Answers

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,696
    Answer ✓

    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

    Senior Director, Technical Services, EMEAI
  • graham_lockgraham_lock Member Posts: 158 PRO

    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.

  • graham_lockgraham_lock Member Posts: 158 PRO

    I've resolved the scoping issue - I had a missing abortFeature;

  • graham_lockgraham_lock Member Posts: 158 PRO

    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)));

                    opSplitPart(context, featureId + state + "splitPart1", {
                                "targets" : tmpPart,
                                "tool" : qCreatedBy(featureId + state + "extrude1", EntityType.BODY),
                                "keepTools" : true
                            });
    
                    // tried qSplitBy but didn't work
    
                    // must be a better way
                    var countBodiesAfterSplit = size(evaluateQuery(context, qEverything(EntityType.BODY)));
    
                    if (countBodiesAfterSplit > countBodiesBeforeSplit)
                    {
                        // correct combination found
    

    I'm counting the number of bodies before and after the split - I'm sure there must be a more efficient way?

    Thank you.

  • Caden_ArmstrongCaden_Armstrong Member Posts: 188 PRO
    Answer ✓

    @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 Applications
  • graham_lockgraham_lock Member Posts: 158 PRO

    Thank you that works fine.

  • graham_lockgraham_lock Member Posts: 158 PRO

    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.

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,696
    Answer ✓

    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, EMEAI
  • Caden_ArmstrongCaden_Armstrong Member Posts: 188 PRO
    Answer ✓

    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 Applications
  • graham_lockgraham_lock Member Posts: 158 PRO

    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.

Sign In or Register to comment.