
Re: Round Specifics of Equations, workaround needed
Charles Culp Sep 23, 2009 10:39 AM (in response to Andrew Warren)can you add a verification IF statement?
If (Round (x)  (x)) = 0.5 then Round (x + 1) else Round (x)
make it so if the original value minus the rounded value is exactly 0.5, then add 1. If it is 0.5, then it is done properly, and if it is anything else, then it wasn't exactly xxx.5 to start with.

Re: Round Specifics of Equations, workaround needed
Charles Culp Sep 23, 2009 10:42 AM (in response to Charles Culp)But just so it is understood, this has been discussed before:
https://forum.solidworks.com/message/35699#35699
https://forum.solidworks.com/message/12849#12849
https://forum.solidworks.com/message/78334#78334

Re: Round Specifics of Equations, workaround needed
Andrew Warren Sep 23, 2009 10:46 AM (in response to Charles Culp)I found a few of those but didn't feel that they specifically addressed my .50 rounding workaround issue.


Re: Round Specifics of Equations, workaround needed
Andrew Warren Sep 23, 2009 10:42 AM (in response to Charles Culp)That is a possibility but I think I would have to implement a design table to take advantage of Excel's formula capabilities since I don't believe Solidwork's equation dialog can handle IF statements. The more I think about this, the more it seems likely that I will have to do this since I highly doubt there is a function to only change this evennumbered rounding behavior.
Re: Round Specifics of Equations, workaround needed
Charles Culp Sep 23, 2009 11:47 AM (in response to Andrew Warren)From the SolidWorks Help file:
Operators, Functions, and Constants
You can also use the Visual Basic IIf function when specifying a model dimension. This function returns one of two values depending on the evaluation of an expression. For example, if the equation specified is "D1@Sketch1" = (IIf("D1@Sketch4">15, 20, 10)) + 8, then:
If D1@Sketch4 is ...
Then D1@Sketch4 is set to ...
And D1@Sketch1 is set to ...
> 15
20
28
<= 15
10
18
Thus the following equation should work:
"D2@Sketch1" = IIf(("D1@Sketch1"  "Round")<0.5, "Round", "Round"+1)
I have attached an example.
Edited to included both always round up line, as well as SolidWorks rounding line.

RoundUpEquation.SLDPRT.zip 93.6 KB




Re: Round Specifics of Equations, workaround needed
Andrew Warren Sep 23, 2009 11:14 AM (in response to Andrew Warren)Turns out you don't even need the suggested qualifier if using Excel to do your rounding. It will automatically round up to the next integer if the number to round is x.50 If it is x.4999999... it will round down to x.
Re: Round Specifics of Equations, workaround needed
Mahir Abrahim Sep 23, 2009 11:32 AM (in response to Andrew Warren)Correction, you CAN use if statements in SW's equations. Look up the IIF statement. It's also mentioned briefly in the help file.
Re: Round Specifics of Equations, workaround needed
Mahir Abrahim Sep 23, 2009 11:57 AM (in response to Mahir Abrahim)Also, SW has issues using an evaluation statement with = in it, so you will have to use LIKE instead. For example, if you wanted to make an equation that worked like this:
If "D1@Sketch1"=1 Then
"D2@Sketch1"=2
Else
"D2@Sketch1"=3
End If
"D1@Sketch1" = IIF("D2@Sketch1"=1,2,3) This would not work
"D1@Sketch1" = IIF("D2@Sketch1" LIKE 1,2,3) But this would

Re: Round Specifics of Equations, workaround needed
Mauricio MartinezSaez Sep 25, 2009 5:45 PM (in response to Mahir Abrahim)The ISSUES using the IIF and = are not SW issues are VB issues, SW uses VB on the equations functionality.
The rounding to x.5 can be done with SW equations several ways, but if you have a design table, Excel have way much power on calculations (you can even define your own functions by adding a VB module with any function as complex as you may need, and them use it in any formula of a cell.
Attached is an Excel file which shows all the standard functions available on Excel as well as examples on how to use each one of them, in addition to this the user can define any function he may need by creating the code in a VB project.
Hope the attached file will serve to help those wanting to use Excel functions to his full potential.

Excel_Functions.xls 3.2 MB

Re: Round Specifics of Equations, workaround needed
Jerry Steiger Sep 25, 2009 6:38 PM (in response to Mauricio MartinezSaez)Mauricio,
Thanks! that is really nice to have.
Jerry Steiger



