Hi,
Would something like this do?
Sub main()
Dim sFilePath As String = "C:\TEST\Test.ipt"
Dim oDoc As Document = ThisApplication.Documents.Open(sFilePath, True) 'False = open invisible, True = open visible. invisible is much faster.
Dim oFaceName As String = "Test"
Dim oSavePath As String = "C:\TEST\Test.dxf"
SaveFace(oDoc, oFaceName, oSavePath)
oDoc.Close
End Sub
Function SaveFace(oDoc As Document, FaceName As String, SavePath As String)
'finding entity called 'FaceName', providing error if can't find
Dim oNamedEntities = iLogicVb.Automation.GetNamedEntities(oDoc)
Try
oFace = oNamedEntities.FindEntity(FaceName)
Catch
MessageBox.Show("Cannot find face called '" & FaceName & "'! DXF not saved.", "Error saving file")
Exit Function
End Try
Dim oFolder As String = System.IO.Path.GetDirectoryName(SavePath)
'creating folder if not exist
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
'selecting entity called 'FaceName'
oDoc.SelectSet.Select(oFace)
'Export selected face to 'SavePath'
Dim oCmdMgr As CommandManager = ThisApplication.CommandManager
Dim oCtrlDef As ButtonDefinition = oCmdMgr.ControlDefinitions.Item("GeomToDXFCommand")
oCmdMgr.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, SavePath)
oCtrlDef.Execute
'deselecting entity called 'FaceName'
oDoc.SelectSet.Clear
End Function
Unfourtnately I think you'll need to open the files visibly to get the GeomToDXFCommand to work, which slows things down a little. I haven't tested this code much so you might need to add a few tweeks.