DWG / DXF Export - Scaling Options

DWG / DXF Export - Scaling Options

matt_jlt
Collaborator Collaborator
2,651 Views
4 Replies
Message 1 of 5

DWG / DXF Export - Scaling Options

matt_jlt
Collaborator
Collaborator

Does anyone know where i can find the list of valid options for exporting of DWG / DXF file export options? I cna't seem to find them anywhere, I have worked out most of them by using the default files and looking at other posts in the forums but i can't work out the scaling option. Can someone please provide the text for each one

 

INI file entry name = "SCALING="

 

Available options

Base View Scale - Model Space = ?
Base View Scale - Layout = ?
Sheet Scale - Model Space = ?
Sheet Scale - Layout = ?
Full Scale (1: 1) - Model Space = ?

 

Thanks, Matt.

0 Likes
Accepted solutions (1)
2,652 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @matt_jlt.  There is a code routine find out what the available options are within a TranslatorAddIn.  It's not perfect, but often gets you most of the way there.  It will tell you what the official names of each option are, and what their current values are, but won't tell you what all the possible values are for each option, or what Enum (pre-established enumeration of variations of some type) (if any) the option's value may be a variation of.  There appear to be two different translator add-ins for these two, but both appear to be defined within the same .dll file (DWGTrans.dll).  And when I run this code on both of these, I get the same results.  It also depends on which type of document you have open/active when you run the rule.  (You get different results when a model file is open than you do when a drawing file is open, because there are different options for each situation.)

When an .idw drawing file is open, it returns one option for both translator add-ins:

option name = "Export_Acad_IniFile"

option value = (a String - the full path and file name of the .ini file to be used, including the .ini file extension)

When a model file is open, it returns 4 options:

option name = "Solid"

Option value = (Boolean - True/False)

 

option name = "Surface"

option value = (Boolean - True/False)

 

option name = "Sketch"

option value = (Boolean - True/False)

 

option name = "DwgVersion"

option value = (a number - for example 33)

 

I would assume the scale setting you are talking about is set up within the .ini file.  If you have previously gone through the export process of a drawing manually, and saved the configuration, you were presented with a file explorer screen where you can specify a location and name for the .ini file it creates.  You would need to point this option's value to the full path and file name of the .ini file you used in that process.

Here is the iLogic rule to get the options:

Sub Main
	'specify document to be exported/translated
	Dim oDoc As Document = ThisDoc.Document
	
	'Get the target TranslatorAddIns to process
	Dim oDXF As TranslatorAddIn
	Dim oDWG As TranslatorAddIn
	For Each oAppAddin As ApplicationAddIn In ThisApplication.ApplicationAddIns
		If oAppAddin.DisplayName = "Translator: DXF" Then
			oDXF = oAppAddin
		ElseIf oAppAddin.DisplayName = "Translator: DWG" Then
			oDWG = oAppAddin
		End If
	Next
	
	'prepare variables to hold values returned from custom Function below
	Dim oDXFOptions As String
	Dim oDWGOptions As String
	'make sure TranslatorAddIn was found, then run Function
	If Not IsNothing(oDXF) Then
		oDXFOptions = GetTranslatorOptions(oDoc, oDXF)
	End If
	If Not IsNothing(oDWG) Then
		oDWGOptions = GetTranslatorOptions(oDoc, oDWG)
	End If
	'report the results
	MsgBox(oDXFOptions, , "DXF Options")
	MsgBox(oDWGOptions, , "DWG Options")
End Sub

Function GetTranslatorOptions(oDocToExp As Document, oTransAddIn As TranslatorAddIn) As String
	'The following lines create the needed input variables
	Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
	oContext.Type = IOMechanismEnum.kUnspecifiedIOMechanism
	Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
	Dim oOptionsString As String = String.Empty

	'When you provide the input variables, it fills in the Options (names & values) for you
	If oTransAddIn.HasSaveCopyAsOptions(oDocToExp, oContext, oOptions) Then
		'the next line would show the options dialog
		'oTransAddIn.ShowSaveCopyAsOptions(oDocToExp, oContext, oOptions)
		Dim oItem As Integer = 1
		For Each oPair In oOptions 'do not define Type of oPair ahead of time
			oOptionsString = oOptionsString & vbCrLf & "Option Name = " & oOptions.Name(oItem) & vbCrLf & "Option Value =   " & oOptions.Value(oOptions.Name(oItem)) & vbCrLf
			'this next line would write each option to the Logger
			'Logger.Trace("Option Name =   " & oOptions.Name(oItem) & "  /  Option Value =   " & oOptions.Value(oOptions.Name(oItem)))
			'MsgBox(oOptions.Name(oItem) & " = " & oOptions.Value(oOptions.Name(oItem)), , "")
			oItem = oItem + 1
		Next
	End If
	Return oOptionsString
