Counting tapped holes

Counting tapped holes

Anonymous
Not applicable
1,935 Views
7 Replies
Message 1 of 8

Counting tapped holes

Anonymous
Not applicable

Hello guys,

 

I have a question about tapped holes. I want to count all tapped holes in a part using iLogic. I'm currently working on a rule that does this and the rule already counts tapped holes and also cuts/extrusions with a thread in them. This is the rule.

 

Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
Dim oHole As HoleFeature
Dim oHoles As HoleFeatures = oDef.Features.HoleFeatures
Dim oThreadFeatures As ThreadFeatures
	oThreadFeatures = oDef.Features.ThreadFeatures
Dim oThreadFeature As ThreadFeature
Dim oThreadInfo As ThreadInfo

'Er zit verschil tussen tapped holes die met de hole functie zijn aangebracht en gaten waar een thread in is aangebracht.
'Deze worden afzonderlijk van elkaar bepaald en bij elkaar opgeteld.

MessageBox.Show(oThreadFeatures.Count, "Aantal threadfeatures")

For Each oHole In oDef.Features.HoleFeatures

If oHole.Tapped = True Then 

i=i+1

End If

Next

MessageBox.Show(i, "aantal tapgaten")

TapgatenTotaal=oThreadFeatures.Count + i

MessageBox.Show(TapgatenTotaal, "Totaal aantal tapgaten")

 

But the holes that are being counted, are all individual holes. When a tapped hole is in a pattern, the rule will count only one hole, the one that is in the model tree above the pattern. I found the rule that is below on the forum to count all holes in a pattern. I tried to modify this rule so it would only count patterns with a tapped hole as parent feature but I couldn't get it to work. I tried the following.

 

If Not (TypeOf oRP.ParentFeatures.Item(1) Is HoleFeature.Tapped) Then Continue For	

 

But this didn't work. I also tried to put all the tapped holes that are recognized in the first rule in a object collection and the run the pattern rule for each hole in the collection but that didn't work either. The rule fills in all the holes that are in the collection in every available pattern so the outcome is way to high.

 

Does anyone know how I can modify the rule (or make a new one) so it only counts tapped holes?

 

 

'assume rectangular pattern
Dim oRectPatterns As RectangularPatternFeatures = oDef.Features.RectangularPatternFeatures

Dim N As Integer = 0 'counter

For Each oRP  As RectangularPatternFeature In oRectPatterns
	'consider only hole patterns
    If Not (TypeOf oRP.ParentFeatures.Item(1) Is HoleFeature) Then Continue For	
	For Each oFPE  As FeaturePatternElement In oRP.PatternElements
		If Not oFPE.Suppressed Then N += 1
	Next
Next

'assume circular pattern
Dim oCircPatterns As CircularPatternFeatures = oDef.Features.CircularPatternFeatures


For Each oCP  As CircularPatternFeature In oCircPatterns
	'consider only hole patterns
    If Not (TypeOf oCP.ParentFeatures.Item(1) Is HoleFeature) Then Continue For	
	For Each oFPE  As FeaturePatternElement In oCP.PatternElements
		If Not oFPE.Suppressed Then N += 1
	Next
Next
MsgBox ("The number of holes in the current part is:  " & N)

Regards,

 

Eric

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

j.romo
Advocate
Advocate

Im having the same problem.

I found a code about a year ago, cant remember who posted it. but it counts rectangular patterns

I would like a Rule to count them ALL.

right now I trigger the single feature rule to count holes as the one you havve and then trigger the following rule

 

SyntaxEditor Code Snippet

' Calc Holes in HoleFeature Pattern

'assume part document
Dim oDoc As PartDocument = ThisDoc.Document
'Set oDoc = ThisApplication.ActiveDocument
Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition

'assume rectangular pattern
Dim oRectPatterns As RectangularPatternFeatures = oDef.Features.RectangularPatternFeatures

Dim N As Integer = 0 'counter

For Each oRP  As RectangularPatternFeature In oRectPatterns
	'consider only hole patterns
    If Not (TypeOf oRP.ParentFeatures.Item(1) Is HoleFeature) Then Continue For	
	For Each oFPE  As FeaturePatternElement In oRP.PatternElements
		If Not oFPE.Suppressed Then N += 1
	Next
Next

 Hope someone could share the code for circular pattern feature count

or a rule to count hem all.

 

thanks

0 Likes
Message 3 of 8

dgreatice
Collaborator
Collaborator
Accepted solution

Hi,

 

try This, I'm using iLogic:

 

Sub Main
Dim oApp As Application
Dim oPD As PartDocument
Dim oPCD As PartComponentDefinition
Dim oFeats As PartFeatures
Dim oHole As HoleFeature
Dim oRecPat As RectangularPatternFeature
Dim oCirPat As CircularPatternFeature
Dim oParentFeat As PartFeature
Dim oHoleInPat As HoleFeature
Dim oCheckHole As HoleFeature
Dim ObjCol1 As ObjectCollection

oApp = ThisApplication
oPD = oApp.ActiveDocument
oPCD = oPD.ComponentDefinition
oFeats = oPCD.Features
ObjCol1 = oApp.TransientObjects.CreateObjectCollection

For Each oRecPat In oFeats.RectangularPatternFeatures
	oParentFeat = oRecPat.ParentFeatures.Item(1)
	If oParentFeat.Type = ObjectTypeEnum.kHoleFeatureObject Then
		oHoleInPat = oParentFeat
		If oHoleInPat.Tapped = True Then
			Call ObjCol1.Add(oRecPat)
		End If
	End If
Next

For Each oCirPat In oFeats.CircularPatternFeatures
	oParentFeat = oCirPat.ParentFeatures.Item(1)
	If oParentFeat.Type = ObjectTypeEnum.kHoleFeatureObject Then
		oHoleInPat = oParentFeat
		If oHoleInPat.Tapped = True Then
			Call ObjCol1.Add(oCirPat)
		End If
	End If
Next

For Each oHole In oFeats.HoleFeatures
	If oHole.Tapped = True Then
		Call ObjCol1.Add(oHole)
	End If
Next

Dim CountHole As Double
Call GetCount(ObjCol1, CountHole)

MsgBox (CountHole)

End Sub

Sub GetCount(ByVal ObjCol1 As ObjectCollection, ByRef CountHole As Double)
For i = 1 To ObjCol1.Count
	On Error Resume Next
	If ObjCol1.Item(i).Type = ObjectTypeEnum.kHoleFeatureObject Then
		For Each itemrec In ObjCol1
			If itemrec.Type = ObjectTypeEnum.kRectangularPatternFeatureObject Or itemrec.Type = ObjectTypeEnum.kCircularPatternFeatureObject Then
				If ObjCol1.Item(i).Name = itemrec.ParentFeatures.Item(1).Name Then
					Call ObjCol1.Remove(i)
				End If
			End If
		Next
	End If
Next

CountHole = 0
For Each Item In ObjCol1
	If Item.Type = ObjectTypeEnum.kRectangularPatternFeatureObject Or Item.Type = ObjectTypeEnum.kCircularPatternFeatureObject Then
		CountHole = CountHole + Item.PatternElements.Count
		ElseIf Item.Type = ObjectTypeEnum.kHoleFeatureObject Then
		CountHole = CountHole + 1
	End If
Next
End Sub

 

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
Message 4 of 8

BrianEkins
Mentor
Mentor
There's another approach that doesn't depend on the feature information. Using features for threads has a few problems, many of which you've noted but there are others too. Take a look at this post for not info about the other solution.

https://ekinssolutions.com/getting-thread-information-in-inventor-and-apprentice
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 5 of 8

j.romo
Advocate
Advocate

Wow 

worked like a charm

I had other aprroach searching circular patterns also

but this weorks better

thanks a lot

0 Likes
Message 6 of 8

dgreatice
Collaborator
Collaborator

This Case are Close?

 

 

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 7 of 8

Anonymous
Not applicable

Hi dgreatice,

 

I have a question about this hole counting code. I cannot run it on this particular part, it returns 0 for some reason. (See screenshot below). However, do you think this code can accurately count the holes in a pattern that is made of two different holes?

 

 

The pattern below is made up of two different types of holes. One is .25in diameter and the other is .75in diameter. To create the pattern I selected Hole1 and Hole2 as the features to pattern. Then I patterned them 3 times. The number of elements in this pattern is 3, but the number of holes is 6. I am guessing that your code would output 3 holes?

Capture.PNG

 

 

0 Likes
Message 8 of 8

dgreatice
Collaborator
Collaborator

Hi,

 

because this topic about tapped holes, I just collect tapped holes only, so if you want get normal holes, and in 1 Feature pattern there are 2 parentFeature, you must iterate again, and add separate each type of holes.

 

example: This only have 1 parentFeature (Hole 1) and type hole are tapped.

 

For Each oRecPat In oFeats.RectangularPatternFeatures
	oParentFeat = oRecPat.ParentFeatures.Item(1)
	If oParentFeat.Type = ObjectTypeEnum.kHoleFeatureObject Then
		oHoleInPat = oParentFeat
		If oHoleInPat.Tapped = True Then
			Call ObjCol1.Add(oRecPat)
else
'more code for normal holes End If End If Next

 

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes