iLogic rule that removes trailing zeros

iLogic rule that removes trailing zeros

harvey_craig2RCUH
Advocate Advocate
110 Views
1 Reply
Message 1 of 2

iLogic rule that removes trailing zeros

harvey_craig2RCUH
Advocate
Advocate

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 

0 Likes
111 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor

I think you are looking for the setting within the 'DimensionStyle' named TrailingZeroDisplay and the one named AngularTrailingZeroDisplay.  There are other properties for leading zeros, and 'included' zeros too.  You can start down that path from the GeneralDimension.Style property.  Styles 'work in mysterious ways' in drawings though. 😉  We can set a dimension or other type of drawing annotation to a specific style, but it may not adhere to every setting of that style, if it already has some style overrides applied to it.  Another thing to keep in mind is that editing a setting within a style for a single dimension, also edits that style, and other dimensions in that drawing may also be using that same style, so be careful there.  It is often best to create a new, special style which already has that modification first, then set the annotations to the special style, instead of attempting to directly edit style properties of individual annotation objects that have already been placed on the sheet.

To get there, you can start from DrawingDocument.StylesManager, but its DrawingStylesManager.DimensionStyles property represents a DimensionStylesEnumerator, which does not have an 'Add' method.  So, I think you would have to get an existing DimensionStyle object (such as the active one), then use its Copy method to create a new one, then edit the properties of that new one, and use that.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes