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.
Extrude problem within a loop
florian_neurohr
Member Posts: 7 EDU
I try to make a feature script that takes a json file with parameters and executes some extrudes in a for loop. That works until a certain index, where it crashes with a EXTRUDE_NO_SELECTED_REGION error.
If I instead create new parts, it finds some regions.
https://cad.onshape.com/documents/e42d897416c543439416259d/w/ddec5409b993612e442e9bec/e/11035714d70327bf2593cbce?renderMode=0&uiState=6932d0a43e18893be3c99dc8
Best Answer
-
EvanReese
Member, Mentor Posts: 2,685 PRO
Glad you got it working. I suspect it wasn't working because you're sketching on the panel face directly, and the regions are coming from imprinting on that face. When you extrude/remove, you're also removing face regions. It will actually be faster to compute only having the one boolean operation anyway. Right now, you're still doing it in the "i" loop, which could be right if you also have multiple targets, but it's a good idea to boolean as few times as possible. If you can get away with it, I suggest just collecting the tool and target bodies in the loops and doing boolean just once after all of the looping is done.
FYI, I couldn't export, I think because the doc was shared via a link, but wasn't made public. Here's what I see as my only option.
0


Answers
Looks like AI code, which I find much harder to fix than code I've made myself. Without access to your JSON it's hard to know what's going on. To diagnose an issue with a for loop though, I'd start by adding a number param called "temp index" and then using it to scrub through iterations and see if I can tell why it breaks down. You could either replace the for loop and use it as an index on your array (so you get one thing at a time), or use it as the size of your loop, so it adds new things to what's already there as you increase the number.
I also notice you're using setVariable, then later getting those variables for constants. Are you also planning to use them in downstream features? Otherwise, you don't need to do that.
The Onsherpa | Reach peak Onshape productivity
www.theonsherpa.com
Hi Evan
Thanks for your answer! What I could identify is that it crashes at index i=4, j=1 even thought its the same form as the index before, just on the next position. I actually manged to extrude all sketches with NewBodyOperationType.NEW so maybe I find a workaround for now if I just subtract those from the part. Could you not just download the json file from the project? I attached it anyway.
The thing with the setVariable makes sense in my original project. That here is just the isolated part with that extrude remove issue.
Glad you got it working. I suspect it wasn't working because you're sketching on the panel face directly, and the regions are coming from imprinting on that face. When you extrude/remove, you're also removing face regions. It will actually be faster to compute only having the one boolean operation anyway. Right now, you're still doing it in the "i" loop, which could be right if you also have multiple targets, but it's a good idea to boolean as few times as possible. If you can get away with it, I suggest just collecting the tool and target bodies in the loops and doing boolean just once after all of the looping is done.
FYI, I couldn't export, I think because the doc was shared via a link, but wasn't made public. Here's what I see as my only option.
The Onsherpa | Reach peak Onshape productivity
www.theonsherpa.com
Hi Evan,
Thanks again for your reply!
I suspected something like that as well but now I stripped the script down to the bare minimum with equal measurements for every extrude, no jsonfile and still it works for the first 3 iterations and then crashes. I mean It's literally the same operation in every loop, except of the name and the position of course.
https://cad.onshape.com/documents/e42d897416c543439416259d/w/ddec5409b993612e442e9bec/e/fc673250481c9ccaf17ae920
No you @EvanReese are right, im stupid!I removed the point to identify the face! that’s the problem. That is kind of what you said. I just did not got it at first.thanks man!