iLogic - Determine hole pattern element's hole feature

iLogic - Determine hole pattern element's hole feature

Anonymous
Not applicable
1,282 Views
3 Replies
Message 1 of 4

iLogic - Determine hole pattern element's hole feature

Anonymous
Not applicable

Problem: Given a hole pattern (rectangular, circular, or mirror) containing different sizes of holes, determine the corresponding hole feature for every element in the pattern.

 

Background:

I am trying to catalog all of the holes in a part by their size and center point coordinates, and of course I have to handle patterns. There is already a solution to count holes in patterns and determining the size of holes in a homogeneous pattern (only one hole feature in the pattern) is trivial. However, I cannot figure out how to determine the size of a hole in a pattern when it is made up of multiple different hole features (non-homogeneous).

 

Discussion:

The problem with the sample code below for non-homogeneous patterns is in the following snippet:

 

Dim hole as HoleFeature = mirror.ParentFeatures.Item(1)

The index on the Item method (1 in this case) is what selects the hole feature that was patterned. For a hole pattern with two different hole features this index can be 1 or 2.  The sample code below works fine for a homogeneous pattern because the hole variable is always the same. However, for a non-homogeneous pattern, that variable must change or else the code thinks the pattern is homogeneous. What is the relationship between the Item method's index value and the current element? From the API there doesn't appear to be any code that relates the two.

 

 

Sample Code for Homogeneous Pattern:

 

For Each mirror As MirrorFeature In part.Definition.Features.MirrorFeatures
	If Not mirror.Suppressed Then
		If (TypeOf mirror.ParentFeatures.Item(1) Is HoleFeature) Then
Dim hole as HoleFeature = mirror.ParentFeatures.Item(1) For j = 1 to mirror.PatternElements.count dim element as FeaturePatternElement element = mirror.PatternElements.item(j) If Not element.Suppressed Then ' Get hole position
' Get hole size End If next j End If End If Next mirror

 

 

 

0 Likes
1,283 Views
3 Replies
Replies (3)
Message 2 of 4

Tom_Sturtevant
Alumni
Alumni

Hi aneely_,

 

You will need to iterate through each patterned feature.  I have not tested this code but see if it gets you what you need.  Note that it now references mirror.ParentFeatures.Item(i).

 

For Each mirror As MirrorFeature In part.Definition.Features.MirrorFeatures

                If Not mirror.Suppressed Then

                                For i = 1 to mirror.ParentFeatures.count

                                                If (TypeOf mirror.ParentFeatures.Item(i) Is HoleFeature) Then

                                                                Dim hole as HoleFeature = mirror.ParentFeatures.Item(i)

                                                                For j = 1 to mirror.PatternElements.count

                                                                                dim element as FeaturePatternElement

                                                                                element = mirror.PatternElements.item(j)

                                                                                If Not element.Suppressed Then

                                                                                                ' Get hole position

                                                                                                ' Get hole size

                                                                                End If

                                                                next j

                                                next i

                                End If

                End If

Next mirror

 

Hope that helps!

T.0.M.



Tom Sturtevant
Inventor Part Modeling Developer
Autodesk, Inc.

0 Likes
Message 3 of 4

Anonymous
Not applicable

Hi Tom, thanks for your input! I made a quick script that runs the algorithm with your modifications as well as a screenshot of the output (See below). I believe it has the same issue as the one I described in my post. Once you get to the inner loop (j loop), in the code below, the PatternElement object has no information about the holes. Sure the outer loop (i loop) has the hole variable, but it isn't specific to the jth PatternElement. That is why it outputs all of the PatternElements twice, because there are two ParentFeatures. And I realized while making this script that the PatternElement object doesn't seem to know that there are two holes in each element. Which is why the PatternElement count is three and not six.

 

In the end I need the following information: There are 6 hole features in this pattern. Three of them are .25 in. diameter and their center points are x,y,z.... The other three are .75 in. diameter and their center points are x,y,z....

 

Sorry if this doesn't make sense. It is hard to explain.

 

  

Sample Code:

Sub Main()
	Dim part As Inventor.PartDocument = ThisDoc.Document
	Dim output As String = ""
	
	For Each pattern As RectangularPatternFeature In part.ComponentDefinition.Features.RectangularPatternFeatures
	    If Not pattern.Suppressed Then
	        output += "Found Pattern: " & pattern.Name & vbNewLine
			For i = 1 To pattern.ParentFeatures.Count
				output += "Parent Feature " & i & " of " & pattern.ParentFeatures.Count & ": " & pattern.ParentFeatures.Item(i).Name & vbNewLine
				If TypeOf pattern.ParentFeatures.Item(i) Is HoleFeature Then
					Dim hole As HoleFeature = pattern.ParentFeatures.Item(i)
					For j = 1 To pattern.PatternElements.Count
						If Not pattern.PatternElements.Item(j).Suppressed Then
							output += "Pattern Element " & j & " of " & pattern.PatternElements.Count & vbnewline
						End If
					Next j
				End If
			Next i
	    End If
	Next pattern
	
	MessageBox.Show(output)
End Sub

 

Output from sample code above:

Capture.PNG

0 Likes
Message 4 of 4

Tom_Sturtevant
Alumni
Alumni

Hi aneely_,

 

It seems like you are pretty close...  In your inner loop (j loop) I think you want to capture:

* the diameter of pattern.ParentFeatures.Item(i)

* the center point of pattern.ParentFeatures.Item(i) transformed by  pattern.PatternElements.Item(j).Transform

 

You may get better help with this in the Inventor Customization forum https://forums.autodesk.com/t5/inventor-customization/bd-p/120

 

Regards,

T.0.M.

 



Tom Sturtevant
Inventor Part Modeling Developer
Autodesk, Inc.

0 Likes