Circular holes - Tubes

Circular holes - Tubes

iva.btblan
Advocate Advocate
803 Views
10 Replies
Message 1 of 11

Circular holes - Tubes

iva.btblan
Advocate
Advocate

I always have to keep counting holes.
Several studies are conducted until you reach the final result.
The holes vary according to the studies.
I have to keep counting holes over and over again.
Is it possible to create a rule to count these holes?

Has a rule in the file.

Thank you!06.05.0011.png

0 Likes
Accepted solutions (1)
804 Views
10 Replies
Replies (10)
Message 2 of 11

A.Acheson
Mentor
Mentor

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
0 Likes
Message 3 of 11

iva.btblan
Advocate
Advocate

Thank you for your attention.

Is it possible to include the holes below?

03.05.0002.pngBottom holes of 12 holes. Total holes 66.

0 Likes
Message 4 of 11

A.Acheson
Mentor
Mentor

It looks like you use the pattern detection code. If this has failed you have it modeled different than I have. It would be better to use the faces count code and set up your radius filter to be between a normal range of holes you expect. All you want to do is filter out the tube itself as being a hole as it is still a cylinder. 

 

If CylRadius > 0.1 And CylRadius < 1 Then

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 11

iva.btblan
Advocate
Advocate

Thank you for your attention.

I couldn't understand where I should put this line below.

Can you help by explaining where should I put this sentence to work the rule?

 

If CylRadius > 0.1 And CylRadius < 1 Then

 

Iva

0 Likes
Message 6 of 11

A.Acheson
Mentor
Mentor

That line will simply be the criteria for selecting the correct cylinder shape. 

Here is the update code with criteria changed. You will need to change the criteria (hole radius) to what works in your case. 

'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.1 And CylRadius < 1 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")

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 7 of 11

_dscholtes_
Advocate
Advocate

@A.Acheson wrote:

 All you want to do is filter out the tube itself as being a hole as it is still a cylinder. 

The cylindrical face of the unperforated tube is bounded by two edgeloops (top and bottom). The same goes for every cylindrical hole made in the tube (edge on inside and outside of tube). So the perforated tube can easily be found, because it is the only cylindrical face with more than two edgeloops. So by getting the edgeloops count and substracting two from this amount, you have the total amount of holes in the tube. No matter how the perforated tube was made.

0 Likes
Message 8 of 11

A.Acheson
Mentor
Mentor

As kindly recommended by @_dscholtes_   Edge loops can be used. So this will look at the faces of the part and count the top of the hole and the tube cylinder ends. The untested code below will find both the inner and outer tube faces but as they will have the same count number either or is acceptable. 

 

'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

   'Change the color of the highlight set to green.
	 Set1.Color = ThisApplication.TransientObjects.CreateColor(0, 255, 0)
	
	'Loop through all faces.
	For Each PartFace As Face In CompDef.SurfaceBodies.Item(1).Faces
		
		If PartFace.SurfaceType = SurfaceTypeEnum.kCylinderSurface Then
          If PartFace.EdgeLoops.Count>2 Then
            Dim Count as Integer = PartFace.EdgeLoops.Count -2
            Set1.AddItem(PartFace)
	     End If	
		End If
	Next
	
	 MessageBox.Show(Count, "Hole Count")

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 9 of 11

iva.btblan
Advocate
Advocate

Thanks for the answer.
I understand perfectly. It will be necessary to add a cap to this tube.
The lid will have several holes.
Can I send you? Or do I have to create another topic?06.01.00021.20.png

0 Likes
Message 10 of 11

A.Acheson
Mentor
Mentor

I think the added end cap would be best counted using the faces and filtering the cylinder radius.  This avoids the need to calculate the edge loops. Can you share the attempted code? I think there is enough methods mentioned to attempt your additional features hole count.  

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 11 of 11

A.Acheson
Mentor
Mentor
Accepted solution

The easiest I have found is still the check faces and check for cylinder shape of known radius. 

AAcheson_0-1677209171301.png

 

	'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("oCylinderRadius :"& CylRadius)
			
			'Filter radius, measurements in system units cm.
			If CylRadius > 0.01 AndAlso CylRadius < 2 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")

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes