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

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.
My FeatureScript blog
[email protected]