×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

If/Then Equation
7

If/Then Equation

If/Then Equation

(OP)
Hello everyone,

I am trying to do what is probably a fairly simple equation, but I am not having much success. I have a piece of formed channel sheet steel, and I have a hole that is patterned in it. I want to put a If/Then that has three parameters in it that state if the overall length of the part is 120 or greater, then the pattern distance is 3. If the overall length of the part is 110 to 119, then the pattern distance is 2. And finally, if the overall length of the part is less than 110, then the pattern distance is 1.

Does anyone know if this can be done, and if so, what the equation might look like?

Aaron
SolidWorks/PDMWorks 08 4.0
CADKey 99 R1.0 (Yes, still using it!)
 

RE: If/Then Equation

2
You can use the IIF statement from VBA.  Syntax for IIF is:

IIF([condition],[value if true],[value if false])

IIF statements can be nested.

Basically, if your pattern distance is "P" and your overall length is "L" then your equation would be:

P = IIF(L>=120,3,IIF(L<110,1,2))

-handleman, CSWP (The new, easy test)

RE: If/Then Equation

2
You can also achieve the same in a design table where the hole pattern quantity has they typical IF/THEN statement out of excel, referencing the length dimension.

Jeff Mirisola, CSWP, Certified DriveWorks AE
http://designsmarter.typepad.com/jeffs_blog

RE: If/Then Equation

(OP)
Handleman,

I tried your suggestion, and I am still doing something wrong. I have uploaded a couple pictures of the equations I did to try and simulate what you did. Am I doing something wrong with punctuation perhaps? Im addition to using "P" and "L" in the equation, I tried it with the actual dimension names to no avail (pic 3).

Aaron
SolidWorks/PDMWorks 08 4.0
CADKey 99 R1.0 (Yes, still using it!)
 

RE: If/Then Equation

Aaron,
Create a design table that captures the length and the pattern distance. Once created, click on the cell that contains the pattern distance and replace it with this formula:
=IF(B2>=120,3,(IF(B2<=110,1,2)))

B2 represents the cell that contains the length dimension, so change it accordingly.  

Jeff Mirisola, CSWP, Certified DriveWorks AE
http://designsmarter.typepad.com/jeffs_blog

RE: If/Then Equation

(OP)
Jeff,

Thank you, it works great! It will only update if I go into the design table though. Is there a way to make it update after a rebuild?

Aaron
SolidWorks/PDMWorks 08 4.0
CADKey 99 R1.0 (Yes, still using it!)
 

RE: If/Then Equation

That's the downside of a DT, it has to be opened to be updated; an equation doesn't.

cheers

RE: If/Then Equation

2
Here is a sample without a design table.  Simply change the length and the rest changes as requested.  (the REF dimension showed is only to show that it is changing)

http://paul-flores.com/temp_files/equation_channel.SLDPRT

In SW equations, I couldn't get the >= to work, so I changed it to 119.99999 to include 120.  Here is the equation used.

CODE

"Pattern_distance@LPattern1" = (iif("Length@Base-Flange1" > 119.99999,3, (iif("Length@Base-Flange1" < 110,1,2))))

Flores

RE: If/Then Equation

That's strange. The = isn't being accepted in the IIF portion of the equation.

I think you've discovered a bug.

cheers

RE: If/Then Equation

(OP)
Smcadman,

Exactly what I was hoping to do! (except for the 119.999 thingy, but that can be dealt with) Thank you sir!

Aaron
SolidWorks/PDMWorks 08 4.0
CADKey 99 R1.0 (Yes, still using it!)
 

RE: If/Then Equation

Can you post the file?

"Equations" in SolidWorks really aren't equations, they are more like formulas.  They don't go both ways.  Whatever is on the left side is set equal to what's on the right, but the right side can never be changed by the left.  So if you use

"P" = "D1@...."

P will be changed to be equal to D1, not the other way around.

The design table route will work, but it will not dynamically update when you change the model like an equation will.  Formulas in cells of Excel design tables are not actually evaluated unless the design table is edited.

-handleman, CSWP (The new, easy test)

RE: If/Then Equation

Ah, yes.  I forgot about that limitation.  There can only be one "=" sign in any equation.   

-handleman, CSWP (The new, easy test)

RE: If/Then Equation

"There can only be one "=" sign in any equation."

Really! Has it always been that way?

I could have sworn I had used nested IIFs with multiple = in the past.

cheers

RE: If/Then Equation

At least since 2007.  That was a limitation I discovered while (or is it whilst? smile) experimenting with the limits of VBA in equations.  I was unable to use any code requiring an "=" sign.

-handleman, CSWP (The new, easy test)

RE: If/Then Equation

Instead of "=" use "LIKE".

It should be IIF(L LIKE 120,..... instead of IIF(L = 120,...

Regards

RE: If/Then Equation

macPT, did you try it in the equation?  I had originally tried "LIKE OR > 120" and also "LIKE 120 OR > 120" but that didn't work so that is why I ended up with the equation I did.   

Flores

RE: If/Then Equation

Quote (Flores):


macPT, did you try it in the equation?  I had originally tried "LIKE OR > 120" and also "LIKE 120 OR > 120" but that didn't work so that is why I ended up with the equation I did.    

The key here is that you are actually using VBA in the equation, so you have to follow the rules of VBA.  The LIKE operator is actually a string comparison operator.  Because VBA is (usually) a pretty smart language, it automatically converts strings to numbers and vice versa when you supply one to an operation that expects the other.  In this case, since you are using LIKE VBA takes both values, converts them to strings, and compares the strings.  It's a bit roundabout, but it works just fine.  The reason that "LIKE 120 OR > 120" doesn't work is because each comparison operation has to be complete and able to stand on its own.  Both sides of the boolean are evaluated, then they are "Booleanated" (or is it "Booleanized"?) together.  So if you put "L LIKE 120 OR > 120", then VBA will evaluate "L LIKE 120", then it will evaluate "> 120" (which is either a syntax error or it might assume the zero and always return "False"), then apply the boolean.  The "> 120" can't "reach across" the boolean to find the "L".  The proper syntax would be "L LIKE 120 OR L > 120".  I usually like to enclose both sides of my booleans with parens to make it easier to read, as "(L LIKE 120) OR (L > 120)", but they are not necessary.

-handleman, CSWP (The new, easy test)

RE: If/Then Equation

Thanks Handleman for making that more confusing, I mean clarifying it up.  smile

Adding the parenthesis to each equation/logic helped things out but also adding quotation marks before and after L finished things up.

I added "L"= "Length@Base-Flange1" to make things a bit easier to read, and I ended up with this:

CODE

"Pattern_distance@LPattern1" = (iif(("L" LIKE 120) OR ("L"> 120),3, (iif("L"< 110,1,2))))

Here it is in use:

http://paul-flores.com/downloads/equation_channel.SLDPRT
 

Flores

RE: If/Then Equation

I guys

Sorry for the late response.

Here I can use the iif(L>=120,...). I don't know why you can't. The LIKE string should be used only insted of "=" (I also don't know why it must be like that!).

Since iif also accepts logic operators, the last expression in smcadman's post should work. It's not clear for me, in this post, if he was succedeed.

There's another possibility (not tested): iif(NOT(L<120),...

Good Luck

P.S. smcadman - the link does not work for me

RE: If/Then Equation

Mac, the equation worked as pasted in my post above yours.

(By the way, sorry about the broken link, I changed web hosts yesterday and am still ironing things out)

Flores

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources