Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

If/Then Equation 7

Status
Not open for further replies.

Overworked1

Mechanical
Dec 7, 2006
33
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!)
 
Replies continue below

Recommended for you

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)
 
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!)
 
 http://files.engineering.com/getfile.aspx?folder=6ff35e59-f7ab-458c-90a2-4e4803f7bf9d&file=Equations.bmp
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
 
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!)
 
That's the downside of a DT, it has to be opened to be updated; an equation doesn't.

[cheers]
 
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)


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
 
That's strange. The = isn't being accepted in the IIF portion of the equation.

I think you've discovered a bug.

[cheers]
 
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!)
 
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)
 
Ah, yes. I forgot about that limitation. There can only be one "=" sign in any equation.

-handleman, CSWP (The new, easy test)
 
"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]
 
At least since 2007. That was a limitation I discovered while (or is it whilst? :)) experimenting with the limits of VBA in equations. I was unable to use any code requiring an "=" sign.

-handleman, CSWP (The new, easy test)
 
Instead of "=" use "LIKE".

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

Regards
 
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
 
Flores said:
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)
 
Thanks Handleman for making that more confusing, I mean clarifying it up. :)

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:



Flores
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor