Hi @iva.btblan .
I wasn't able to open your file to investigate your rule. If possible it is best to post the rule in the forum post this way you can get some immediate help outside of looking at the files themselves.
Here is one such approach to count holes. The API helps samples are good resources for this analysis work. This help page has lot of the information all ready laid out.
The rule works by identifying cylinder shaped faces which is a component of a hole. Then checking the radius of this face in order to identify the hole being counted. You can use a highlight set as a tool to identify objects so you know what objects you have found.
'Set the part document variables.
Dim PartDoc As PartDocument = ThisDoc.Document
Dim CompDef As PartComponentDefinition = PartDoc.ComponentDefinition
'Create a list for storing objects
Dim HoleFaces As New List(Of Face)
'Create a highlight Set.
Dim Set1 As HighlightSet = PartDoc.CreateHighlightSet
'Loop through all faces.
For Each PartFace As Face In CompDef.SurfaceBodies.Item(1).Faces
If PartFace.SurfaceType = SurfaceTypeEnum.kCylinderSurface Then
'Get the Cylinder mathematical Object.
Dim Cyl As Cylinder = PartFace.Geometry
'Get the Cylinder radius.
Dim CylRadius As Double = Cyl.Radius
'Logger.Info("CylRadius :" & CylRadius)
'Filter radius, measurements in system units cm.
If CylRadius = 0.5 Then
Set1.AddItem(PartFace)
HoleFaces.Add(PartFace)
End If
End If
Next
'Change the color of the highlight set to green.
Set1.Color = ThisApplication.TransientObjects.CreateColor(0, 255, 0)
MessageBox.Show(HoleFaces.Count, "Hole Count")
And another approach is to look into the hole patterns and identify the parameters used for hole qty. This approach is a little more difficult as you need to know how the part is constructed which can be time consuming.
'Set the part document variables
Dim PartDoc As PartDocument = ThisDoc.Document
Dim CompDef As PartComponentDefinition = PartDoc.ComponentDefinition
'Create a highlight Set.
Dim Set1 As HighlightSet = PartDoc.CreateHighlightSet
Dim RecPatCount As Integer
Dim RecPatSpacing As Double
Dim CircPatCount As Integer
Dim CircPatAngle As Double
For Each Feat As PartFeature In CompDef.Features
If Feat.Type = ObjectTypeEnum.kRectangularPatternFeatureObject Then
RecPatSpacing = Feat.Parameters.Item(1).Value
RecPatCount = Feat.Parameters.Item(2).Value
Logger.Info("RectangularPatternFeature-Spacing: " & RecPatSpacing)
Logger.Info("RectangularPatternFeature-RowCount: " & RecPatCount)
Set1.AddItem(Feat)
ElseIf Feat.Type = ObjectTypeEnum.kCircularPatternFeatureObject
CircPatAngle = Feat.Parameters.Item(1).Value
CircPatCount = Feat.Parameters.Item(2).Value
Logger.Info("CircularPatternFeature-AngularSpacing in Radians: " & CircPatAngle)
Logger.Info("CircularPatternFeature-RowCount: " & CircPatCount)
Set1.AddItem(Feat)
End If
Next
Dim HoleCount As Integer = RecPatCount * CircPatCount
'Change the color of the highlight set to green.
Set1.Color = ThisApplication.TransientObjects.CreateColor(0, 255, 0)
MessageBox.Show(HoleCount, "HoleCount")
If this solved a problem, please click (accept) as solution.
Or if this helped you, please, click (like)
Regards
Alan