iLogic - Rounding Dimensions to nearest 0.5

iLogic - Rounding Dimensions to nearest 0.5

Lewis.Young
Collaborator Collaborator
4,017 Views
5 Replies
Message 1 of 6

iLogic - Rounding Dimensions to nearest 0.5

Lewis.Young
Collaborator
Collaborator

Hi All,

 

I've got a little bit of experience using iLogic, but i haven't really used it with drawings before.

 

What i need is a rule that will round all dimension values to the nearest "0.5". If the length of that feature changes i would also like the dimensions to update, where as if i just changed the dimension by overriding it at the moment, it wouldn't update automatically.and would stay at that overridden value.

 

Thanks 

0 Likes
4,018 Views
5 Replies
Replies (5)
Message 2 of 6

ThomasB44
Mentor
Mentor

Hi @Lewis.Young

Here an example of code to round values, round to nearest with "round", round up with "Ceil" and round down with "Floor"

By multiply by 2 and then divide by 2 you will obtain your round by 0.5.

 

SyntaxEditor Code Snippet

Dim Num as Decimal
Num = 1.6
MessageBox.Show("Round : " & Round(Num*2,0) / 2 _
& vbNewLine & "Ceil : " & Ceil(Num*2) / 2 _
& vbNewLine & "Floor : " & Floor(Num*2) / 2, "Title")

And here an example of rule to go through each dimension and apply the rounded value, so the dimension is override...

You will need to run the rule to update the dimensions.

 

 SyntaxEditor Code Snippet

Dim oDrawDoc as DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim oDrawingDimension As Object
Dim oDimValue As Double

For Each oDrawingDimension In oDrawDoc.ActiveSheet.DrawingDimensions.GeneralDimensions
    oDimValue = oDrawingDimension.ModelValue * 10 'cm to mm
    oDimValue = (Round(oDimValue * 2) / 2)
    oDrawingDimension.OverrideModelValue = oDimValue / 10 'mm to cm
Next

You could add some statements to only round the needed dimensions.

Or also inspire with this rule here, wrote by Curtis Smiley Wink


Thomas
Mechanical Designer / Inventor Professional 2025
Inventor Professional EESignature

Message 4 of 6

Anonymous
Not applicable

That's all well and good, but I think it's a pity that it's not an automatic feature of Inventor, for those of us who feel iLogic is bit above our pay-grades.

0 Likes
Message 5 of 6

katy.psallida
Explorer
Explorer

This code works amazing but unfortunately when using angular dimensions to show degrees it doesn't work.

is there a fix for that?

0 Likes
Message 6 of 6

johnNL9B49
Explorer
Explorer

i had the same problem as you where the angular dimensions were overwritten to seemingly random numbers.

but i've managed to botch a fix with the following:  

 

' a reference to the active drawing document
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument

' a reference to the active sheet & dimension
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
Dim oDrawingDimension As DrawingDimension

' Iterate over all dimensions in the drawing if they are linear (Not angular)
For Each oDrawingDimension In oSheet.DrawingDimensions
If TypeOf oDrawingDimension Is LinearGeneralDimension Then

oDimValue = oDrawingDimension.ModelValue * 10 'cm to mm
oDimValue = (Round(oDimValue * 2) / 2)
oDrawingDimension.OverrideModelValue = oDimValue / 10 'mm to cm
End If
Next

0 Likes