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.
how to trigger reportFeatureInfo in forEachEntity?
EvanReese
Member, Mentor Posts: 3,059 PRO
I'm using forEachEntity to iterate over a query. Some of the operations may fail and I want to let the user know when they do. It seems like reportFeatureWarning and reportFeatureInfo don't do anything when inside the loop. I also tried making a boolean variable isError outside the loop to change inside the loop, but inside the loop it's treated as a const, which I can't edit. How might I solve this?
0
Best Answer
-
to get some value from pure function you can define a box container in the outer scope, then make a change to the box value in the function body, call the function and the value will be stored in the box - this is called closure:var b = new box("");// declearing box containervar f = function (){//do somethingb[] = "new box value"; // b[] - accessing box inner valuereturn "something"; // explicit return - may or may not exist;}//function callf();//now box will contain "new box value"println(b[]);
0
Answers
-
Seem like report functions are only showing message for the first call in the execution flow, the downstream calls are shadowed. Multiple error messages handling is a problematic part of Featurescript because say even if you collected error messages from the loop in a single string, it will ignore any formatting like line break symbols.
1 -
In my case, I only need one error message if any or all of my functions fail, but I'm still not sure how to set a boolean to true inside the loop and retrieve it outside the loop. With a normal for loop it's not a problem, but I don't think I totally understand forEachEntity.0
-
to get some value from pure function you can define a box container in the outer scope, then make a change to the box value in the function body, call the function and the value will be stored in the box - this is called closure:var b = new box("");// declearing box containervar f = function (){//do somethingb[] = "new box value"; // b[] - accessing box inner valuereturn "something"; // explicit return - may or may not exist;}//function callf();//now box will contain "new box value"println(b[]);
0 -
Thanks! I've never used a Box type before, so this is really helpful. I got it working.1
