get number of holes(without hole feature)

get number of holes(without hole feature)

Naoufel_EMW
Participant Participant
589 Views
6 Replies
Message 1 of 7

get number of holes(without hole feature)

Naoufel_EMW
Participant
Participant

Is there any way to get the number of holes on a part without using the hole feature api 

Naoufel_EMW_0-1648563210803.png

 

thanks 

0 Likes
590 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor

Hi @Naoufel_EMW.  Your image is showing an assembly document currently open.  Are all the holes you are trying to find perfectly round?  Were these holes created within the assembly, or were they created within the part (while the part document was active)?  Were these holes created using Extrude cut features?  Are you only looking for holes that were created within the main assembly, or do you also want to count any holes that may have been created within the parts, prior to the parts being in the assembly?  Do you just want to see the resulting hole count in a pop-up message, or do you want this number to be recorded somewhere?  This sounds like it could be a challenging task to do entirely by code.  Why do you need to know the number of holes?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 7

WCrihfield
Mentor
Mentor

Hi @Naoufel_EMW.  Here is an iLogic rule you can try out that will attempt to count the number of extruded circles that are set to cut, within the document you run the rule on.  It does not attempt to count any holes that are created using the a HoleFeature.  This can be ran from an assembly, or a part.  If ran from an assembly, it will only find ones that were created within the context of the assembly itself, not ones that were created within the context of any components.

Dim oDoc As Document = ThisDoc.Document
Dim oExtrudeFeats As ExtrudeFeatures
If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Or _
	oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
	oExtrudeFeats = oDoc.ComponentDefinition.Features.ExtrudeFeatures
Else
	MsgBox("This rule only works on Parts or Assemblys. Exiting.", vbCritical, "")
	Exit Sub
End If
If IsNothing(oExtrudeFeats) OrElse oExtrudeFeats.Count = 0 Then Exit Sub
Dim oHoleCount As Integer = 0
For Each oEFeat As ExtrudeFeature In oExtrudeFeats
	If oEFeat.Suppressed OrElse _
		oEFeat.Definition.Operation <> PartFeatureOperationEnum.kCutOperation Then
		Continue For
	End If
	oProfile = oEFeat.Definition.Profile
	For Each oPath As ProfilePath In oProfile
		If oPath.Closed = False Then Continue For
		If oPath.Item(1).CurveType = Curve2dTypeEnum.kCircleCurve2d Then
			oHoleCount = oHoleCount + 1
		End If
	Next
Next
MsgBox("oHoleCount = " & oHoleCount,,"")

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 :bulb: or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 7

Naoufel_EMW
Participant
Participant

Thank you very much for the detailed response. It worked as expected, just disabled the part below.

OrElse _
		oEFeat.Definition.Operation <> PartFeatureOperationEnum.kCutOperation

 

I appreciate your help.

0 Likes
Message 5 of 7

Naoufel_EMW
Participant
Participant

Hi 

I want to thank you again for your respond and your support.

I faced an other case where the hole is under component under an assembly which is not solved by the previous algorithm you sent.

 

Naoufel_EMW_0-1649666200546.png

 

I will be grateful if you can give me help.

thank you  

 

0 Likes
Message 6 of 7

WCrihfield
Mentor
Mentor

Hi @Naoufel_EMW.  I'm not sure what you want/need in your last post.  And I am not sure what I am seeing within the red rectangle on the model screen part of the image you posted there.  I am guessing that it is an extruded rectangular cutout, but it could also just be a rectangular part, or a small WorkPlane.  I am also guessing that you want to access the part that you have the red box around in the model browser, that is within a sub assembly that you also have a red box around, but I am not sure about what you want after that.  If the model space image is an extruded rectangular cutout area in the part, and that is what you are trying to access, than what do you want to happen once it is reached?  Do you need to confirm that it is a rectangle, or if it is square?  Do you need to check its size?  Attempting to check if that feature represents a rectangle, or square would require a lot more code and complication.  Please explain in more detail what you want.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 7

Naoufel_EMW
Participant
Participant

Hi,

Thanks for your answer first.

For my case I need just to get the number of holes/cavities (in red rectangle on the model screen) and note that the shape of holes are random (square, rectangle, circle...) and is within a sub-assembly (which is not the case in the above algorithm), I need just to get the number of holes (neither the shape nor the size), known that the comparison on the cut type, that you mentioned at the end of the above algorithm, didn't help.
I really appreciate your help

0 Likes