@Andrii_Humeniuk
There's a incorrect "design" assumption in your code, which leads to incorrect results in certain cases: when three or more holes are partly overlapping.
- when 3 holes are overlapping and their resulting shape looks like a triangle made of circles, the code will count three cilindrical faces.
- when 3 holes are overlapping and the resulting shape looks like a line made of circles, the code will count four cilindrical faces, which is one more than there are actual holes.
I currently have no solution to this. It depends on @iva.btblan if this is an issue or not.
@iva.btblan
Please find below a different approach. It checks all the edges of a user selected face and checks if they are circular shaped (of any radius). It has the same flaw as I mentioned above to @Andrii_Humeniuk. Depending on your workflow, you can replace the user selection a face with a detection of the correct face.
VBA:
Public Sub CountHoles()
'Get face to count holes in
Dim oFace As Face
Set oFace = ThisApplication.CommandManager.Pick(kPartFacePlanarFilter, "Select perforated face (or press ESC to quit)")
'Check if user selected a face. If not, quit
If oFace Is Nothing Then Exit Sub
'Declarations
Dim oEdge As Edge
Dim oEdgeLoop As EdgeLoop
Dim dHoleCount As Double
'Iterate though each edge loop
For Each oEdgeLoop In oFace.EdgeLoops
'Iterate through each edge
For Each oEdge In oEdgeLoop.Edges
'Check if edge has circular shape
If oEdge.GeometryType = kCircleCurve Or oEdge.GeometryType = kCircularArcCurve Then
dHoleCount = dHoleCount + 1
End If
Next
Next
'Inform user
MsgBox "Ammount of holes: " & CStr(dHoleCount - 1), vbInformation + vbOKOnly, "Count holes"
End Sub
iLogic:
'Get face to count holes in
Dim oFace As Face = ThisApplication.CommandManager.Pick(kPartFacePlanarFilter, "Select perforated face (or press ESC to quit)")
'Check if user selected a face. If not, quit
If oFace Is Nothing Then Exit Sub
'Compensate for circular shaped outer contour
Dim dHoleCount As Double = - 1
'Iterate though each edge loop
For Each oEdgeLoop As EdgeLoop In oFace.EdgeLoops
'Iterate through each edge
For Each oEdge As Edge In oEdgeLoop.Edges
'Check if edge has circular shape
If oEdge.GeometryType = kCircleCurve Or oEdge.GeometryType = kCircularArcCurve Then
dHoleCount = dHoleCount + 1
End If
Next
Next
'Inform user
MsgBox ("Ammount of holes: " & CStr(dHoleCount), vbInformation + vbOKOnly, "Count holes")
[Edit 02-05-2024] Added iLogic example code and modified VBA example (added "- 1" in line 30).