Equations are underappreciated.
You can make one feature adapt to changes in another. You can make your model smarter.
So let’s dive right in.
You can create an equation all around SOLIDWORKS.
It works in sketch mode and also while entering the extruding thickness, in the equations viewer…..
Just start a dimension with an equal sign, add a formula and press enter. This is now an equation.
Notice that typing an equation (like 3*6) without the equals sign does not create an equation. SOLIDWORKS just calculates the value once.
You can also create an equation within the equations viewer.
When you create or edit an equation, you can click any dimension to add it to your equation.
If you want to use the thickness dimension of an extrude, double click the extrude to show all dimensions, then click the dimension to use it in your equation.
You can access the equations viewer in the following three ways:
By default, the equations folder in the feature tree shows up after you add the first equation.
When the equations folder isn’t visible, you can show it by right-clicking in the empty space in the feature tree and selecting Hide/Show Tree Items.
There you can set the visibility to Show, Hide or Automatic.
When you open the equations menu/viewer, you will see a window like this one:
So there are a lot of buttons and options here. These are the visible ones:
These controls are usually hidden though:
The goal of the four views isn’t immediately clear, at least not to me. These are their functions:
I’ll re-post the equations window so you can clearly see the three groups of variables:
A global variable is a named variable that you can use it throughout the part/assembly.
All you have to do is type in a name (with or without double quotes, SOLIDWORKS adds them when you don’t) and a value or equation.
You can use other variable names when you enter them between double quotes: =”height” * 12 is a working equation when you define the variable height as well.
You can use the global variables:
This group lets you determine the suppression state of features, depending on the outcome of equations.
To enter a value in the first column:
Enter a text like =”unsuppressed” or =if(“var6″>3,”suppressed”,”unsuppressed”) in the second column.
I would rather call this group Dimensions than Equations. You can enter a new item by selecting a dimension in a sketch. You can then create an equation to calculate the value for this dimension.
If you created an equation in a dimension dialog box, the equation will also show up here. The same holds for linked dimensions.
There’s a limited set of mathematical functions that you can use in your equations.
Once you start entering a value, a popup shows you the possibilities:
The final entry in the list of mathematical functions is the IF (or IFF) function from VBA. When you enter an IF statement, SOLIDWORKS will usually replace it with an IFF.
The difference is explained here, but what it comes down to is that every option is evaluated and one of the results is returned. So dividing by zero will result in an error, even when that side of the if statement isn’t applicable.
You can create functions like:
= if ( “variable1” > 100 , 10 , 20 )
This will make the variable before the equal sign equal to 10 if variable1 is greater than 100. If not, it will be set to 20.
Creating nested functions is also possible:
= if ( “var1” > 100 , if ( “var1” > 200 , 30 , 20 ) , 10 )
A very basic version of suppressing features has been in SOLIDWORKS for years.
However, you could only suppress a feature by creating an equation like “Feature 1″ =”suppressed”. The help files said it should be used for debugging your equations only.
Since 2014 you can really use the suppression state in an if, then, else function.
This video by TriMech Solutions shows it very well. Just view it in full-screen mode (and skip to 1 minute 20 seconds for the equations).
Older version of SOLIDWORKS (think 2013 and before) would let you suppress an equation and set its suppression state per configuration.
Current SOLIDWORKS versions do not let you suppress an equation anymore.
A suppressed equation would be hidden or grayed out.
You can now only configure the equation itself, as shown in this video by GoEngineer. Skip to 2:00 if you’re in a hurry.
This is a strange one. To add a measurement:
You have now added a driven dimension to your model. The dimension doesn’t show up in a sketch or feature. It’s called an annotation, but it won’t be listed as such.
The two buttons labeled Import and Export should speak for themselves.
You can create a text file by exporting your equations and you can reuse them using the import function.
In addition, if you want multiple parts to use the same text file with equations, you check the box labeled “Link to external file”.
This will then keep the equations in sync. Because of the synchronization, you will have to edit the text file to edit the equations.
First of all, to add and edit equations using the API, you need to create an Equation Manager.
Adding an equation can be done using either Add2 (faster, no configuration support) or Add3 (newer, using configs).
Note that to use double quotes inside a string in VBA, you need to add them twice.
Open a part (with sketches called Sketch1 and Sketch2) and run this simple macro to add two equations:
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim EqMan As EquationMgr
Dim index As Long, RetVal As Long
Dim equation As String
Dim i As Integer
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set EqMan = swModel.GetEquationMgr
equation = """D1@Sketch2"" = 3*6"
index = -1 'Using -1 will add it to the end of the list
EqMan.Add2 index, equation, True
i = 6
EqMan.Add2 i, ("""D1@Sketch1"" = (IIf(""var7"">20, 25, 20))+3"), False
This is a feature you can include in all sketches, so 2D and 3D.
You can add a curve to a 2D sketch using Tools > Sketch Entities > Equation Drive Curve or by expanding the curve icon in the sketch toolbar.
This menu isn’t self-explanatory though:
Fortunately, the official help page will give you a flying start.
As it turns out, you can use X here to calculate Y and enter the start and end value for X. They draw half a circle by entering sqrt( 4 – x ^ 2) in the Y-box, -2 for the start value of x and 2 for the end value.
As a result, creating a straight line can be done by entering a linear function like 2*x+10.
If you select the parametric option, you can define formulas for X and Y separately. That means you can draw all kinds of funky lines.
The great thing about these equation driven curves is that you can drag them after they have been defined. When you unlock the endpoints, you can even drag and redefine those.
Once you enter a 3D sketch you will get the option of adding a 3D curve using the menu shown below.
In conclusion: curves in 3D can be used to create spirals, springs, staircases and zig-zag lines. Just play with them and see what happens.
Soon you will find a good use for a 3D curve. I guess.
So that’s everything I know about equations in SOLIDWORKS.
This post has become quite a read, because of all the options that SOLIDWORKS has to offer. Well done if you read everything up to this point!
So now it’s your turn to draw your own smart Lego blocks. Just don’t try to 3D print them, because you’ll only learn that they need to be damn accurate.