Hi,
I'm trying to export a face from a solid using iLogic. I have made the face a named entity and have been trying to export the face using the GeomToDXFCommand API, but have had no luck in being able to pass the face to the API. I can't export the flat pattern as I only want the face in its folded form. Is there a way to get the functionality of 'Right Click' > 'Export Face As' using iLogic?
Thanks
Solved! Go to Solution.
Solved by mitchELAHB. Go to Solution.
Solved by gerrardhickson. Go to Solution.
Try this:
It requires you to have a face selected before running. You could select this face programmatically or manually.
Sub Main()
Dim oCtrlDef As ButtonDefinition
oCtrlDef = ThisApplication.CommandManager.ControlDefinitions.Item("GeomToDXFCommand")
Dim oDXFFullFileName As String
oDXFFullFileName = "C:\Temp\Face.dxf"
ThisApplication.CommandManager.PostPrivateEvent( PrivateEventTypeEnum.kFileNameEvent, oDXFFullFileName)
oCtrlDef.Execute
End Sub
Borrowed from here:
Thanks, I've implemented something similar with a try/catch statement when setting the face name.
Function SaveFace(FaceName As String, SavePath As String)
'finding entity called 'FaceName', providing error if can't find
Dim oNamedEntities = iLogicVb.Automation.GetNamedEntities(ThisDoc.Document)
Try
oFace = oNamedEntities.FindEntity(FaceName)
Catch
MessageBox.Show("Cannot find face called '" & FaceName & "'! DXF not saved.", "Error saving file")
Exit Function
End Try
'selecting entity called 'FaceName'
ThisDoc.Document.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
End Function
This works well for my needs, but I did wonder if there was a more elegant solution than selecting the face programmatically.
Cheers
Do you mean you would like to export the face directly? E.g. oFace.exporttodxf?
If that's what you were hoping for, then it seems that you're out of luck. I think the exit face as DXF was introduced to inventor relatively recently, so it hasn't been included in the API yet.
Thanks for that. Yeah, I was hoping to be able to do some a bit more eloquently, but what I have works.
Cheers
@mitchELAHB , it works great.
Instead of exporting a face from "ThisDoc", I would like to export a face from a known file, because I want to run this rule in a DWG file to export faces from multiple .ipt files that are there.
Eg.
'selecting entity called 'FaceName' ThisDoc.Document.SelectSet.Select(oFace)
How can I change this line to select oFace from a specific known file?
Thank you.
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.
Hi,
Thank you for the code. Yes it works !
The only issue is here:
Dim oDoc As Document = ThisApplication.Documents.Open(sFilePath, True) 'False = open invisible, True = open visible. invisible is much faster.
If I set the boolean to False (wich I think is a good idea to open invisible), the export does not take place. But I think you already knew this.
If I have no choice, I'll add oDoc.Close at the end of your code.
Yes, as far as I know the document will need to be opened. Good point on closing the file, that slipped my mind, I'll update my code for any future searches that find this topic.