Preview | SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
SDScott Deas18/02/2009
Hi,
I've just spent a wee while trying to find a way of setting a dimension based on whether a global variable is either odd or even. It took me a while, and since I don't know VB I didn't know the answer, so I thought I would share it here, just in case someone else is in the same predicament!
Basically, I have a variable that sets the number of instances in a pattern. If this was odd, I wanted the offset distance of the part to be patterned to be different than if it was even.
If there is a more straight forward way of doing this, then let me know!
I set the number of instances like so...
"Num" = 4
Then to find if that's odd or even, I used...
"OddOrEven" = "Num" MOD 2
Which gives 1 if its odd and 0 when even since MOD works out the remainder when the first variable is divided by the second. And its not case sensitive.
Then, I used...
"Offset" = IIF ( "OddOrEven" LIKE 0 , "EvenValue" , "OddValue" )
Where "EvenValue" and "OddValue" are the value I want the dimension to be when the "Num" is even or odd.
Finally, I linked the dimension with the variable "Offset" to transfer it back the model.
I was trying to set "OddOrEven" = 0 for ages inside the IIF statement, but Solidworks wouldn't let me, then I found out I can use LIKE, which means the same thing to SW and it was happy! Since I don't know any VB this was new to me!!
I hope someone else finds this useful!
I've just spent a wee while trying to find a way of setting a dimension based on whether a global variable is either odd or even. It took me a while, and since I don't know VB I didn't know the answer, so I thought I would share it here, just in case someone else is in the same predicament!
Basically, I have a variable that sets the number of instances in a pattern. If this was odd, I wanted the offset distance of the part to be patterned to be different than if it was even.
If there is a more straight forward way of doing this, then let me know!
I set the number of instances like so...
"Num" = 4
Then to find if that's odd or even, I used...
"OddOrEven" = "Num" MOD 2
Which gives 1 if its odd and 0 when even since MOD works out the remainder when the first variable is divided by the second. And its not case sensitive.
Then, I used...
"Offset" = IIF ( "OddOrEven" LIKE 0 , "EvenValue" , "OddValue" )
Where "EvenValue" and "OddValue" are the value I want the dimension to be when the "Num" is even or odd.
Finally, I linked the dimension with the variable "Offset" to transfer it back the model.
I was trying to set "OddOrEven" = 0 for ages inside the IIF statement, but Solidworks wouldn't let me, then I found out I can use LIKE, which means the same thing to SW and it was happy! Since I don't know any VB this was new to me!!
I hope someone else finds this useful!