I wrote some iLogic code which allows a user to automatically export any face in an Inventor Part or Assembly file to DXF. The code allows the user to predefine a file name and path. The animated GIF below shows how the code works.
There is one “glitch”, this code will export out flat and curved (projected) faces too.
For the geeks out there, here is a bit more info on how it all works.
I have been interested in the idea of using tool-tips with iLogic for a while now, my previous iLogic blog post looked at displaying iProperties of parts inside of an Assembly file.
I wanted to create a useful tool that exports a selected face to DXF. Currently a user can right-click on any face (while in a .ipt), and then export it to DXF via the user interface (see my blog post here).
Initially I was unable to find a reference to the DXF export in the Inventor API, but after a quick internet search, my suspicion was confirmed, the workaround is to use the “Command Manager”, which is essentially the same as clicking a button in the interface. For more on the “Command Manager”, have a look at this Autodesk blog post.
The code I have shared below, uses the same “Mouse Input” code that I used in the iProperties post, with the DXF export via the “Command Manager”, courtesy of the forum post shared in the code.
SetTheFilePathHere = "C:\Temp" SetTheFilenameHere = ThisDoc.FileName(False)
Here is the code:
'CREDITS: 'Code By @ClintBrown3D 'Originally posted at https://clintbrown.co.uk/dxf-export 'Mouse input code based on this forum post: https://forums.autodesk.com/t5/inventor-customization/ilogic-to-handle-mouse-event-for-part-selection/td-p/3902918 'Additonal DXF info via 'https://forums.autodesk.com/t5/inventor-customization/export-face-as-dxf-from-api/td-p/1965512 SetTheFilePathHere = "C:\Temp" SetTheFilenameHere = ThisDoc.FileName(False) 'without extension Error0 = 1 On Error GoTo error1 ThisApplication.StatusBarText = "Select a Face to Export as DXF : @ClintBrown3D" Dim doc = ThisApplication.ActiveDocument Dim entity = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a Face to Export as DXF : @ClintBrown3D") doc.SelectSet.Select(entity) ThisApplication.CommandManager.PostPrivateEvent(kFileNameEvent, SetTheFilePathHere &"\" & SetTheFilenameHere & ".dxf") ThisApplication.StatusBarText = "Exporting your DXF, please hold : @ClintBrown3D" Dim oCtrlDef As ButtonDefinition oCtrlDef = ThisApplication.CommandManager.ControlDefinitions.Item("GeomToDXFCommand") oCtrlDef.Execute Error0 = 0 MessageBox.Show("Success! - DXF exported", "@ClintBrown3D - DXF Export") ThisApplication.StatusBarText = "Success! - DXF exported : @ClintBrown3D" InventorVb.DocumentUpdate(False) error1 : If Error0 = 1 Then MessageBox.Show("iLogic Rule Cancelled", "@ClintBrown3D - DXF Export") End If