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.
Global Variables - Feature Script
3D
OS Professional Posts: 52 ✭✭
Can anyone offer advise on the possibility / components for / method of making a global variable using FeatureScript?
0
Answers
In my thoughts on programming, there's very very few cases in which the best way to implement something is with an actual global variable; usually it's cleaner to pass by reference or use getters/setters.
PhD, Mechanical Engineering, Stanford University
PhD, Mechanical Engineering, Stanford University
FS could be done in a similar way but it would be a workaround leveraging linked documents.
With part studio configurations, part variables become scoped to the part instance in the assembly. If other parts in the assembly depend on such a variable, I don't see how simple global variables would be a solution. (For example, with two instances of the same part with different configurations in the same assembly, two values for the same variable can be at play in the same assembly context.)
Maybe the assembly "Insert" functionality could somehow be extended to import variables, as well as sketches and parts?
I'd love to have variables in asm, mostly for defining patterns. But today there enough work arounds to get 80% there.
If you have a particular need, you should post it. We'll see if there is an elegant work around available.
I have a FeatureScript with parameters for the tolerance needed for a tight fit vs. a loose fit for example. If I put all variables in (i.e. #diameter here), I can have one tube outside diameter specified as something like "#diameter - #gapLoose". But if I make a one-off tube where the variable is declared locally as #mountTube, I cannot set anything to be (#mountTube - #gapLoose). No error is displayed, but it turns red and fails..
I have some configurable plates that connect two parts which themselves are configurable. My approach for now is just going to be to have a limited selection of configurations and I'll manually measure the distance to connect the two parts to connect for each configuration. Having variables would unlock a lot of other possibilities too, instead of defining distances for mates offset or sliding mates you could use the variable and it would just be such a cleaner workflow.
@wout_theelen541 They implemented Global Variables in June 2022. This is not with FeatureScript, but it is global variables.
https://forum.onshape.com/discussion/18569/improvements-to-onshape-june-27th-2022/p1
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
You can use super derive to import that variable into other part studios.
You just can't import that variable into an assembly.