What is the correct way to write this iLogic code / Parameter equation?

What is the correct way to write this iLogic code / Parameter equation?

chris
Advisor Advisor
324 Views
4 Replies
Message 1 of 5

What is the correct way to write this iLogic code / Parameter equation?

chris
Advisor
Advisor

I want to round up a dimension, based on another dimension to the nearest 1/8".

 

Examples:

 

if d17 0.735, then I want d18 to = 0.75

if d21 = 0.317 then I want d22 to = 0.375

 

can you show this for both iLogic and for Parameters?

0 Likes
Accepted solutions (2)
325 Views
4 Replies
Replies (4)
Message 2 of 5

Andrii_Humeniuk
Advisor
Advisor

Hi @chris . I recommend trying the mathematical iLogic snippet "Round Closest to Increment".

 

inc = .125 ' rounding increment ( .125, .25, .5, etc)
roundedClosest = Round(Round(d0,4) / inc) * inc

Example formula for parameters:

round(d0 / 0,125 mm) * 0,125 mm

 

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 3 of 5

chris
Advisor
Advisor

@Andrii_Humeniuk  I think your example shows how to round a single dimension, but I am looking for one dimension to be rounded "up" based on a reference dimension... unless I'm missing something...?

0 Likes
Message 4 of 5

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

You need to use the math function Ceil

For iLogic:

 

inc = .125 ' rounding increment ( .125, .25, .5, etc)
roundedClosest = Ceil(d0/inc) * inc

 

For Parameters:

 

Ceil(d0 / 0,125 mm) * 0,125 mm

 

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 5 of 5

marcin_otręba
Advisor
Advisor
Accepted solution

There is no need to use ilogic , you can just use formula in parameters as @Andrii_Humeniuk wrote:

Ceil(d0 / 0,125 mm) * 0,125 mm

it will round it up as you wanted.

 

but f you want to use formula in ilogic then it would look like:

Parameter("d18") = (Ceil(d17 / 0.125) * 0.125)
Parameter("d22") = (Ceil(d21 / 0.125) * 0.125)
iLogicVb.UpdateWhenDone = True

 

 

marcin_otrba_0-1740552806353.png

 

 

here is help reference:

Inventor 2025 Help | Math Functions Reference (iLogic) | Autodesk

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes