To perform the same thing programmatically, there is no direct equivalent in the API currently, however there is a workaround: this is a mix of API calls & user commands called programmatically which is following the workflow described above.
To test it, open an assembly file, select or create a workplane that intersect with the assembly and run the following sample TestProjectCutEdges method, replacing "PartTestProjection:1" by the name of the occurrence you want to project as it appears in the browser pane.
Public Sub TestProjectCutEdges()
' access the active document as
' Assembly Document
If (m_inventorApplication.ActiveDocumentType <> _
DocumentTypeEnum.kAssemblyDocumentObject) Then Return
Dim oAsmDoc As AssemblyDocument
oAsmDoc = m_inventorApplication. _
ActiveDocument
' get the workplane
Dim oWorkPlane As WorkPlane = TryCast(
m_inventorApplication. _
ActiveDocument.SelectSet.Item(1), _
WorkPlane)
If (oWorkPlane Is Nothing) Then Return
' start the method
MethodProjectCutEdges(oAsmDoc, _
oWorkPlane, _
"PartTestProjection:1")
End Sub
Public Sub MethodProjectCutEdges( _
ByVal oAsmDoc As AssemblyDocument, _
ByVal oWorkPlane As WorkPlane, _
ByVal OccurenceName As String)
Dim xVector As Vector = Nothing
Dim yVector As Vector = Nothing
Dim zVector As Vector = oWorkPlane.Plane.Normal.AsVector
'Create a coordinate system based on the workplane's normal vector
CreateCoordSystem(xVector, yVector, zVector)
' create a transformation matrix
Dim oMatrix As Matrix = m_inventorApplication. _
TransientGeometry.CreateMatrix
' and set the coordinate system
oMatrix.SetCoordinateSystem( _
oWorkPlane.Plane.RootPoint, _
xVector, yVector, zVector)
' create a new part document
Dim oPartDoc As PartDocument = m_inventorApplication. _
Documents.Add(DocumentTypeEnum.kPartDocumentObject, _
m_inventorApplication.FileManager. _
GetTemplateFile( _
DocumentTypeEnum.kPartDocumentObject), _
False)
' and add as an occurrence to the active assembly document
Dim oCompOcc As ComponentOccurrence = oAsmDoc. _
ComponentDefinition.Occurrences.AddByComponentDefinition( _
oPartDoc.ComponentDefinition, oMatrix)
' and start edit mode
oCompOcc.Edit()
' access the part document component definition
Dim oPartCompDef As PartComponentDefinition = _
oCompOcc.Definition
' and create a new sketch
Dim oSketch As Sketch
oSketch = oPartCompDef.Sketches.Add( _
oPartCompDef.WorkPlanes.Item("XY Plane"))
oSketch.Edit()
' make the part occurrence as the selection
Dim oSelectedOcc As Object
oSelectedOcc = oAsmDoc.ComponentDefinition. _
Occurrences.ItemByName(OccurenceName)
oAsmDoc.SelectSet.Clear()
oAsmDoc.SelectSet.Select(oSelectedOcc)
' and execute the built-in command
m_inventorApplication.CommandManager. _
ControlDefinitions. _
Item("SketchProjectCutEdgesCmd").Execute()
End Sub
Public Sub CreateCoordSystem(ByRef xVector As Vector, _
ByRef yVector As Vector, _
ByRef zVector As Vector)
' get the transient geometry object
Dim tg As TransientGeometry = m_inventorApplication. _
TransientGeometry
Dim Tolerance As Double = 0.000000000001
'Set a tolerance treshold for the normal vector
If Math.Abs(zVector.X) < Tolerance Then
zVector.X = 0.0#
ElseIf Math.Abs(zVector.Y) < Tolerance Then
zVector.Y = 0.0#
ElseIf Math.Abs(zVector.Z) < Tolerance Then
zVector.Z = 0.0#
End If
If zVector.X <> 0 Then
xVector = tg.CreateVector(-zVector.Y / zVector.X, 1, 0)
yVector = zVector.CrossProduct(xVector)
ElseIf zVector.Y <> 0 Then
xVector = tg.CreateVector(0, -zVector.Z / zVector.Y, 1)
yVector = zVector.CrossProduct(xVector)
ElseIf zVector.Z <> 0 Then
xVector = tg.CreateVector(1, 0, 0)
yVector = zVector.CrossProduct(xVector)
End If
End Sub