Get first element of pattern

Get first element of pattern

GeorgK
Advisor Advisor
535 Views
4 Replies
Message 1 of 5

Get first element of pattern

GeorgK
Advisor
Advisor

Hello together,

 

I would like to select a hole and get the first element from an RectangularPattern or CircularPattern feature in part environment. How could I achieve this?

 

 

 Dim m_inventorApp As Inventor.Application = Nothing

        m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")

        ' Get the selected face.
        On Error Resume Next
        Dim oFace As Face
        oFace = m_inventorApp.ActiveDocument.SelectSet.Item(1)


        ' Check to see if this face was created by an extrude,
        ' revolve, or hole feature.
        Dim oCreatedByFeature As PartFeature
        oCreatedByFeature = oFace.CreatedByFeature

        ' Get the associated sketch.
        Dim oSketch As PlanarSketch

        If TypeOf oCreatedByFeature Is HoleFeature Then
            Dim oHole As HoleFeature
            oHole = oCreatedByFeature

            MsgBox(oHole.Name)

        ElseIf TypeOf oCreatedByFeature Is RectangularPatternFeature Or TypeOf oCreatedByFeature Is CircularPatternFeature Then
            Dim oHole As HoleFeature

            On Error Resume Next
            oHole = oCreatedByFeature.ParentFeatures.Item(1)
            MsgBox(oHole.Name & " Circular or Rectangular Pattern")
            
        End If

 

Thank you

 

Georg

 

 

0 Likes
Accepted solutions (1)
536 Views
4 Replies
Replies (4)
Message 2 of 5

HermJan.Otterman
Advisor
Advisor

Hello Georg,

 

try this:

 

 

 

Dim oPartDoc As Inventor.PartDocument = m_inventorApplication.ActiveDocument

Dim selectedFace As Face = oPartDoc.SelectSet(1)

Dim InternalName As String = selectedFace.InternalName

Dim oFeatures As Inventor.PartFeatures = oPartDoc.ComponentDefinition.Features

Dim elementFound As Boolean = False

If oFeatures.RectangularPatternFeatures.Count > 0 Then

For Each oRectPat As RectangularPatternFeature In oFeatures.RectangularPatternFeatures

For Each oElement As FeaturePatternElement In oRectPat.PatternElements

For Each oFace As Face In oElement.Faces

If oFace.InternalName = InternalName Then

oPartDoc.SelectSet.Clear()

oPartDoc.SelectSet.Select(oRectPat.PatternElements(1))

elementFound = True

Exit For

End If

Next

If elementFound = True Then Exit For

Next

If elementFound = True Then Exit For

Next

End If

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 3 of 5

GeorgK
Advisor
Advisor

Hello Herm Jan,

 

thanks for the code. How could I change the hole diameter?

 

Georg

0 Likes
Message 4 of 5

HermJan.Otterman
Advisor
Advisor
Accepted solution

how do you make the part?

 

if you create a sketch of the hole, or make a hole feature, you get a parameter for the diameter.

give it a name and you can find it again.!?

 

ok, changed the code a bit:

 

Dim oPartDoc As Inventor.PartDocument = _inventorApplication.ActiveDocument

Dim selectedFace As Face = oPartDoc.SelectSet(1)

Dim InternalName As String = selectedFace.InternalName

Dim oFeatures As Inventor.PartFeatures = oPartDoc.ComponentDefinition.Features

Dim elementFound As Boolean = False

' change:

Dim oRectPat As RectangularPatternFeature = Nothing

If oFeatures.RectangularPatternFeatures.Count > 0 Then

' change:

For Each oRectPat In oFeatures.RectangularPatternFeatures

For Each oElement As FeaturePatternElement In oRectPat.PatternElements

For Each oFace As Face In oElement.Faces

If oFace.InternalName = InternalName Then

oPartDoc.SelectSet.Clear()

oPartDoc.SelectSet.Select(oRectPat.PatternElements(1))

elementFound = True

Exit For

End If

Next

If elementFound = True Then Exit For

Next

If elementFound = True Then Exit For

Next

 

'Add: if hole created with one extrude feature:

Dim oParentFeature As Object = oRectPat.ParentFeatures(1)

For Each oParam As Inventor.Parameter In oParentFeature.Parameters

MsgBox(oParam.Name)

MsgBox(oParam.Value)

Next

' you still have to know the name of the parameter..!!??

End If

 

 

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 5 of 5

GeorgK
Advisor
Advisor

Hello Herm Jan,

 

thanks for the code. I could solve it now.

 

Georg

0 Likes