Message 1 of 13
iLogic - Code to add a specific tolerance to a selected hole
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
With the help of a few folks on this forum, I was able to create a small utility to apply a standard set of tolerances to dowel holes. Since I'm in the tool and die business, we pin a lot of components in place. So I wanted to be able to select some specific press fit holes and apply a H6 tolerance to them en masse. I also wanted to do the same thing with a "deviation" tolerance of +0.001" / -0.000" to any slip fit holes.
Anyway, here's the code for the press fit version:
Dim oDoc As Document
oDoc = ThisApplication.ActiveEditDocument
Dim i As Integer
i = 1
Dim Proceed As Integer
Dim FeatureCount As Integer
Dim HoleModCount As Integer
If ThisDoc.Document.SelectSet.count <1 Then ' Verify the total number of selected features
q = MessageBox.Show("You must select at least one hole.", "iLogic Error", MessageBoxButtons.OK, MessageBoxIcon.asterisk, MessageBoxDefaultButton.Button1)
Exit Sub
End If
FeatureCount = ThisDoc.Document.SelectSet.count ' Store the total number of selected features
HoleModCount = 0 ' Zero the counter for modified holes
'For Each CurrentHole As HoleFeature In oDoc.ComponentDefinition.Features.HoleFeatures ' Run on ALL Holes
'For Each CurrentHole As HoleFeature In ThisDoc.Document.SelectSet ' Run on SELECTED Holes
For Each CurrentHole In ThisDoc.Document.SelectSet ' Run on SELECTED Features
'If CurrentHole.Suppressed = False Then Proceed = 0 'Run command on suppressed features
Proceed = 0 ' Green light variable
If CurrentHole.Type = ObjectTypeEnum.kHoleFeatureObject Then ' Check to make sure this feature is a hole
Proceed = 1 ' Green light
If CurrentHole.Tapped = True Then Proceed = 0 ' Cancel if a tapped hole
Else
Proceed = 0 ' Red light if the feature isn't a hole
End If
If Proceed = 1 Then
Dim oDef As PartComponentDefinition
oDef = oDoc.ComponentDefinition
Dim oHole(i) As HoleFeature
oHole(i) = oDef.Features.HoleFeatures.Item(i)
Dim oDiamParam(i) As Parameter
oDiamParam(i) = oHole(i).HoleDiameter
Dim oTol(i) As Tolerance
oTol(i) = oDiamParam(i).Tolerance
If oTol(i).ToleranceType() = 31233 Then ' If the hole currently has a default tolerance
oTol(i).SetToFits(31244,("H6"),("")) ' Modify the hole tolerance
HoleModCount = HoleModCount + 1 ' Bump the counter
InventorVb.DocumentUpdate() ' Update Doc
End If
End If
Next CurrentHole ' Next Feature
q = MessageBox.Show(FeatureCount & " features were selected. " & HoleModCount & " hole(s) were modified. ", "iLogic Summary", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
oDoc.Update()
'Reference Info:
'Const kBasicTolerance = 31245
'Const kDefaultTolerance = 31233
'Const kDeviationTolerance = 31236
'Const kLimitLinearTolerance = 31238
'Const kLimitsFitsLinearTolerance = 31242
'Const kLimitsFitsShowSizeTolerance = 31243
'Const kLimitsFitsShowTolerance = 31244
'Const kLimitsFitsStackedTolerance = 31241
'Const kLimitsStackedTolerance = 31237
'Const kMaxTolerance = 31239
'Const kMinTolerance = 31240
'Const kOverrideTolerance = 31234
'Const kReferenceTolerance = 31246
'Const kSymmetricTolerance = 31235And here's the code for the slip fit version:
Dim oDoc As Document
oDoc = ThisApplication.ActiveEditDocument
Dim i As Integer
i = 1
Dim Proceed As Integer
Dim FeatureCount As Integer
Dim HoleModCount As Integer
If ThisDoc.Document.SelectSet.count <1 Then ' Verify the total number of selected features
q = MessageBox.Show("You must select at least one hole.", "iLogic Error", MessageBoxButtons.OK, MessageBoxIcon.asterisk, MessageBoxDefaultButton.Button1)
Exit Sub
End If
FeatureCount = ThisDoc.Document.SelectSet.count ' Store the total number of selected features
HoleModCount = 0 ' Zero the counter for modified holes
'For Each CurrentHole As HoleFeature In oDoc.ComponentDefinition.Features.HoleFeatures ' Run on ALL Holes
'For Each CurrentHole As HoleFeature In ThisDoc.Document.SelectSet ' Run on SELECTED Holes
For Each CurrentHole In ThisDoc.Document.SelectSet ' Run on SELECTED Features
'If CurrentHole.Suppressed = False Then Proceed = 0 'Run command on suppressed features
Proceed = 0 ' Green light variable
If CurrentHole.Type = ObjectTypeEnum.kHoleFeatureObject Then ' Check to make sure this feature is a hole
Proceed = 1 ' Green light
If CurrentHole.Tapped = True Then Proceed = 0 ' Cancel if a tapped hole
Else
Proceed = 0 ' Red light if the feature isn't a hole
End If
If Proceed = 1 Then
Dim oDef As PartComponentDefinition
oDef = oDoc.ComponentDefinition
Dim oHole(i) As HoleFeature
oHole(i) = oDef.Features.HoleFeatures.Item(i)
Dim oDiamParam(i) As Parameter
oDiamParam(i) = oHole(i).HoleDiameter
Dim oTol(i) As Tolerance
oTol(i) = oDiamParam(i).Tolerance
If oTol(i).ToleranceType() = 31233 Then ' If the hole currently has a default tolerance
oTol(i).SetToDeviation("0.001 in","0.0 in") ' Modify the hole tolerance
HoleModCount = HoleModCount + 1 ' Bump the counter
InventorVb.DocumentUpdate() ' Update Doc
End If
End If
Next CurrentHole 'Next Feature
q = MessageBox.Show(FeatureCount & " features were selected. " & HoleModCount & " hole(s) were modified. ", "iLogic Summary", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
oDoc.Update()
'Reference Info:
'Const kBasicTolerance = 31245
'Const kDefaultTolerance = 31233
'Const kDeviationTolerance = 31236
'Const kLimitLinearTolerance = 31238
'Const kLimitsFitsLinearTolerance = 31242
'Const kLimitsFitsShowSizeTolerance = 31243
'Const kLimitsFitsShowTolerance = 31244
'Const kLimitsFitsStackedTolerance = 31241
'Const kLimitsStackedTolerance = 31237
'Const kMaxTolerance = 31239
'Const kMinTolerance = 31240
'Const kOverrideTolerance = 31234
'Const kReferenceTolerance = 31246
'Const kSymmetricTolerance = 31235