Hi @isocam. That is obviously not the whole code, because there is no code shown for where the 'oDoc' variable gets defines or a value set to it, and no code showing where the 'Dxffilename' variable is defined or value set to it. So, I am not sure if you want this to be a single routine, or a 2-part routine. I like to keep my export routines separate from the rest of my code, so I have a 2-part example below where the 'Main' section, where the face is obtained, and a file name is defined, is customized to your code above.
I usually use a different route for this type of thing though, to avoid having to use selection and executing a command. My process starts a Transaction, creates a new sketch on the face, where all face profiles are projected to the sketch plane, then turned to regular geometry (instead of construction), then export the sketch, similar to what Michael suggested, then abort the transaction to get rid of the sketch. This is likely what that command does behind the scenes anyways.
Sub Main
Dim oDoc As Inventor.Document = ThisApplication.ActiveDocument
If (Not TypeOf oDoc Is PartDocument) And (Not TypeOf oDoc Is AssemblyDocument) Then Return
Dim oExtFeats As ExtrudeFeatures = oDoc.ComponentDefinition.Features.ExtrudeFeatures
If oExtFeats.Count = 0 Then Return
Dim oExtrude As ExtrudeFeature = oExtFeats.Item(1)
Dim oBaseFace As Face = oExtrude.EndFaces.Item(1)
Dim sDXF_FullFileName As String = System.IO.Path.ChangeExtension(oDoc.FullFileName, ".dxf")
ExportFaceToDXF(oBaseFace, sDXF_FullFileName)
End Sub
Sub ExportFaceToDXF(oFace As Face, sDXF_FullFileName As String)
If oFace Is Nothing Or String.IsNullOrEmpty(sDXF_FullFileName) Then Return
Dim oDoc As Inventor.Document = oFace.Parent.ComponentDefinition.Document
oDoc.SelectSet.Clear
oDoc.SelectSet.Select(oFace)
Dim oCmdMgr As CommandManager = ThisApplication.CommandManager
oCmdMgr.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, sDXF_FullFileName)
oCmdMgr.ControlDefinitions.Item("GeomToDXFCommand").Execute
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)