Monday, August 1, 2011

SolidWorks IIF equal’s to “the syntax is wrong” error workaround



  


Ever try creating an if-then statement in SolidWorks to control a feature. Well if you ever want to then you need to use the IIF function. Yes there are two I’s.


 


Background:


The syntax of the Visual Basic IIf function is:  iif(expression, truepart, falsepart)


 


where:


·expression is the expression you want to evaluate


·truepart is the value to use if expression is true


·falsepart is the value to use if expression is false


 


ex:


· The following equation suppresses a linear pattern when the value of global variable "overall length" is less than 40.


"LPattern1" = iif ("overall length"<40, "suppressed", "unsuppressed")


 


· This following equation unsuppresses a rib feature when a particular dimension is greater than 100.


"Rib1" = iif ("D3@Sketch1">100, "unsuppressed", "suppressed")


 


Issue:


What SolidWorks doesn’t like and will prevent from working is the equals sign used for an equal’s to syntax. Such as


 


“D1@sketch3” = iif (“D2@sketch1” = 0.5, 1.0, 1.25)


 


Work Around:


The workaround for this is to utilize the “double negative” syntax. Such as


 


“D1@sketch3” = iif (not(“D2@sketch1” <> 0.5), 1.0, 1.25)


 


Which is equivalent to “D1@sketch3” = iif (“D2@sketch1” = 0.5, 1.0, 1.25)


 


 



No comments:

Post a Comment