Popular Topics

# Design Automation with DriveWorks for SolidWorks - Rule Spotlight - The IF Statement

DriveWorks is the design automation tool for companies that engineer to order. Using DriveWorks we can create infinite variations of your product in a fraction of the time done manually. DriveWorks does this though it’s easy to learn rules engine. What is a rule? A rule is a formula used to control the value of the item to which it is attached, e.g. a dimension of a feature, or the name of a drawing. Today we will showcase a particular rule we can use to drive our models.

Rule Spotlight – The IF Statement

The IF statement is one of the most frequently used rules in DriveWorks. It allows us to evaluate an argument and return a value whether the argument is True or False. Let take a look at this statement in everyday terms. If the Sun is up, then it is daytime, else it is nighttime. If we were to put this argument in an IF statement, it would read like this:

IF (Sun = Up, daytime, nighttime).

While this example might not be practical, we can see how we can use this in a DriveWorks project.

Let’s say that we wanted to drive the color of a part based on a color name on a form. On this form we have a drop down with our color options.

When the user selects a color option we want the RGB code to be driven to the part.

We can do this using an IF statement rule. In SolidWorks, a part’s color can be driven using an RGB color code and the custom property “DWColor”. For example, the color Red is 255|0|0, and Blue is 0|0|255. To achieve this, we right an IF statement like this for the “DWColor” custom property found in the model rules:

IF(ColorReturn = “Red”, “255|0|0”, “0|0|255”)

This is great if we have only two colors. If we have more than two options, we can use a Nested IF statement like this:

If(ColorReturn = “Red”, “255|0|0”, IF(ColorReturn = Blue, “0|0|255”, “0|255|0”))

Hint: “0|255|0” is Green

You can continue stringing together IF statements until all of the color codes are exhausted. This can get confusing rather quickly if we have many options, especially considering the variation we can have with colors. This is when we can employ a different rule that we will explore next time, the vLookUp.

If you found this rule helpful and would like to know more, check out “The Little Book of Rules”. This pocket book is fully loaded with examples of how rules can be used by you to automate your repetitive and everyday tasks using DriveWorks.

What to try it yourself? You can start using DriveWorks Xpress today! DriveWorks Xpress is included with every seat of solidworks, just look under the evaluate tab. Want to try the complete engineering automation tool? Download the 30-day trial of DriveWorks Solo. Need to bring automation to the masses? DriveWorks Pro takes the power of SolidWorks automation beyond the engineering department and brings it to the enterprise, and even to the web! For more information contact us at cati@cati.com or goto DriveWorks.co.uk