Setting dimension tolerance types

Setting dimension tolerance types

Anonymous
Not applicable
4,835 Views
21 Replies
Message 1 of 22

Setting dimension tolerance types

Anonymous
Not applicable
Is anybody aware of a method to set all the Tolerance Types for a GeneralDimension via VBA.
The Tolerance object, accessible via the GeneralDimension object, offers methods to set Deviation, Fits, Limits & Symmetric tolerance types, but I can’t find a way to set other Tolerance types, such as Reference, Basic, Max & Min
0 Likes
Accepted solutions (1)
4,836 Views
21 Replies
Replies (21)
Message 2 of 22

Anonymous
Not applicable
Unfortunately, the API does not currently support these tolerance types. Sanjay- "DavidRichardson" wrote in message news:33417847.1108375962669.JavaMail.jive@jiveforum2.autodesk.com... > Is anybody aware of a method to set all the Tolerance Types for a GeneralDimension via VBA. > The Tolerance object, accessible via the GeneralDimension object, offers methods to set Deviation, Fits, Limits & Symmetric tolerance types, but I can't find a way to set other Tolerance types, such as Reference, Basic, Max & Min
0 Likes
Message 3 of 22

Anonymous
Not applicable
OK, it would have been nice, but never mind.
Thanks for looking.
0 Likes
Message 4 of 22

Curtis_Waguespack
Consultant
Consultant
Accepted solution

I ran across this thread when searching.

 

Here's a quick iLogic example of this, in case it helps someone who finds this thread in the future.

 

 I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

' Set a reference to the select set of the active document.
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument

' Find all selected occurrences and add them to an ObjectCollection.
Dim oDrawingDims As DrawingDimension

'Loop through all dimensions
For Each oDrawingDims In oDoc.ActiveSheet.DrawingDimensions
'set the Tolerance Method
'oDrawingDims.Tolerance.SetToDefault
'oDrawingDims.Tolerance.SetToBasic 
oDrawingDims.Tolerance.SetToReference
Next 

 

'deviation example

' Set a reference to the select set of the active document. Dim oDoc As DrawingDocument oDoc = ThisApplication.ActiveDocument ' Find all selected occurrences and add them to an ObjectCollection. Dim oDrawingDims As DrawingDimension 'Loop through all dimensions For Each oDrawingDims In oDoc.ActiveSheet.DrawingDimensions 'set Tolerance Method oDrawingDims.Tolerance.SetToDeviation( 0.5, -0.5) Next

 

'symmetric example
' Set a reference to the select set of the active document. Dim oDoc As DrawingDocument oDoc = ThisApplication.ActiveDocument ' Find all selected occurrences and add them to an ObjectCollection. Dim oDrawingDims As DrawingDimension 'Loop through all dimensions For Each oDrawingDims In oDoc.ActiveSheet.DrawingDimensions 'set Tolerance Method oDrawingDims.Tolerance.SetToSymmetric( 0.5) Next

 

 

'limits example

' Set a reference to the select set of the active document.
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument

' Find all selected occurrences and add them to an ObjectCollection.
Dim oDrawingDims As DrawingDimension

'Loop through all dimensions
For Each oDrawingDims In oDoc.ActiveSheet.DrawingDimensions
'set Tolerance Method
oDrawingDims.Tolerance.SetToLimits(ToleranceTypeEnum.kLimitsStackedTolerance,"0.2", "0.1")
'oDrawingDims.Tolerance.SetToLimits(ToleranceTypeEnum.kLimitLinearTolerance ,"0.2", "0.1")
Next 

 

EESignature

Message 5 of 22

forbillian
Advocate
Advocate

Hi Curtis,

 

Thank You for posting those examples - they have really helped.

 

I have been trying for a few days to find a way of controlling the precision on the deviation example you posted to '0' decimal places & all I can find as a solution is to change dimension style.

 

I found this code by Mjdeck which i have been trying to adapt to my deviation values, but with no luck.

 

Anyhelp would be appreciated.

 

For Each sheetX As sheet In ThisDrawing.Document.Sheets
  For Each drawingDim as DrawingDimension In sheetX.DrawingDimensions
     drawingDim.ModelValueOverridden = False
     Dim genDim As GeneralDimension = TryCast(drawingDim, GeneralDimension)
     If (genDim IsNot Nothing) Then
       If (DrawingUnits = "in") Then
         genDim.Style.LinearPrecision = LinearPrecisionEnum.kThreeDecimalPlacesLinearPrecision 
       ElseIf (DrawingUnits = "mm") Then
         genDim.Style.LinearPrecision = LinearPrecisionEnum.kTwoDecimalPlacesLinearPrecision 
         drawingDim.OverrideModelValue = drawingDim.ModelValue * 25.4
       End If
    End If
  Next
Next

 

0 Likes
Message 6 of 22

Formsprag
Advocate
Advocate

This code works GREAT for all dimensions on a drawing, but how do you single out "Dimension 1" & "Dimension 2" as Default while "Dimension 3" & "Dimension 4" are set to Reference?

0 Likes
Message 7 of 22

forbillian
Advocate
Advocate

@Formsprag 

 

I have found it easier using the select method - so the rule applies to anything you select visually. This is what I used based on @Curtis_Waguespack examples:

 

Sub Main()''deviation example

' Set a reference to the select set of the active document.
	Dim oDoc As DrawingDocument
	oDoc = ThisApplication.ActiveDocument


' Find all selected occurrences/dimensins and add them to an ObjectCollection.
	Dim oDrawingDims As DrawingDimension
	Dim oSSet As SelectSet = oDoc.SelectSet
	'Loop through all dimensions
	For Each oDrawingDims In oSSet
	
	'1. DEVIATION VALUES
'	Add Tolerance Deviation - the below gives a = +0/-1 result
	oDrawingDims.Tolerance.SetToDeviation(+ 0.0, - 0.1)
	
	'2. TOLERATION PRECISION
'	Change the Tolerance Precision to suit 0, or 1 or 2 etc
	oDrawingDims.TolerancePrecision = 0
	
	'3. STD PRECISION
'	Change the Std Precision to suit 0, or 1 or 2 etc
	'oDrawingDims.Precision = 0
	
Next  

End Sub
Message 8 of 22

Formsprag
Advocate
Advocate

That's works but it's not quite what I'm after. This drawing is going to end up as a sales tool, I don't think I want a salesman selecting which dimensions are what. It needs to be set by the program so every drawing is the same every time.

 

In the example below: Dimensions 1 & 4 needs to be default 1 decimal place, Dimensions 2, 3 & 6 needs to be reference 2 decimal places and Dimension 5 needs to be MAX 3 decimals. 

 

2020-07-13_5-25-22.jpg

0 Likes
Message 9 of 22

forbillian
Advocate
Advocate

Ahhh Gotya now @Formsprag 

 

I will post something soon that could do the trick.

0 Likes
Message 10 of 22

forbillian
Advocate
Advocate

This should work for you. @Formsprag 

 

I have tested it and it seems to do the trick - if you need a rule that applies this to multiple drawings in batch let me know.  Hope it works for you.

 

Credit given to @Vladimir.Ananyev for the basis of this code.

https://forums.autodesk.com/t5/inventor-customization/how-do-i-retrieve-a-drawing-dimension-value-wi...

 

 

Sub Main EditDimPrecision()
 
    Dim oDoc As DrawingDocument
     oDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet
     oSheet = oDoc.ActiveSheet
 
    Dim oGeneralDimensions As GeneralDimensions
     oGeneralDimensions = oSheet.DrawingDimensions.GeneralDimensions
	 
	Dim oDim As GeneralDimension
	
	Dim i As Long
		For i = 1 To 6			
  			'get the reference to a dimension by item #
       		oDim = oGeneralDimensions.Item(i)
		 	
			If i = 1 Or i = 4 Then
				oDim.Precision = 1
			ElseIf i = 2 Or i = 3 Or i = 6 Then
				oDim.Precision = 2
			Else If i = 5 Then
				oDim.Precision = 3
			End If
		
		Next i
	 
 End Sub

 

0 Likes
Message 11 of 22

Formsprag
Advocate
Advocate

This is perfect for setting the Precision but that only gets me halfway to my goal.

 

Is there any way to set the Tolerance Method as well within this rule?

 

In the example below I need:

  • Dimensions 1 & 4 to be 1 decimal place and the Tolerance Method set to Default
  • Dimensions 2, 3 & 6 to be 2 decimal places and the Tolerance Method set to Reference
  • Dimensions 5 to be 3 decimal places and the Tolerance Method set to MAX

I found a rule that works for all dimensions to be set to one Tolerance Method, but I need to change the Method by item # defined in the code. See post for Method snippets https://forums.autodesk.com/t5/inventor-customization/setting-dimension-tolerance-types/m-p/3820804/...

 

2020-07-17_7-07-44.jpg2020-07-17_7-08-40.jpg

0 Likes
Message 12 of 22

forbillian
Advocate
Advocate
Sure is - watch this space


0 Likes
Message 13 of 22

forbillian
Advocate
Advocate

Something like this @Formsprag ?

 

Sub Main EditDimPrecision()
 
    Dim oDoc As DrawingDocument
     oDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet
     oSheet = oDoc.ActiveSheet
 
    Dim oGeneralDimensions As GeneralDimensions
     oGeneralDimensions = oSheet.DrawingDimensions.GeneralDimensions
	 
	Dim oDim As GeneralDimension
	
	Dim i As Long
		For i = 1 To 6			
  			'get the reference to a dimension by item #
       		oDim = oGeneralDimensions.Item(i)
		 	
			If i = 1 Or i = 4 Then
				oDim.Precision = 1
				oDim.Tolerance.SetToDefault 
			ElseIf i = 2 Or i = 3 Or i = 6 Then
				oDim.Precision = 2
				oDim.Tolerance.SetToReference
			Else If i = 5 Then
				oDim.Precision = 3
				oDim.Tolerance.SetToMAX()
			End If
		
		Next i
	 
 End Sub
0 Likes
Message 14 of 22

Formsprag
Advocate
Advocate

Perfect!!!! Thank you!!

 

How do I incorporate this into an existing rule?  I would like it to be integrated into the rule applying the dimensions and not the iLogicVb.RunRule method.

 

'Get Sheet, View, Intent
Dim Sheet_1 = ThisDrawing.Sheets.ItemByName("Sheet:1")
Dim FRONT_VIEW = Sheet_1.DrawingViews.ItemByName("FRONT VIEW")

'Standard Housing
Dim WP_S_MP = FRONT_VIEW.GetIntent("2021_2-250008-15-001:1", "WP_S_MP")
Dim WP_S_FVCP = FRONT_VIEW.GetIntent("2021_2-250008-15-001:1", "WP_S_FVCP")
Dim WP_S_F1_OE = FRONT_VIEW.GetIntent("2021_2-250008-15-001:1", "WP_S_F1_OE")
Dim WP_S_F1_IE = FRONT_VIEW.GetIntent("2021_2-250008-15-001:1", "WP_S_F1_IE")
Dim WP_S_F2_OE = FRONT_VIEW.GetIntent("2021_2-250008-15-001:1", "WP_S_F2_OE")
Dim WP_S_F2_IE = FRONT_VIEW.GetIntent("2021_2-250008-15-001:1", "WP_S_F2_IE")
Dim WP_S_FLH = FRONT_VIEW.GetIntent("2021_2-250008-15-001:1", "WP_S_FLH")
Dim WP_GV_RH = FRONT_VIEW.GetIntent({"2021_2-250004-98-000:1", "2021-2-250004-21-016:1" }, "WP_GV_RH")
Dim WP_GV_LH = FRONT_VIEW.GetIntent({"2021_2-250004-98-000:1", "2021-2-250004-21-016:1" }, "WP_GV_LH")
Dim F_B_TF = FRONT_VIEW.GetIntent({"2021_2-250004-98-000:1", "2021-150003-21-018:1" }, "F_B_TF")



'Calculations for Dimension Placement

	Dim HorizontalLengthPos = ThisDrawing.Geometry.Point2d(0, 0)
	HorizontalLengthPos.InDatabaseUnits = WP_S_MP.PointOnSheet
	HorizontalLengthPos.Y = HorizontalLengthPos.Y - 1.5 * FRONT_VIEW.Scale

	Dim HorizontalLengthPos2 = ThisDrawing.Geometry.Point2d(0, 0)
	HorizontalLengthPos2.InDatabaseUnits = WP_S_MP.PointOnSheet
	HorizontalLengthPos2.Y = HorizontalLengthPos2.Y - 3 * FRONT_VIEW.Scale
	
	Dim VerticalLengthPos = ThisDrawing.Geometry.Point2d(0, 0)
	VerticalLengthPos.InDatabaseUnits = WP_GV_RH.PointOnSheet
	VerticalLengthPos.X = VerticalLengthPos.X + 1.5 * FRONT_VIEW.Scale

	Dim VerticalLengthPos2 = ThisDrawing.Geometry.Point2d(0, 0)
	VerticalLengthPos2.InDatabaseUnits = WP_GV_RH.PointOnSheet
	VerticalLengthPos2.X = VerticalLengthPos2.X + 3 * FRONT_VIEW.Scale


'Dimensions
ThisDrawing.BeginManage()
	Dim genDims = Sheet_1.DrawingDimensions.GeneralDimensions
	Dim linDim1 = genDims.AddLinear("Dimension 1", HorizontalLengthPos, WP_S_F1_OE, WP_S_F1_IE)
	Dim linDim2 = genDims.AddLinear("Dimension 2", HorizontalLengthPos, WP_S_F2_OE,WP_S_F2_IE)
	Dim linDim3 = genDims.AddLinear("Dimension 3", HorizontalLengthPos2, WP_S_MP, WP_S_FLH, DimensionTypeEnum.kHorizontalDimensionType)
	Dim linDim4 = genDims.AddLinear("Dimension 4", HorizontalLengthPos2, WP_S_MP, WP_GV_RH, DimensionTypeEnum.kHorizontalDimensionType)
	Dim linDim5 = genDims.AddLinear("Dimension 5", VerticalLengthPos, WP_S_F2_OE, WP_S_FVCP, DimensionTypeEnum.kVerticalDimensionType)
	Dim linDim6 = genDims.AddLinear("Dimension 6", VerticalLengthPos2, WP_S_F2_OE, F_B_TF, DimensionTypeEnum.kVerticalDimensionType)
0 Likes
Message 15 of 22

forbillian
Advocate
Advocate

@Formsprag 

 

Ok so if that rule works for you?  I would do something like this:

 

Sub Main()
	
	'Get Sheet, View, Intent
Dim Sheet_1 = ThisDrawing.Sheets.ItemByName("Sheet:1")
Dim FRONT_VIEW = Sheet_1.DrawingViews.ItemByName("FRONT VIEW")

'Standard Housing
Dim WP_S_MP = FRONT_VIEW.GetIntent("2021_2-250008-15-001:1", "WP_S_MP")
Dim WP_S_FVCP = FRONT_VIEW.GetIntent("2021_2-250008-15-001:1", "WP_S_FVCP")
Dim WP_S_F1_OE = FRONT_VIEW.GetIntent("2021_2-250008-15-001:1", "WP_S_F1_OE")
Dim WP_S_F1_IE = FRONT_VIEW.GetIntent("2021_2-250008-15-001:1", "WP_S_F1_IE")
Dim WP_S_F2_OE = FRONT_VIEW.GetIntent("2021_2-250008-15-001:1", "WP_S_F2_OE")
Dim WP_S_F2_IE = FRONT_VIEW.GetIntent("2021_2-250008-15-001:1", "WP_S_F2_IE")
Dim WP_S_FLH = FRONT_VIEW.GetIntent("2021_2-250008-15-001:1", "WP_S_FLH")
Dim WP_GV_RH = FRONT_VIEW.GetIntent({"2021_2-250004-98-000:1", "2021-2-250004-21-016:1" }, "WP_GV_RH")
Dim WP_GV_LH = FRONT_VIEW.GetIntent({"2021_2-250004-98-000:1", "2021-2-250004-21-016:1" }, "WP_GV_LH")
Dim F_B_TF = FRONT_VIEW.GetIntent({"2021_2-250004-98-000:1", "2021-150003-21-018:1" }, "F_B_TF")



'Calculations for Dimension Placement

	Dim HorizontalLengthPos = ThisDrawing.Geometry.Point2d(0, 0)
	HorizontalLengthPos.InDatabaseUnits = WP_S_MP.PointOnSheet
	HorizontalLengthPos.Y = HorizontalLengthPos.Y - 1.5 * FRONT_VIEW.Scale

	Dim HorizontalLengthPos2 = ThisDrawing.Geometry.Point2d(0, 0)
	HorizontalLengthPos2.InDatabaseUnits = WP_S_MP.PointOnSheet
	HorizontalLengthPos2.Y = HorizontalLengthPos2.Y - 3 * FRONT_VIEW.Scale
	
	Dim VerticalLengthPos = ThisDrawing.Geometry.Point2d(0, 0)
	VerticalLengthPos.InDatabaseUnits = WP_GV_RH.PointOnSheet
	VerticalLengthPos.X = VerticalLengthPos.X + 1.5 * FRONT_VIEW.Scale

	Dim VerticalLengthPos2 = ThisDrawing.Geometry.Point2d(0, 0)
	VerticalLengthPos2.InDatabaseUnits = WP_GV_RH.PointOnSheet
	VerticalLengthPos2.X = VerticalLengthPos2.X + 3 * FRONT_VIEW.Scale


'Dimensions
ThisDrawing.BeginManage()
	Dim genDims = Sheet_1.DrawingDimensions.GeneralDimensions
	Dim linDim1 = genDims.AddLinear("Dimension 1", HorizontalLengthPos, WP_S_F1_OE, WP_S_F1_IE)
	Dim linDim2 = genDims.AddLinear("Dimension 2", HorizontalLengthPos, WP_S_F2_OE,WP_S_F2_IE)
	Dim linDim3 = genDims.AddLinear("Dimension 3", HorizontalLengthPos2, WP_S_MP, WP_S_FLH, DimensionTypeEnum.kHorizontalDimensionType)
	Dim linDim4 = genDims.AddLinear("Dimension 4", HorizontalLengthPos2, WP_S_MP, WP_GV_RH, DimensionTypeEnum.kHorizontalDimensionType)
	Dim linDim5 = genDims.AddLinear("Dimension 5", VerticalLengthPos, WP_S_F2_OE, WP_S_FVCP, DimensionTypeEnum.kVerticalDimensionType)
	Dim linDim6 = genDims.AddLinear("Dimension 6", VerticalLengthPos2, WP_S_F2_OE, F_B_TF, DimensionTypeEnum.kVerticalDimensionType)

	Call EditDimPrecision

End Sub



Private Sub EditDimPrecision()
 
    Dim oDoc As DrawingDocument
     oDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet
     oSheet = oDoc.ActiveSheet
 
    Dim oGeneralDimensions As GeneralDimensions
     oGeneralDimensions = oSheet.DrawingDimensions.GeneralDimensions
	 
	Dim oDim As GeneralDimension
	
	Dim i As Long
		For i = 1 To 6			
  			'get the reference to a dimension by item #
       		oDim = oGeneralDimensions.Item(i)
		 	
			If i = 1 Or i = 4 Then
				oDim.Precision = 1
				oDim.Tolerance.SetToDefault 
			ElseIf i = 2 Or i = 3 Or i = 6 Then
				oDim.Precision = 2
				oDim.Tolerance.SetToReference
			Else If i = 5 Then
				oDim.Precision = 3
				oDim.Tolerance.SetToMax
			End If
		
		Next i
	 
 End Sub



 

Message 16 of 22

Formsprag
Advocate
Advocate

I figured it out, just had to remove the Sub main, End Sub.....

 

Thank you for your help!!!!

Message 17 of 22

Formsprag
Advocate
Advocate

One last dimension setting. I have a 3 decimal place Limit-Stacked Dimension it set, with the help of forbillian the code below solved the problem! Thanks forbillian for all you help!

 

Private Sub EditDimPrecision()
 
    Dim oDoc As DrawingDocument
     oDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet
     oSheet = oDoc.ActiveSheet
 
    Dim oGeneralDimensions As GeneralDimensions
     oGeneralDimensions = oSheet.DrawingDimensions.GeneralDimensions
	 
	Dim oDim As GeneralDimension
	
	Dim i As Long
		For i = 1 To 7			
  			'get the reference to a dimension by item #
       		oDim = oGeneralDimensions.Item(i)
		 	
			If i = 1 Or i = 4 Then
				oDim.Precision = 1
				oDim.Tolerance.SetToDefault 
			ElseIf i = 2 Or i = 3 Or i = 6 Then
				oDim.Precision = 2
				oDim.Tolerance.SetToReference
			Else If i = 5 Then
				oDim.Precision = 1
				oDim.Tolerance.SetToMax
			Else If i = 7 Then
				oDim.TolerancePrecision = 1
				oDim.Tolerance.SetToLimits(ToleranceTypeEnum.kLimitsStackedTolerance,"0.2", "0.1")
				End If
		
		Next i
	 
 End Sub

 

0 Likes
Message 18 of 22

Anonymous
Not applicable

Hello Everyone,

 

I am trying to create an ilogic code for symmetric tolerances  and I have come across an existing code. However I want to add if  conditions to this code like if dimension is 0-400 then tolerance is 1 else 2 etc... 

 

I tried to add if logic, but I am getting an error cannot be converted to boolean. How can I solve this error?

 

Regards

Venkat

 

'symmetric example
' Set a reference to the select set of the active document. Dim oDoc As DrawingDocument oDoc = ThisApplication.ActiveDocument ' Find all selected occurrences and add them to an ObjectCollection. Dim oDrawingDims As DrawingDimension 'Loop through all dimensions For Each oDrawingDims In oDoc.ActiveSheet.DrawingDimensions 'set Tolerance Method oDrawingDims.Tolerance.SetToSymmetric( 0.5) Next

 

0 Likes
Message 19 of 22

adhil.pa.789
Contributor
Contributor

Thaks bro, it's great helpful for me

0 Likes
Message 20 of 22

sbalasubramanianJJDFU
Enthusiast
Enthusiast

Hi,

Can you help with ilogic code
1. to select a sketch dimension, set its median tolerance and set it deviation
2. to select a drawing dimension and set dim style accordingly (from couple of different dim styles)

0 Likes