End Function

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 5

matt_jlt
Collaborator
Collaborator

Thanks @WCrihfield , I'll save that code 🙂  but yes, it doesn't solve what are the available options issue.

I assume that at somepoint I saved / pointed to an INI file location but i can't find which one i am set to by default as there doesn't seem to be a location kept anywhere that I can see in any options. and i guess the answer would be to find that and export each option and see if it updates the INI file and read each combination.

 

But would be handy if someone from autodesk could provide the list of options for us? I have already checked the API dialog and found nothing. (could be that i have missed it)

 

If anyone has a list of the options I would appreciate it if it was posted here.

 

Thanks, Matt.

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor

If you are exporting an Inventor .idw or Inventor .dwg to an AutoCAD .dwg or AutoCAD .dxf, by code using their translator addins, there is only one option that can be specified for that export process.  Your only option in that situation is to specify the .ini file for it to use, which contains all the other available options.  As far as I know, you can't change any of the options/settings within that .ini file from the code.  The only course of action here seems to be to create a new .ini file, by going through the manual process and dialogs, setting everything up the way you want it within those dialogs, then using the [Save Configuration ...] button to create the new .ini file (while taking note of where you put it and what its name is.  (Create multiple this way if needed, each with different settings and different names.)  I believe the default location for these .ini files is the following:

"C:\Users\Public\Documents\Autodesk\Inventor 2021\Design Data\DWG-DXF\", then something like "exportdxf.ini" is the default one installed with Inventor.

(Inventor version in that path may be different, of course.)

 

Then you can specify the full file name of that .ini file you created as the value of that one option within the code.

Once you have created the .ini file(s), here one (of many) version of the main iLogic rule to export an 'active' drawing to DXF.

 

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing Document must be active for this rule to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
	ExportDrawingToDXF(oDDoc)
End Sub

Sub ExportDrawingToDXF(oDrg As DrawingDocument)
	'get the DXF Translator Add-in
	Dim oDXF As TranslatorAddIn
	For Each oAddin As ApplicationAddIn In ThisApplication.ApplicationAddIns
		If oAddin.AddInType = ApplicationAddInTypeEnum.kTranslationApplicationAddIn And
			oAddin.DisplayName.Contains("DXF") Then
			oDXF = oAddin
		End If
	Next
	
	'create the necessary variables
	Dim oTO As TransientObjects = ThisApplication.TransientObjects
	Dim oContext As TranslationContext = oTO.CreateTranslationContext
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	Dim oOptions As NameValueMap = oTO.CreateNameValueMap
	Dim oDataMedium As DataMedium = oTO.CreateDataMedium
	
	'DXF will be same path & name, but .dxf file extension
	Dim oFileName As String = System.IO.Path.ChangeExtension(oDrg.FullFileName, ".dxf")
	'set file name of DXF to be created
	oDataMedium.FileName = oFileName
	
	'look in the following location to find the default and/or Saved settings INI files and XML files that
	'specify your settings for importing and exporting DXF's and DWG's
	'C:\Users\Public\Documents\Autodesk\Inventor 2021\Design Data\DWG-DXF\
	
	Dim oINI_File As String = "C:\Users\Public\Documents\Autodesk\Inventor 2021\Design Data\DWG-DXF\exportdxf.ini"
	If Not System.IO.File.Exists(oINI_File) Then
		MsgBox("Couldn't find this INI file:  " & vbCrLf & oINI_File & vbCrLf & "Exiting.", , "")
		Exit Sub
	End If
	
	If oDXF.HasSaveCopyAsOptions(oDrg, oContext, oOptions) Then
		oOptions.Value("Export_Acad_IniFile") = oINI_File
	End If
	
	'each sheet of the drawing will be exported as a seperate DXF file
	'with the sheet name appended to the end of each file name
	oDXF.SaveCopyAs(oDrg, oContext, oOptions, oDataMedium)
End Sub

Or did you maybe have some other scenario in mind, like exporting sheet metal flat patters or faces to DXF?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 5

matt_jlt
Collaborator
Collaborator
Accepted solution

Thanks again for your help, because i couldn't find where my default INI file location was, someone else kindly gave me the exported options. I'll post them here for everyone.
Scale / Space Configuration options
Base View Scale - Model Space

Scaling = Geometry, Space = Model
Base View Scale - Layout

Scaling = Geometry, Space =  Layout
Sheet Scale - Model Space

Scaling = Text, Space = Model
Sheet Scale - Layout

Scaling = Text, Space = Layout
Full Scale(1: 1) - Model Space

Scaling = Full, Space = Model

0 Likes