Message 1 of 2
iLogic rule that removes trailing zeros
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I'm looking for another way to remove trailing zeros from all dimension values and tolerances on a drawing. I remember seeing trailing zeros being a Boolean option somewhere in the object tree but for the life of me I can't find it in intellisense or online? Did I dream this?
I have written something that does the job, however I'm wondering if there was a cleaner way to do this?
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument Dim oSheet As Sheet = oDoc.Sheets.Item(1) For Each oDim In oSheet.DrawingDimensions.GeneralDimensions 'loop through each dimension on the drawing 'Section for removing trailing zeros from the value. Dim oModelValue As Double = oDim.ModelValue * 10 'This gets the actual model value, it's multiplied by 10 because iLogic works in cm and we want it in mm, like the drawing. AfterDecimalPoint = Round(oModelValue - Math.Floor(oModelValue), 2) 'This gets all the numbers after the decimal point. eg 11.34 becomes 0.34. It is also rounded to 2 decimal places because for some reason (another quirk) Inventor adds on tiny amounts (picometers) that affect this process. If AfterDecimalPoint = 0 Then 'if the number after the decimal point is 0 then it is a whole number therefore nothing after decimal point, therefore numbers after decimal point (precision) = 0 oDim.Precision = 0 Else 'Otherwise the precision become how many numbers make up that value after the decimal point. a further 2 is taken away to remove the '0.' at the start of the number. Eg in 0.34 we want to remove the '0.' to allow it to become '34' and this is 2 digits long therefore our precision is 2 digits long. oDim.Precision = AfterDecimalPoint.ToString.Length - 2 End If 'Section for removing trailing zeros from the tolerance. If oDim.Tolerance.ToleranceType = 31235 'if the tolerance type is symmetric Dim oModelTol As Double = oDim.Tolerance.Upper * 10 'This gets the actual model Tol, it's multiplied by 10 because iLogic works in cm and we want it in mm, like the drawing. AfterDecimalPoint = Round(oModelTol - Math.Floor(oModelTol), 2) 'This gets all the numbers after the decimal point. eg 11.34 becomes 0.34. It is also rounded to 2 decimal places because for some reason (another quirk) Inventor adds on tiny amounts (picometers) that affect this process. If AfterDecimalPoint = 0 Then 'if the number after the decimal point is 0 then it is a whole number therefore nothing after decimal point, therefore numbers after decimal point (precision) = 0 oDim.TolerancePrecision = 0 Else 'Otherwise the precision become how many numbers make up that Tol after the decimal point. a further 2 is taken away to remove the '0.' at the start of the number. Eg in 0.34 we want to remove the '0.' to allow it to become '34' and this is 2 digits long therefore our precision is 2 digits long. oDim.TolerancePrecision = AfterDecimalPoint.ToString.Length - 2 End If End If Next
Many thanks,
Harvey