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