SolidWorks 2010 Bible

(Martin Jones) #1

Part II: Building Intelligence into Your Parts


In practice, you could use it like this:

IIF(x>5, x-1, x+1)

which reads, “if x is greater than 5, then subtract 1 from x; if not, then add 1 to x.” One of the
reasons why this is considered a parlor trick is that this function causes the value of x to oscillate
between two numbers (depending on the number that it starts with) with each rebuild. It may be
difficult to imagine an application where this sort of behavior would be desirable, but when you
combine it with a macro that simply rebuilds a model a number of times, you can use it to create a
certain animation effect.

On the CD-ROM
A simple example of the IIF function can be found on the CD-ROM with the filename Chapter 9
Oscillate.sldprt. The equation is shown in Figure 9.9. n

FIGURE 9.9
An equation using IIF

Tip
You can find some great examples of this function at http://www.mikejwilson.com, along with many other
extremely creative examples of SolidWorks modeling. The model on this site called Ship in a Bottle.
sldprt also includes a macro that will rebuild the model a certain number of times, which is useful for
animations that are created in this way. n


SWITCH .......................................................................................................


The SWITCH function enables you to have a list of relationships with associated values. The value
of the first relationship in the list that is satisfied is returned by the SWITCH function. For example,

switch (x>2, 1.5, x>1, .5 x<1, 2.5)

reads as follows: “if x is greater than 2, then the answer is 1.5; if x is not greater than 2 but greater
than 1, then the answer is .5; if x is less than 1, then the answer is 2.5.”

As you can see, this function does not cover all situations, but it does create a condition where the
value cycles through three different numbers in a specific order. Is this useful? Possibly. Again, the
main application for this function would be a simple animation for changing the size or shape of
SolidWorks components that cannot be changed in other more conventional ways.
Free download pdf