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?
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
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
Jeff Mirisola, CSWP, Certified DriveWorks AE
http://designsmarter.typepad.com/jeffs_blog
RE: If/Then Equation
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
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
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
Jeff Mirisola, CSWP, Certified DriveWorks AE
http://designsmarter.typepad.com/jeffs_blog
RE: If/Then Equation
RE: If/Then Equation
http://
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
Flores
RE: If/Then Equation
I think you've discovered a bug.
RE: If/Then Equation
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
"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
-handleman, CSWP (The new, easy test)
RE: If/Then Equation
Really! Has it always been that way?
I could have sworn I had used nested IIFs with multiple = in the past.
RE: If/Then Equation
-handleman, CSWP (The new, easy test)
RE: If/Then Equation
It should be IIF(L LIKE 120,..... instead of IIF(L = 120,...
Regards
RE: If/Then Equation
Flores
RE: If/Then Equation
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
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
Here it is in use:
http:/
Flores
RE: If/Then Equation
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
(By the way, sorry about the broken link, I changed web hosts yesterday and am still ironing things out)
Flores