SOLIDWORKS Basics - Intro to If/Then Statements

Article by Tashayla Openshaw on Nov 18, 2020

Have you ever wondered whether you can derive features or dimensions in a SOLIDWORKS part off another dimension in the same part? The answer is yes, you can! This tutorial is an introduction to using If/Then Statements in SOLIDWORKS in order to achieve this. 

How to Use If/Then Statements

To derive features or dimensions off another dimension in the same part, we use the nested IF statement within the Equation tool in SOLIDWORKS. The first thing to remember when writing an IF statement is that they are written as “IIF” instead of “IF”. The IF statement will not work if it is written with just one ‘I’. 

IF equations can get complicated, but for now I will go over the basic IF statement. Here is the generic way to create an IF statement: 

  • Simple IF Statement
    • This is equivalent to the generic IF/Then statement. “If a value is greater than this, then the result is this, else it’s that.” 
      • Result = IIF (“Value” <= 100, “Result 1”, “Result 2”) 
    • These simple statements can also be used to control whether a feature is suppressed or unsuppressed in the part when created in the Features section. That would look something like this: 
      • Fillet = IIF (“Value” <= 100, “suppressed”, “unsuppressed”)

IF statements are super handy to use when there are one or several dimensions that rely on other dimensions in the part design. They save a lot of time because otherwise, these changes would have to be created manually. 

IF/Then Statements Example

The following example will go over the basics steps to adding those IF equations to help automate a part's design. 

How I chose to start was by creating some global variables for the equations to relate to (which isn’t necessary to do but it is one way to organize your equations). 

To add global variables, you will need to open the Equations tool by going to Tools > Equations, and you can add them in the top section called Global Variables. The IF statements that I will be creating will be input in the Features, as well as the Equations section of that same Equations tool. 

Part Design 

For this part, I chose to write IF statements to drive the height of the vertical boss, the width of the base, and whether the fillets are active, on the total length of the base. 

SOLIDWORKS If/Then Statement Example

Steps 

1 – In the Global Variables section of the Equation tool, I input the variables that I wanted to see for the height and width, that I will use to refer to within the IF equation. The different variables I chose were: 

Height 1 = 35 mm Height 2 = 45 mm Width 1 = 10 mm Width 2 = 20 mm

2 – In the Features section, I created an IF statement that will suppress the Fillet feature if the Length value is less than or equal to 130 mm, and unsuppressed if it's greater than 130 mm. 

Equation: Fillet2 = IIF ( "Length" < = 130 , "suppressed" , "unsuppressed" )

3 – In the Equations section of the Equation tool I created an IF statement that will make the Height = Height 1 if Length is less than or equal to 130 mm, and Height = Height 2 if Length is greater than 130 mm. 

Equation: Width = IIF ( "Length" < = 130 , "Height 1" , "Height 2" )

Introduction to if/then statements in SOLIDWORKS

I hope you found this SOLIDWORKS tutorial helpful. Learn more SOLIDWORKS tips and tricks below.

Learn More About SOLIDWORKS

SOLIDWORKS Copy and Paste Features: Same or Different Parts

SOLIDWORKS Routing 101: Pipe Design

SOLIDWORKS Convert to Sheet Metal Command Explained

How to Create a Lip/Groove Feature in SOLIDWORKS

SOLIDWORKS Combine Feature Tutorial

VIEW MORE SOLIDWORKS TIPS & TRICKS

 

About Tashayla Openshaw

Tashayla Openshaw is a SOLIDWORKS Technical Support Engineer based out of our Headquarters in Salt Lake City, Utah. She earned her Bachelor’s degree in Mechanical Engineering from the University of Utah in 2018 and has been part of the GoEngineer family since February 2019.

View all posts by Tashayla Openshaw