Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
karthur1
4135 Views, 17 Replies

Save ALL associated files to DXF

I use a macro that will open each idw that is associated with an assembly and then save them to PDF.  I would like to modify this macro to save as DXF rather than PDF. Seems pretty simple and I found lots of examples where other have done something similar. I tried several things, but fialed in getting this to work.

 

The closest I got was by taking the code attached here and doing a find/replace and replacing PDF with DXF.  The new code runs and creates a DXF, but when I open the DXF it does not contain the drawing.  I tried to make it work, but I'm terrible at coding.

 

This original code was written by @Curtis_Waguespack and posted at this thread.

 

Any help would be appreciated.

 

Kirk

 

 

Owner2229
in reply to: karthur1

Hi, try changing these lines:

'- - - - - - - - - - - - -dxf setup - - - - - - - - - - - -
oPath = ThisDoc.Path
DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
'DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")

 

To:

'- - - - - - - - - - - - -dxf setup - - - - - - - - - - - -
oPath = ThisDoc.Path
'DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")

 

And let me know if it worked. I'll look at it a bit deeper if it won't work.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
karthur1
in reply to: Owner2229

Mike,

When I run the macro like I posted above, the macro runs... but I looked at the generated file using a text editor and it is creating dWf files rather than dXf files.

 

When I run the macro with the change like you recommend, I get this error "The parameter is incorrect".

 

Kirk

 

2016-02-26_1109.png

 

 

Hi karthur1,

 

I'm short on time so did not test very much, but I think this will work for you. See the attached *.txt file if this code gives you Copy-Paste errors from this forum.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)

'check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
Exit Sub
End If

'get user input
RUsure = MessageBox.Show ( _
"This will create a DXF file for all of the asembly components that have drawings files." _
& vbLf & "This rule expects that the drawing file shares the same name and location as the component." _
& vbLf & " " _
& vbLf & "Are you sure you want to create DXF Drawings for all of the assembly components?" _
& vbLf & "This could take a while.", "iLogic  - Batch Output DXFs ",MessageBoxButtons.YesNo)

If RUsure = vbNo Then
Return
Else
End If

oPath = ThisDoc.Path

'get DXF target folder path
oFolder = oPath & "\" & oAsmName & " DXF Files"

'Check for the DXF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If



'[ DXF setup

' Get the DXF translator Add-In.
Dim DXFAddIn As TranslatorAddIn
DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
'Set a reference to the active document (the document to be published).
Dim oDocument As Document
oDocument = ThisApplication.ActiveEditDocument
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
' Create a NameValueMap object
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
' Create a DataMedium object
Dim oDataMedium As DataMedium
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

' Check whether the translator has 'SaveCopyAs' options
If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
	Dim strIniFile As String
	strIniFile = "C:\temp\dxfout.ini"
	' Create the name-value that specifies the ini file to use.
	oOptions.Value("Export_Acad_IniFile") = strIniFile
End If

'] end of DXF setup


'[ ComponentDrawings 
	'look at the files referenced by the assembly
	Dim oRefDocs As DocumentsEnumerator
	oRefDocs = oAsmDoc.AllReferencedDocuments
	Dim oRefDoc As Document
	
	'work the the drawing files for the referenced models
	'this expects that the model has a drawing of the same path and name 
For Each oRefDoc In oRefDocs
	idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "idw"
	
	'check to see that the model has a drawing of the same path and name 
	If(System.IO.File.Exists(idwPathName)) Then
			Dim oDrawDoc As DrawingDocument
		oDrawDoc = ThisApplication.Documents.Open(idwPathName, True)
		oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) -3)
	
		On Error Resume Next ' if DXF exists and is open or read only, resume next
		'Set the DXF target file name
		oDataMedium.FileName = oFolder & "\" & oFileName & "DXF"
		'Write out the DXF
		'Set the destination file name
		oDataMedium.FileName = oFolder & "\" & oFileName & "dxf"
		'Publish document.
		Call DXFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
		'close the file
		oDrawDoc.Close
	Else
	'If the model has no drawing of the same path and name - do nothing
	End If
Next
'] End of ComponentDrawings 



'[ Top Level Drawing 
	oAsmDrawing = ThisDoc.ChangeExtension(".idw")
	oAsmDrawingDoc = ThisApplication.Documents.Open(oAsmDrawing, True)
	oAsmDrawingName = Left(oAsmDrawingDoc.DisplayName, Len(oAsmDrawingDoc.DisplayName) -3)
	'write out the DXF for the Top Level Assembly Drawing file
	On Error Resume Next ' if DXF exists and is open or read only, resume next
	'Set the DXF target file name
	oDataMedium.FileName = oFolder & "\" & oAsmDrawingName & "dxf"
	'Write out the DXF
	Call DXFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMedium)
	'Close the top level drawing
	oAsmDrawingDoc.Close
'] Top Level Drawing 

MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
'open the folder where the new ffiles are saved
Shell("explorer.exe " & oFolder,vbNormalFocus)

 

Works great!!

 

Thanks Curtis.

Anonymous
in reply to: Curtis_Waguespack

Thanks for these useful codes.
What if I need to separate dxf files by thickness and materials?

philip.G
in reply to: Anonymous

Aren't Material and Thickness Ilogic- Parameters?

adriaanslabbert
in reply to: karthur1

Hi,

 

I ran the rule using the code but it doesn't generate the dxf files.

I am using 2018 inventor if that helps

Please HELP!

karthur1
in reply to: adriaanslabbert

Did you get an error message?

If I remember correctly,you have to have the file extenstions turned on (from windows explorer) before you run this.

adriaanslabbert
in reply to: karthur1

No it doesnt give an error msg

File extensions is turned on

 

karthur1
in reply to: adriaanslabbert

One other thing is that you must have a .ini file for the export to work.  Place the attached DXFOUT.ini file into your C:\Temp directory and try again.  

 

When it works correctly, it will open the directory where the files are written.

 

 

adriaanslabbert
in reply to: karthur1

nope, still not working

when I run the rule, it opens and closes all the .idw's and then opens the location where the dxf's are saved but the file is empty

It's working!

 

Thanks!

karthur1
in reply to: adriaanslabbert

When the rule is running and converting the file to DXF, you will see at the bottom of the window a message like ..."Executing Data Export" in the bottom right of the inventor window.  Do you see that?

 

I recorded a Screencast video below or you can click this link to watch.

 

If the file extensions are not shown in windows explorer, it will cause the issue.

 

adriaanslabbert
in reply to: karthur1

It is working now, thanks!

karthur1
in reply to: adriaanslabbert

Glad you go it going.  What was the issue?

adriaanslabbert
in reply to: karthur1

I restarted Inventor and I was working with an assembly that wasn't saved, saved the assembly and then it was working....lol

 

thanks for the help!

Hi Curtis, thanks for your ruler but I would like to add the external line. I think so is the sheet scale-layout configuration before printing.

aronmatheus_0-1621621683621.png