Global Variables
A global variable is a named value that belongs to the whole part, not to one sketch. Give it a name such as Width and a value such as 2 in, then use the name in any dimension formula. Change the value once and every dimension that reads it follows, through the same sketch solver that holds every other dimension. Variables build on Equations: a variable is used the way a dimension's name is used.
When to Use It
- Keep one wall thickness or plate width in a single place, and have every sketch of the part read it
- Make a family of sizes: change
Widthonce to get the next size - Hold a number that is not a dimension at all, such as a count or a ratio, and use it in formulas
- Keep a hole spacing as half of a variable that you change to suit the job
Step by Step
- Open a sketch and draw a rectangle with two dimensions (see Smart Dimension).
- On the Sketch tab, click Edit, then Global variables.... The Equations window opens with a Global variables section at the top.
- In the empty row, type the name
Width, leave the type on Length, type4 inas the value and click Add. The variable is listed with its value. - Click the number of the rectangle's width dimension, type
Widthand press Enter. The dimension now follows the variable and shows Σ. - In the window, change the value of
Widthto6 inand press Enter. The rectangle becomes 6 in wide. - Press Ctrl+Z once. The value of
Widthand the rectangle both go back together. Ctrl+Y puts both back.
Names and Types
A name uses letters, digits and the underscore, and must start with a letter. Width, Wall_2 and Slot_Depth are fine; _Width is not. A space, a sign or an @ is not, because the @ belongs to dimension names such as D1@Sketch1. Capitals do not matter, so width and Width are the same name. A name can be up to 40 characters. It cannot be another variable's name, a dimension's name, or a word a formula already uses, such as in, mm, sin or pi.
- Length: a size.
2 in,10 mmandWidth / 2are lengths. A number with no unit is in the display unit you were using when you typed it, and the variable keeps that unit, so2typed in inches stays 2 in when someone opens the part with millimetres showing. A variable saved with no unit noted is read in millimetres. - Number: a plain number with no unit, such as a count or a ratio. It can be zero or negative. Multiply it by a length to use it, as in
Count * 1 in. - Angle: degrees, more than 0 and less than 360. An angle dimension can read it.
A variable's value can be a formula of other variables, such as Width / 2 or Wall * 3. It cannot read a dimension, because a dimension belongs to one sketch and a variable belongs to the whole part.
What Happens When a Variable Changes
- The sketch that is open follows at once. Every formula that reads the variable is worked out again, in order, and the solver moves the sketch to match.
- A sketch that is waiting on its plane, or the sketch of a step in the History, follows when you open it. A note says how many dimensions changed, and Ctrl+Z takes it back.
- A step already in the History keeps the shape it was made with until its sketch is opened and Update step is pressed.
- The Extrude depth box can use a variable too, such as
Width / 4. It is worked out once, when you press Extrude or Cut.
When a Change Is Refused
A value that cannot be used is refused with a plain sentence, and nothing changes. Not the sketch, not the undo history.
- A circle: if one variable needs another and that one needs the first, the message says so by name.
- A name that is not there: a variable can read only numbers, units and other variables.
- A result that cannot hold: if the change would make a dimension formula give a length of zero or less, or an angle that is too big, or if the sketch cannot hold together, the change is refused and the message says why.
- Deleting or renaming a variable that is in use: a variable a formula reads cannot be deleted. Change or delete that formula first. Renaming one that is read in the open sketch changes those formulas to the new name; renaming one that a sketch on another plane, or a step in the History, reads is refused until that formula is changed. Changing the type of such a variable is refused too.
- Too many: a part can have 100 variables.
Options
- In the Equations window: add, change, rename, change the type of and delete variables in one place. Edit a name or a value and press Enter; click the × to delete.
- In any formula: type the name like a dimension's name.
Width / 2 + 0.25 inis fine. - Needs an open sketch: variables are changed from a sketch, so that Ctrl+Z can take a change back with the sketch.
- Earlier versions: a version you are only looking at cannot be changed.
Tips and What to Expect
- The variables are saved with the part. Close the model and open it again and they are back, with the formulas that read them.
- A model saved before this release opens exactly as it was, with no variables.
- The number of every dimension is saved beside its formula. An older version of the viewer opens the model with the plain numbers and does not lose them, but it will not show or keep the variables.
- A variable that is not read by any formula changes nothing in the model; it is only a stored value until you use it.
- Each add, change, rename and delete is one Undo step, with everything that followed it.