16 Replies Latest reply on Jan 27, 2015 2:09 PM by Daen Hendrickson

# Referencing a range in an equation

Hi all!

I want to create an IIF equation for pattern instances that uses ranges

For example

Currently I have =( IIF ( "LENGTHd2@Sketch1" > 2000 , 3 , 2 )  )

Ideally I want to replace the '2000' with something that dictates:

<=2000 - 2 instances

Between 2001 and 5000 - 3 instances

Between 5001 and 7000 - 4 instances

Between 7001 and 9000 - 5 instances

and so on...

Is this possible?  Can post .prt if necessary.

Thanks

Oli

• ###### Re: Referencing a range in an equation

You can do this with a straightforward mapping function, something like INT((B3-2001)/2000)+3, but not exactly.

Did you mean for your second bucket to have 3000 and all of the others to have 2000? That will make the mapping less elegant.

• ###### Re: Referencing a range in an equation

This repeats every 2000 ad infinitum.

= 2 + IIF ("x" > = 2001 , 1 , 0 ) + IIF ( "x" > = 5001 , 1 , 0 ) + int ( ( "x" - 5001 ) / 2000 ) * iif ( "x" > 5001 , 1 , 0 )

• ###### Re: Referencing a range in an equation

I think what you need is to use the AND function - see below:

= IIF ( "LENGTHd2@Sketch1" > 2000 and "LENGTHd2@Sketch1" < 4999.99, 3 , 2 )

in the above example I did not use 5000 because if D2 = 5000 then it is not less than 5000 & thus it would return the false.  I don't think solidworks supports less than or equal to (or at least I cannot get it to work)

• ###### Re: Referencing a range in an equation

then you should use 5001 in the second part.  with 4999.99 he would not get the 5000 referenced.

• ###### Re: Referencing a range in an equation

oh yeah that would make sense...

either way - using "and" should help to achieve desired results.

• ###### Re: Referencing a range in an equation

I used four global variables to achieve what you're looking for.

cnt3 = if ( "testcnt" > 1999 and "testcnt" < 5001 , 3 , 0 )

cnt4 = if ( "testcnt" > 5000 and "testcnt" < 7001 , 4 , 0 )

cnt5 = if ( "testcnt" > 7000 and "testcnt" < 9001 , 5 , 0 )

TotalCount = cnt3 + cnt4 +cnt5

Replace "testcnt" with your dim variable (I didn't have a dim that large so I used a global var).

Then reference your instance variable to point to "TotalCount".

You may need to modify the test condition values.

Also, there's no explicit test for <2000 or >9000. if so, then your "TotalCount" will be zero.

I hope this helps.

Kevin

• ###### Re: Referencing a range in an equation

Oops, I missed the <2000 count of 2 instances, but the basic scheme remains the same, just add cnt2:

cnt2 = if ( "testcnt" < 2001 , 2 , 0 )

cnt3 = if ( "testcnt" > 1999 and "testcnt" < 5001 , 3 , 0 )

cnt4 = if ( "testcnt" > 5000 and "testcnt" < 7001 , 4 , 0 )

cnt5 = if ( "testcnt" > 7000 and "testcnt" < 9001 , 5 , 0 )

TotalCount = cnt2 + cnt3 + cnt4 +cnt5

Kevin

• ###### Re: Referencing a range in an equation

Just nest your "ifs" in the proper order.  No need to confirm "in-between-ness"

Start by asking if less than 2000.  Another "if" goes in the else part to check if less than 3000. etc etc.

• ###### Re: Referencing a range in an equation

And keep in mind it needs to be the Iinline IF construct [ IIF(...) ]. The IF(...) will throw a sintax error if nested in the equation manager. (at least is does in SW2013 SP3)

Also, the LESS THAN OR EQUAL TO  and the GREATER THAN OR EQUAL TO abilities exist.

YourEquationManagerVariable    = iif ( "Vert@Triangle Sketch" > 0 AND "Vert@Triangle Sketch" < = 2000 , 2 , iif ( "Vert@Triangle Sketch" > = 2001 AND "Vert@Triangle Sketch" < = 5000 , 3 , iif ( "Vert@Triangle Sketch" > = 5001 AND "Vert@Triangle Sketch" < = 7000 , 4 , 5 ) ) )

Daen

• ###### Re: Referencing a range in an equation

Actually, less than or equal to is not available in 2013 if my recollection is correct.  SolidWorks will not accept anything that has an "=" sign on the right side of the main "=" of the equation.  Might work in 2014.

• ###### Re: Referencing a range in an equation

Didn't know that. It does work in 2015.

• ###### Re: Referencing a range in an equation

Nope, not in 2014, sp5.

• ###### Re: Referencing a range in an equation

This explains why it did not work at work but started working at home. Well, the rest of it is fine, you can just delete the equals signs and move the limits accordingly.

• ###### Re: Referencing a range in an equation

Josh,

I didn't think it worked either... But wanted to take a crack at this for my own education and the equation I posted above is copied from my equation manager and it is working (SW2013 SP3).

I'll attach the part file for anyone else to see if it works in pre-2015 (can't figure out how to get to the advanced editor from a reply window).

Daen

• ###### Re: Referencing a range in an equation

And the part file...

If you modify the triangle's vertical length dimension, the formulas adjust the horizontal length.

Made with SW2013 SP3.

Daen

• ###### Re: Referencing a range in an equation

To everyone, thanks for the input here.  I'll give these a go today.

Thanks