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.
Feature Script simple question
jelte_steur814
Member Posts: 232 PRO
Hi,
I'm learning Feature Script these weeks but i'm a newb to programming.
one of the custom features i created selects and edge (by user), and then the edgelenght is evaluated and used in many places.
it seems that the definition of the edge or a value created in the 'precondition' is available for all function calls below.
but I can't evaluate edgelength in the 'precondition' i believe.
but when I evaluate the edge length in the first (main) function below it and put it in a constant, it's not available for other functions that are called separately.
How does this work? I'm trying to understand the basic programming principles here. it seems the constants are available in the level of { } they're created in, but preconditions are available more widely it seems.
I'm working on the optimization for this one:
https://cad.onshape.com/documents/df7470bfcac6dbf738846c11/w/4e60241b9fc0b28698901775/e/27dcebec77fdc3f92e51e357
kind regards
Jelte
I'm learning Feature Script these weeks but i'm a newb to programming.
one of the custom features i created selects and edge (by user), and then the edgelenght is evaluated and used in many places.
it seems that the definition of the edge or a value created in the 'precondition' is available for all function calls below.
but I can't evaluate edgelength in the 'precondition' i believe.
but when I evaluate the edge length in the first (main) function below it and put it in a constant, it's not available for other functions that are called separately.
How does this work? I'm trying to understand the basic programming principles here. it seems the constants are available in the level of { } they're created in, but preconditions are available more widely it seems.
I'm working on the optimization for this one:
https://cad.onshape.com/documents/df7470bfcac6dbf738846c11/w/4e60241b9fc0b28698901775/e/27dcebec77fdc3f92e51e357
kind regards
Jelte
Tagged:
0
Comments
Awesome, this was exactly the explanation I was looking for! thank you!
it seems i'm not allowed to evaluate the edgeLenght in the precondition though. I'm already needing the edgelenght in the manipulator change function which is called before the feature body is.
After lots of googling, I resorted to evaluating the edgelength in an 'edit logic function' and putting it in the precondition through an ALWAYS_HIDDEN length annotation.
Not sure that's faster or cleaner than just evaluating it twice, but i learnt a lot again... and it works
that seems to do the trick.
Short version: Im trying to add more advanced FS training. Would like to know more about what issues users are hitting when trying to write FS.