iLogic Rule to change tolerances/decimal places on .idw items

iLogic Rule to change tolerances/decimal places on .idw items

sbone94WTK
Explorer Explorer
764 Views
7 Replies
Message 1 of 8

iLogic Rule to change tolerances/decimal places on .idw items

sbone94WTK
Explorer
Explorer

I am learning iLogic and have a few questions. I have created a rule that dimensions the height of my part.

I would like to turn on of my dimensions into a reference and one into a symmetric tolerance (+/-.18).

I've included my current rule code below, lines 11 and 12 are the two dimensions I'd like to change.

If possible I'd also like to make line 13 to 3 decimal places. I am very new with both iLogic and VB so if you provide a solution I'd greatly appreciate an explanation as well. So far I've done this much by scouring these and other forums.

 

Thanks!

 

'View1 Dimensions
Dim Sheet_1 = ThisDrawing.Sheets.ItemByName("Sheet:1")
Dim VIEW1 = Sheet_1.DrawingViews.ItemByName("VIEW1")
Dim namedGeometry1 = VIEW1.GetIntent("Face2")
Dim namedGeometry2 = VIEW1.GetIntent("TopPlane")
Dim namedGeometry3 = VIEW1.GetIntent("Edge1")
Dim namedGeometry4 = VIEW1.GetIntent("Face4")
Dim namedGeometry5 = VIEW1.GetIntent("Face3")
Dim genDims = Sheet_1.DrawingDimensions.GeneralDimensions
'Dim linDim1 = genDims.AddLinear("Dimension 1", VIEW1.SheetPoint(0.5, -0.1), namedGeometry1)
Dim linDim2 = genDims.AddLinear("Dimension 2", VIEW1.SheetPoint(1.00, -0.1), namedGeometry2, namedGeometry3)
Dim linDim3 = genDims.AddLinear("Dimension 3", VIEW1.SheetPoint(-0.125, -0.1), namedGeometry2, namedGeometry4)
Dim linDim4 = genDims.AddLinear("Dimension 4", VIEW1.SheetPoint(-0.125, -0.1), namedGeometry1, namedGeometry5)

 

 

0 Likes
Accepted solutions (1)
765 Views
7 Replies
Replies (7)
Message 2 of 8

tyler.warner
Advocate
Advocate
Accepted solution

@sbone94WTK you can set the types with these commands at the end of your code. Additional info can be found in the Inventor API (link) .

Dim oUnitOfMeas As UnitsOfMeasure = ThisApplication.ActiveDocument.UnitsOfMeasure

Dim linDim1Tol As Double = .5
' Inventor default length type is centimeters. Below line convertes input based on document settings.
linDim1Tol = oUnitOfMeas.ConvertUnits(linDim1Tol, kDefaultDisplayLengthUnits, kDatabaseLengthUnits)
linDim1.NativeEntity.Tolerance.SetToSymmetric(linDim1Tol) ' Value of tolerance.
linDim1.NativeEntity.TolerancePrecision = 3 'Length of tolerance.
If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes
Message 3 of 8

sbone94WTK
Explorer
Explorer

Tyler,

 

Thanks for replying to my question. I was able to use your code to produce the +/- tolerance. However, when I do the 3 decimal place tolerance it continues to show only 2 decimal places (my value is .235 and it shows .24). If I go in and manually change this the primary unit is still showing two decimals but the primary tolerance is showing 3 decimals.

This is likely a misunderstanding on my part.

 

Thanks again

0 Likes
Message 4 of 8

WCrihfield
Mentor
Mentor

Just a thought, but since the 'input' variable within the Tolerance.SetToSymmetric() method is defined as Variant, that leads me to believe that it will accept either a Double, or a String.  There are many places that will accept either, so it seems plausible to me that it could be here to.  If that is the case, you could simply set that value like SetToSymmetric(".18 in"), if you are working with Inches, that way you don't need to mess around with attempting to convert units.  And since this method does not specify whether it defaults to 'database units' or not, its hard to say if they might be understood as document units instead anyways.

They really need to do a lot of work on their online help area to clarify these types of things.  I have submitted many change requests to them about it myself over the years.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 8

tyler.warner
Advocate
Advocate

@sbone94WTK add this line to the above code to control the precision of the actual dimension:

 

linDim1.NativeEntity.Precision = 3

 

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes
Message 6 of 8

sbone94WTK
Explorer
Explorer

Tyler, just curious is it possible to only change one dimension to dual unit. For example, if I have a round piece steel sheet and I want to add a hole in the center. I need the diameter of the steel to be in inches but the hole I need to show both inches and millimeters. Can I set the hole dimension to show both and the diameter of the steel to be only inches.

0 Likes
Message 7 of 8

tyler.warner
Advocate
Advocate

The easiest way to do that would be to manually add another dimension style (with alternate units displayed) thru the styles editor on the manage tab of the ribbon. This would only need to be done once. Then you can just set your dimension to that style when you want certain dimensions to have alternate units. Below would demonstrate that.

 

Add to the code above before linDim1 is defined:

 

Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oDimStyle As Style = oDoc.StylesManager.DimensionStyles.Item("IN_MM")

 

 

Add to the code above to add to the definition of linDim1:

 

linDim1.NativeEntity.Style = oDimStyle

 

 

-----

If you wanted to create the new style with code, you'd be able to do something like the example below:

 

Add to the code above before linDim1 is defined:

 

Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oDimStyle As DimensionStyle
Try
	oDimStyle = oDoc.StylesManager.DimensionStyles.Item("IN_MM")
Catch
	oDimStyle = oDoc.StylesManager.DimensionStyles.Item("IN_ONLY").Copy("IN_MM")
	''https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=DimensionStyle
	oDimStyle.DimensionDualFormat = kAdjacentWithBracketsForAlternateFormat
	oDimStyle.AlternateDisplayUnitType = True
	oDimStyle.AlternateLinearUnits = kMillimeterLengthUnits
	oDimStyle.AlternateLinearPrecision = kOneDecimalPlaceLinearPrecision
	oDimStyle.ToleranceAlternateUnitPrecision = 1
End Try

 

 

Add to the code above to add to the definition of linDim1:

 

linDim1.NativeEntity.Style = oDimStyle

 

 

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes
Message 8 of 8

yuriboutique10
Community Visitor
Community Visitor

Hi, Thanks for your reppy. 

I want a ilogic about precision tolerance for the Dimension, can you help me? Thanks.

0 Likes