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?
sloan_thrasher
Member Posts: 14 ✭✭
Looks like a lot of people are asking for global (at least within a document) variables.
Are there any plans to add this feature?
5
Best Answers
-
I imagine you've already added your vote to the Improvement Request here: https://forum.onshape.com/discussion/4027/global-variables#latest
If you haven't please do!
That's the main way that Onshape knows what features we want (and any improvement requests you submit through your "Contact Support" link in-document).
Romeo5 -
@sloan_thrasher
Its strange this hasn't been solved despite numerous calls and the obvious necessity. https://forum.onshape.com/discussion/comment/60779#Comment_60779
However so far I do it by a featurescript:
1. next to the tabs press plus - 'create feature studio'
2, insert the code below where "thickness" etc. will be your global values
3. press [commit]
4. on each part studio - SIGH - (where you want to use the globals) you pressthe {[]} symbol 'Custom features...' and insert '"Global Dimensions"' (name defined in the featurescript below). Put it early in your features list.
5 Now you have these centrally defined variables at your disposal.
e.g. : #thickness, #connhole etc.
----------START ------FeatureScript 1024;import(path : "onshape/std/geometry.fs", version : "1024.0");const VALUES = { // Below we have the global variables driving the design:"thickness" : 1.5 * millimeter, //Thickness of walls"connhole" : 1.2 * millimeter, //Connector hole"bandwidth" : 20 * millimeter, //The width of the wrist band"padding" : 5 * millimeter, //Padding from skin to band"margin" : 0.5 *millimeter , //Distance between objects"gap" : 0.8 *millimeter //Distance between objects};annotation { "Feature Type Name" : "Global Dimensions" }export const setGlobals = defineFeature(function(context is Context, id is Id, definition is map)precondition{}{for (var value in VALUES)setVariable(context, value.key, value.value);});
---------END ---------2 -
You can now use the new "Variable Studio" to define shared variables: https://cad.onshape.com/help/Content/variable_studio.htm1
Answers
-
I imagine you've already added your vote to the Improvement Request here: https://forum.onshape.com/discussion/4027/global-variables#latest
If you haven't please do!
That's the main way that Onshape knows what features we want (and any improvement requests you submit through your "Contact Support" link in-document).
Romeo5 -
FYI “Contact Support” is only available for paid users. Free users should cast their votes on the forum. Thanks.Senior Director, Technical Services, EMEA2
-
@sloan_thrasher
Its strange this hasn't been solved despite numerous calls and the obvious necessity. https://forum.onshape.com/discussion/comment/60779#Comment_60779
However so far I do it by a featurescript:
1. next to the tabs press plus - 'create feature studio'
2, insert the code below where "thickness" etc. will be your global values
3. press [commit]
4. on each part studio - SIGH - (where you want to use the globals) you pressthe {[]} symbol 'Custom features...' and insert '"Global Dimensions"' (name defined in the featurescript below). Put it early in your features list.
5 Now you have these centrally defined variables at your disposal.
e.g. : #thickness, #connhole etc.
----------START ------FeatureScript 1024;import(path : "onshape/std/geometry.fs", version : "1024.0");const VALUES = { // Below we have the global variables driving the design:"thickness" : 1.5 * millimeter, //Thickness of walls"connhole" : 1.2 * millimeter, //Connector hole"bandwidth" : 20 * millimeter, //The width of the wrist band"padding" : 5 * millimeter, //Padding from skin to band"margin" : 0.5 *millimeter , //Distance between objects"gap" : 0.8 *millimeter //Distance between objects};annotation { "Feature Type Name" : "Global Dimensions" }export const setGlobals = defineFeature(function(context is Context, id is Id, definition is map)precondition{}{for (var value in VALUES)setVariable(context, value.key, value.value);});
---------END ---------2 -
Cant believe this isnt implemented, I need this basically every project3
-
Agreed, i use it in almost every project, but still isn't enough. There needs to be a way to use variables to drive patterns and such in assemblies too3
-
I've used the feature script solution, but it doesn't integrate with the auto-replace of variable names, and you have to print it out or copy to a text file to remember the variable names, especially when you have a lot of vars. I'd love to see an "include" feature where you have the vars in a file and just have to include/reference that file to make either sketch or document level vars. Also, when making as repeating pattern, you can't use a variable to specify the number of repeats. Aaarg! IMHO, you should be able to use variables anyplace the needs a value.
2 -
You can now use the new "Variable Studio" to define shared variables: https://cad.onshape.com/help/Content/variable_studio.htm1
-
I was excited to see this but changing a variable name in Variable Studio broke things: it didn't rename the references in the parts studio.Jonatan_Schumacher said:...use the new "Variable Studio" to define shared variables...1 -
This is still an issue as of June 3, 2023. I was similarly extremely excited about this, but changing "Height" to "Depth" broke the reference in every part studio it was being used in instead of changing #Height to #Depth in the feature parameters. Still better than nothing, I guess, as long as you pick the forever-name of the variable from the start...jmsaltzman said:
I was excited to see this but changing a variable name in Variable Studio broke things: it didn't rename the references in the parts studio.Jonatan_Schumacher said:...use the new "Variable Studio" to define shared variables...1




