iLogic Rounding Issue when going from 2016 to 2018

iLogic Rounding Issue when going from 2016 to 2018

jtylerbc
Mentor Mentor
526 Views
7 Replies
Message 1 of 8

iLogic Rounding Issue when going from 2016 to 2018

jtylerbc
Mentor
Mentor

We're in the process of migrating from Inventor 2016 to 2018.  I've run into an odd minor issue with an iLogic rule that had previously worked fine, and thus far haven't been able to figure out why it now behaves differently.

 

The issue is with the rounding.  In 2016 and older, the rule would round the mass to the nearest whole number (zero decimal places).  So if a piece actually weighed 99.5 lbs per the model, it would determine a value of "100", which then gets written to a custom iProperty.

 

Now, in 2018, the same code gives slightly different results.  The rounding is correct numerically, but it displays an additional digit after the decimal place.  So instead of "100", we get "100.0". 

 

Can someone give me some direction as to why it now behaves differently, and what to do about it?  Code is below.

 

 

 

' This rule copies the mass of the referenced model to a custom iProperty of the drawing.
' Allows stripping of the lbmass from the model mass, and forces update of model mass,
' keeping drawing weight up to date.

Try
      model = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)
      mass = iProperties.Mass(model)
      lbs = Round(mass*2.20462262, 0)
      iProperties.Value("Custom", "Weight") = lbs
      InventorVb.DocumentUpdate()
Catch
      iProperties.Value("Custom", "Weight") = 0
End Try
0 Likes
527 Views
7 Replies
Replies (7)
Message 2 of 8

HermJan.Otterman
Advisor
Advisor

interesting.... I have the same.

 

the weight is a number, why the .0 is there....?

 

but when you change you lbs to a string, the zero is gone..

 

iProperties.Value("Custom", "Weight") = cstr(lbs)
If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 3 of 8

jtylerbc
Mentor
Mentor

Thanks.  Changing to a string does seem to fix it, so that's probably what I'll end up doing.  Still wondering why the behavior changed at all.  The rule worked as-is for years, and now suddenly gives different results.

0 Likes
Message 4 of 8

JaneFan
Autodesk
Autodesk

@HermJan.Otterman @jtylerbc

 

Hi Herm and John, 

 

Can I know the build you are using to reproduce this issue? I can see the same correct behavior with both inventor 2016 and inventor 2018 that no dot and numbers after the Round number value. 

Some info Round() method: the return value of Round() method is Double/Decimal instead of a integer, so it is recommended to explicitly convert it to integer or string if you want an integer looking number showing there. 




Jane Fan
Inventor/Fusion QA Engineer
0 Likes
Message 5 of 8

HermJan.Otterman
Advisor
Advisor

Hello Jane,

 

I use Inventor 2018 build 227, release 2018.2.1

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 6 of 8

jtylerbc
Mentor
Mentor

@JaneFan wrote:

@HermJan.Otterman @jtylerbc

 

Hi Herm and John, 

 

Can I know the build you are using to reproduce this issue? I can see the same correct behavior with both inventor 2016 and inventor 2018 that no dot and numbers after the Round number value. 

 


 

I'm on Build: 227, Release: 2018.2.3 - Date:  Tue 01/16/18.  In case it matters, operating system is Windows 10.  Our Inventor 2016 installation (where the code worked as intended) was on Windows 8.1, so I'm pointing it out as an additional thing that changed at the same time.

 

I have a friend at another company using the same code and seeing the same issue - not certain what build he is on, what operating system he is running.

 

I have no problem with converting it to a string if that's what is preferable.  Was just wondering what caused the behavior change. 

0 Likes
Message 7 of 8

JaneFan
Autodesk
Autodesk

Hi @HermJan.Otterman and @jtylerbc

 

Thank you so much for your feedback. I am working with windows 10 OS with inventor 2018.2.3 and couldn't reproduce the issue with multiple times trying, even switching OS locale to Non-English which I doubt might be the cause. Odd. 

I will keep eye on it, it would be helpful if any of you could send me a file can easily reproduce the issue. Thank you.




Jane Fan
Inventor/Fusion QA Engineer
0 Likes
Message 8 of 8

HermJan.Otterman
Advisor
Advisor

Hello Jane,

 

I updated to the latest version, and still have the same issue.

look at my screencast

 

 

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes