How to add automatically linear tolerances.

How to add automatically linear tolerances.

Anonymous
Not applicable
1,267 Views
5 Replies
Message 1 of 6

How to add automatically linear tolerances.

Anonymous
Not applicable

Hi everyone,

I'm trying to find a way in which add in a automatic way the linear limits according to a standard rule like ISO2768-mk, because we are using a new machine in which we upload the file in .step.

What I am doing now is adding the tolerances manually in the sketch, and I would like to know if there is a quickest way to do that.

Hope you can help me.

 

Thanks.

0 Likes
Accepted solutions (1)
1,268 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Do you mean like the "Application Protocol" or the "Spline Fit Accuracy" setting in the Options when you export a model document to a STEP file?  If so, here is a link to a sample VBA macro for exporting to STEP, that includes setting the application protocol, and the spline fit accuracy option is called "export_fit_tolerance".

If not, which specific setting are you referring to when you say "linear tolerances"?

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

Anonymous
Not applicable

@WCrihfield 

Thanks for your reply, but it is not what I'm looking for.

Here there is a picture in which you can see that I'd added the specific tolerances, those that are out of the general rule ISO 2768 for the standards tolerances.

I want to add to every dimension (that hasn't a specific tolerance) the general linear tolerances, according to the rule, but in an automatic way.

Maybe am I looking for a setting in which I can add a general rule for the tolerances??

Thanks!

 

XBNG.png

0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor
Accepted solution

I have made an attempt at a solution for you.  I'm not sure if it is exactly what you wanted, and it may need more 'tweaking', but there's quite a bit of work done for you in there, so it should be a pretty good start, if you need to further customize it.

I created a custom 'Enum' to control the expected input variable for what tolerance class you want to use.

I created a separate Sub routine do define all the tolerance and tolerance class settings in, to leave the main Sub a but cleaner, and you could even move more of the main Sub's code down into it if you wanted.

It assumes you are targeting the 'first' planar sketch in the part document, but you can change that however you want, if you need to specify a different sketch to target.

It is only targeting two variations of dimension constraints within the sketch, because there are many types, and not all are linear, just to avoid potential error for now, but you can expand which ones you want it to work with if you need to.

It is set to only work with dimensions that are 'driving' (not 'driven').

And it only tries to set a tolerance if the parameter being represented by that dimension is currently set to 'Default', so it won't bother ones that have a different type of tolerance already set.

Here's the code.

(Make sure you read through it before attempting to run it, and probably run it on a 'test' part first, just to be safe.)

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
		MsgBox("A Part Document must be active for this rule to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
		Exit Sub
	End If
	Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
	Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
	Dim oSketch As PlanarSketch = oPDef.Sketches.Item(1)
	For Each oDim As DimensionConstraint In oSketch.DimensionConstraints
		'MsgBox("oDim.Type.ToString = " & oDim.Type.ToString, , "")
		If oDim.Driven = False Then
			If oDim.Type = ObjectTypeEnum.kTwoPointDistanceDimConstraintObject Or _
				oDim.Type = ObjectTypeEnum.kTwoPointDistanceDimConstraintObject Then
				If oDim.Parameter.Tolerance IsNot Nothing AndAlso oDim.Parameter.Tolerance.ToleranceType = ToleranceTypeEnum.kDefaultTolerance Then
					'call sub here to set tolerance the way you want it
					SetTolerance(oDim, ToleranceClassEnum.Fine)
				End If
			End If
		End If
	Next
End Sub
Public Sub SetTolerance(ByRef oDimC As DimensionConstraint, ByVal oTolClass As ToleranceClassEnum)
	'just recreating the two variables here to enable 'intellisense' below
	Dim oDim As DimensionConstraint = oDimC
	Dim oTC As ToleranceClassEnum = oTolClass
	Dim oVal As Double = oDim.Parameter.Value
	Dim oTol As Tolerance = oDim.Parameter.Tolerance
	'define the rules of the tolerances by tolerance class
	If oTC = ToleranceClassEnum.Fine Then
		If oVal > .5 AndAlso oVal <= 3 Then
			oTol.SetToSymmetric(.05)
		ElseIf oVal > 3 AndAlso oVal <= 6 Then
			oTol.SetToSymmetric(.05)
		ElseIf oVal > 6 AndAlso oVal <= 30 Then
			oTol.SetToSymmetric(.1)
		ElseIf oVal > 30 AndAlso oVal <= 120 Then
			oTol.SetToSymmetric(.15)
		ElseIf oVal > 120 AndAlso oVal <= 400 Then
			oTol.SetToSymmetric(.2)
		ElseIf oVal > 400 AndAlso oVal <= 1000 Then
			oTol.SetToSymmetric(.3)
		ElseIf oVal > 1000 AndAlso oVal <= 2000 Then
			oTol.SetToSymmetric(.5)
		ElseIf oVal > 2000 AndAlso oVal <= 4000 Then
			'do nothing, out of range
		End If
	ElseIf oTC = ToleranceClassEnum.Medium Then
		If oVal > .5 AndAlso oVal <= 3 Then
			oTol.SetToSymmetric(.1)
		ElseIf oVal > 3 AndAlso oVal <= 6 Then
			oTol.SetToSymmetric(.1)
		ElseIf oVal > 6 AndAlso oVal <= 30 Then
			oTol.SetToSymmetric(.2)
		ElseIf oVal > 30 AndAlso oVal <= 120 Then
			oTol.SetToSymmetric(.3)
		ElseIf oVal > 120 AndAlso oVal <= 400 Then
			oTol.SetToSymmetric(.5)
		ElseIf oVal > 400 AndAlso oVal <= 1000 Then
			oTol.SetToSymmetric(.8)
		ElseIf oVal > 1000 AndAlso oVal <= 2000 Then
			oTol.SetToSymmetric(1.2)
		ElseIf oVal > 2000 AndAlso oVal <= 4000 Then
			oTol.SetToSymmetric(2.0)
		End If
	ElseIf oTC = ToleranceClassEnum.Coarse Then
		If oVal > .5 AndAlso oVal <= 3 Then
			oTol.SetToSymmetric(.2)
		ElseIf oVal > 3 AndAlso oVal <= 6 Then
			oTol.SetToSymmetric(.3)
		ElseIf oVal > 6 AndAlso oVal <= 30 Then
			oTol.SetToSymmetric(.5)
		ElseIf oVal > 30 AndAlso oVal <= 120 Then
			oTol.SetToSymmetric(.8)
		ElseIf oVal > 120 AndAlso oVal <= 400 Then
			oTol.SetToSymmetric(1.2)
		ElseIf oVal > 400 AndAlso oVal <= 1000 Then
			oTol.SetToSymmetric(2.0)
		ElseIf oVal > 1000 AndAlso oVal <= 2000 Then
			oTol.SetToSymmetric(3.0)
		ElseIf oVal > 2000 AndAlso oVal <= 4000 Then
			oTol.SetToSymmetric(4.0)
		End If
	ElseIf oTC = ToleranceClassEnum.VeryCoarse Then
		If oVal > .5 AndAlso oVal <= 3 Then
			'do nothing, out of range
		ElseIf oVal > 3 AndAlso oVal <= 6 Then
			oTol.SetToSymmetric(.5)
		ElseIf oVal > 6 AndAlso oVal <= 30 Then
			oTol.SetToSymmetric(1.0)
		ElseIf oVal > 30 AndAlso oVal <= 120 Then
			oTol.SetToSymmetric(1.5)
		ElseIf oVal > 120 AndAlso oVal <= 400 Then
			oTol.SetToSymmetric(2.5)
		ElseIf oVal > 400 AndAlso oVal <= 1000 Then
			oTol.SetToSymmetric(4.0)
		ElseIf oVal > 1000 AndAlso oVal <= 2000 Then
			oTol.SetToSymmetric(6.0)
		ElseIf oVal > 2000 AndAlso oVal <= 4000 Then
			oTol.SetToSymmetric(8.0)
		End If
	End If
End Sub

Public Enum ToleranceClassEnum
	Fine
	Medium
	Coarse
	VeryCoarse
End Enum

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 6

Anonymous
Not applicable

@WCrihfield 

Many, many, many thanks, that's what I was looking for.

 

Thanks again for your time 🙂

0 Likes
Message 6 of 6

Maximilian.Prasser
Participant
Participant

Someone have an idea how i can set the tolerance of the dimension by using two different parameters with ilogic.

Base Value should be 1096,60mm.

MaximilianPrasser_3-1738159344196.png

Thanks in Advance

 

0 Likes