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.

how to trigger reportFeatureInfo in forEachEntity?

Evan_ReeseEvan_Reese Member Posts: 2,060 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?
Evan Reese / Principal and Industrial Designer with Ovyl
Website: ovyl.io

Best Answer

  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    edited December 2021 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 container

    var f = function ()
    {
    //do something
    b[] = "new box value"; // b[] - accessing box inner value
    return "something"; // explicit return - may or may not exist;
    }

    //function call
    f();

    //now box will contain "new box value"
    println(b[]);


Answers

  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    edited December 2021
    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.
  • Evan_ReeseEvan_Reese Member Posts: 2,060 PRO
    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.
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    edited December 2021 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 container

    var f = function ()
    {
    //do something
    b[] = "new box value"; // b[] - accessing box inner value
    return "something"; // explicit return - may or may not exist;
    }

    //function call
    f();

    //now box will contain "new box value"
    println(b[]);


  • Evan_ReeseEvan_Reese Member Posts: 2,060 PRO
    Thanks! I've never used a Box type before, so this is really helpful. I got it working.
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
Sign In or Register to comment.