Use XDirectionMidPlanePattern and YDirectionMidPlanePattern for symmetrical Rectangular pattern

By Wayne Brill

Issue

I am trying to use the API to create a Rectangular Pattern that is symmetrical around the feature being used for the pattern. I am not finding a way to use the parameters of the RectangularPatternFeatures.Add method to achieve the same results that I get using the MidPlane option in the UI. Is there a way to achieve this using the API?

Solution

The API does not provide the MidPlane option on forward create. But you can edit the feature to get the desired result. Here are a VBA and VB.NET examples that shows how this can be done. Before running have an extrusion with a hole that can be used for the pattern. (have the hole near the middle of the face)

VBA

Sub PatternRectTest()
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oCompDef As PartComponentDefinition
    Set oCompDef = oDoc.ComponentDefinition
    
    Dim objColFeatures As ObjectCollection
    Set objColFeatures = ThisApplication. _
        TransientObjects.CreateObjectCollection
    
    Call objColFeatures.Add _
        (oCompDef.Features.HoleFeatures.Item(1))
    
    Dim oRectFeature As RectangularPatternFeature
    Set oRectFeature = oCompDef.Features. _
        RectangularPatternFeatures.Add(objColFeatures, _
        oCompDef.WorkAxes.Item _
        ("X Axis"), False, 3, "1 in", , , _
        oCompDef.WorkAxes.Item _
        ("Y Axis"), True, 3, "1 in", , , kOptimizedCompute)
    
    oRectFeature.XDirectionMidPlanePattern = True
    oRectFeature.YDirectionMidPlanePattern = True
    
End Sub

VB.NET

Public Class Form1
    Dim m_inventorApp As Inventor.Application = Nothing
    
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' Get an active instance of Inventor
        Try
            m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
        Catch 'Inventor not started
            System.Windows.Forms.MessageBox.Show("Start an Inventor session")
            Exit Sub
        End Try
        
        'Call the Sub
        test()
    End Sub
    
    Sub test()
        Dim oDoc As PartDocument = m_inventorApp.ActiveDocument
        
        Dim oCompDef As PartComponentDefinition = oDoc.ComponentDefinition
        
        Dim objColFeatures As ObjectCollection = m_inventorApp.TransientObjects.CreateObjectCollection
        
        Call objColFeatures.Add(oCompDef.Features.HoleFeatures.Item(1))
        
        Dim oRectFeature As RectangularPatternFeature
        oRectFeature = oCompDef.Features. _
            RectangularPatternFeatures.Add(objColFeatures, _
            oCompDef.WorkAxes.Item("X Axis"), False, 3, "1 in", , , _
            oCompDef.WorkAxes.Item("Y Axis"), _
            True, 3, "1 in", , , _
            PatternComputeTypeEnum.kOptimizedCompute)
        
        oRectFeature.XDirectionMidPlanePattern = True
        oRectFeature.YDirectionMidPlanePattern = True
    End Sub
End Class

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading