Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DXF Scaling

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
darren.lees
477 Views, 6 Replies

DXF Scaling

Hi All,

I have an issue with exporting DXFs

 

I have created a routine for exporting DXF files to a specific location from an Inventor DWG file, with a lot of help from this forum.  Thank you!!

 

I have an issue with scaling of the final DXF.

 

If I was to save a DXF in a conventional manner: SAVE>SAVE COPY AS>etc.  the DXF file comes out at the correct scale, i.e. the size of the item is as the dimensions states.

 

However, when I use the routine the DXF file comes out 25.4 times too small (metric to imperial), though any dimension will still show the correct value.

 

I have literally tried EVERY option within the Save As DXF options dialogue and saved many exportdxf.ini files to suit each option. I know the routine looks at the correct .ini file as I've seen the various DXF layouts change when a different .ini file is chosen.  I have even tried using an AutoCAD template which I know uses mm instead of inches as a base unit, to no avail.

 

We send the DXFs to profilers to cut out plates for fabrications and, though the profilers should check the DXFs anyway, it may become an issue at some point.  I'm interested to know why the scaling may be an issue.

 

Does anyone have any idea where the problem may lie???

 

Any help is greatly appreciated.

 

 

THis is the code I use.  It is used in collaboration with other routines to create PDFs, etc.

 

Sub Main
	'Make sure the active document is a drawing document.
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("This Rule, '" & iLogicVb.RuleName & "' only works on Drawing Documents. Exiting.", vbCritical, "WRONG DOCUMENT TYPE")
		Return
	End If
	Dim oDDoc As DrawingDocument = ThisDoc.Document

	Dim oSaveFolder = SharedVariable("oDXF_Folder")


	'Dim oDesiredFolder As String = oSaveFolder
	If Not System.IO.Directory.Exists(oSaveFolder) Then
		System.IO.Directory.CreateDirectory(oSaveFolder)
	End If
	'---------------------------------------------------------------------------

	Dim sPath As String = oSaveFolder

	'MessageBox.Show("File Path = " & sPath, "File Path")

	Dim oSheets As Inventor.Sheets = oDDoc.Sheets

	For Each oSheet As Inventor.Sheet In oSheets
		oSheet.Activate
		Dim oView As DrawingView = Nothing
		Try : oView = oSheet.DrawingViews.Item(1) : Catch : End Try
		If oView Is Nothing Then Continue For
		Dim oModelDoc As Inventor.Document = oView.ReferencedDocumentDescriptor.ReferencedDocument

		'Use the name of the SHEET as the file name
		Dim oFName As String = IO.Path.GetFileNameWithoutExtension(ActiveSheet.Sheet.Name)
		'MessageBox.Show("File Name = " & oFName, "Filename")

		Dim sDXF_FullFuleName As String = sPath & "\" & oFName & ".dxf"	'Create filename for DXF files
		Logger.Info("Proposed DXF FullFileName = " & sPath)
		'Create the temporary drawing file, copy the sheet, then delete all sheets in new drawing.
		Dim oTempDDoc As DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, , False)
		Dim oTempSheet As Sheet = oSheet.CopyTo(oTempDDoc)
		For Each oTSheet As Inventor.Sheet In oTempDDoc.Sheets
			If oTSheet IsNot oTempSheet Then oTSheet.Delete
		Next 'oTSheet
		'call the custom Sub to run, to export the DXF
		ExportDrawingToDXF(oTempDDoc, sDXF_FullFuleName)
		oTempDDoc.Close(True)
	Next

End Sub

Sub ExportDrawingToDXF(oDrawingDoc, sDXFFullFileName)
	'Get the DXF Translator AddIn
	Dim oDXF_AddIn As TranslatorAddIn = Nothing
	For Each oAddIn As ApplicationAddIn In ThisApplication.ApplicationAddIns
		If oAddIn.DisplayName = "Translator: DXF" Then oDXF_AddIn = oAddIn
	Next
	If oDXF_AddIn Is Nothing Then Exit Sub
	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

	oDataMedium.FileName = sDXFFullFileName '<<< assign the file name here >>>
	If oDXF_AddIn.HasSaveCopyAsOptions(oDrawingDoc, oContext, oOptions) Then
		'If your export DXF settings are saved somewhere else or named differently, you will have to change this next line.
		'oOptions.Value("Export_Acad_IniFile") = "L:\Templates\2022\Design Data\DWG-DXF\exportdxf.ini"
		oOptions.Value("Export_Acad_IniFile") = "L:\Templates\2022\Design Data\DWG-DXF\DXF Export.ini"
	End If
	'Publish DXF
	Try
		oDXF_AddIn.SaveCopyAs(oDrawingDoc, oContext, oOptions, oDataMedium)
		Logger.Info("Just exported the following DXF file:" & vbCrLf & sDXFFullFileName)
	Catch
		Logger.Error("Error exporting the following DXF file:" & vbCrLf & sDXFFullFileName)
	End Try
End Sub
6 REPLIES 6
Message 2 of 7
A.Acheson
in reply to: darren.lees

Hi @darren.lees 

 

In sounds like the dxf .ini file is picking up the wrong units. Check the document units of the inventor drawing. Not sure if this has any bearing on this You could try and open the .ini file in a text editor and find units. An internet search should tell you how. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 7
darren.lees
in reply to: darren.lees

Hi @A.Acheson,

 

Thank you for this. However, when saving a DXF in the normal fashion, SAVE> SAVE COPY AS> .... everything is OK. This suggests to me that the units are the template is not part of the problem.

 

When I use the routine WITHOUT pointing to any .ini file, the scaling is still off. This suggests to me that the problem may be with the routine I'm using (see above).

This is the .ini file I am using to output our DXFs...

 

[EXPORT SELECT OPTIONS]
AUTOCAD VERSION=AutoCAD 2010
CREATE AUTOCAD MECHANICAL=No
USE TRANSMITTAL=No
USE CUSTOMIZE=No
CUSTOMIZE FILE=C:\Users\Public\Documents\Autodesk\Inventor 2022\Design Data\DWG-DXF\FlatPattern.xml
CREATE LAYER GROUP=No
PARTS ONLY=No
REPLACE SPLINE=No
CHORD TOLERANCE=0.001000
[EXPORT PROPERTIES]
SELECTED PROPERTIES=
[EXPORT DESTINATION]
SPACE=Model
SCALING=Geometry
ALL SHEETS=Yes
MAPPING=MapsBest
MODEL GEOMETRY ONLY=No
SHEET CONTENT ONLY=No
EXPLODE DIMENSIONS=No
SYMBOLS ARE BLOCKED=Yes
AUTOCAD TEMPLATE=
DESTINATION DXF=Yes
USE ACI FOR ENTITIES AND LAYERS=No
ALLOW RASTER VIEWS=No
SHOW DESTINATION PAGE=Yes
ENABLE POSTPROCESS=Yes
[EXPORT LINE TYPE & LINE SCALE]
LINE TYPE FILE=C:\Users\Public\Documents\Autodesk\Inventor 2022\COMPATIBILITY\Support\invISO.lin
Continuous=Continuous;0.
Dashed=DASHED;0.
Dashed Space=DASHED_SPACE;0.
Long Dash Dotted=LONG_DASH_DOTTED;0.
Long Dash Double Dot=LONG_DASH_DOUBLE_DOT;0.
Long Dash Triple Dot=LONG_DASH_TRIPLE_DOT;0.
Dotted=DOTTED;0.
Chain=CHAIN;0.
Double Dash Chain=DOUBLE_DASH_CHAIN;0.
Dash Double Dot=DASH_DOUBLE_DOT;0.
Dash Dot=DASH_DOT;0.
Double Dash Dot=DOUBLE_DASH_DOT;0.
Double Dash Double Dot=DOUBLE_DASH_DOUBLE_DOT;0.
Dash Triple Dot=DASH_TRIPLE_DOT;0.
Double Dash Triple Dot=DOUBLE_DASH_TRIPLE_DOT;0.

 

I know that the SPACE=Model and SCALING=Geometry lines suggest the possible scaling factors, but changing this doesn't have the desired effect.

 

I'm reverting back to the exportdxf.ini file which is supplied with Inventor to see what that does.

Wish me luck!!

 

I'll keep digging, though as I said before, any help is greatly appreciated!!

 

 

🙂

Message 4 of 7
A.Acheson
in reply to: darren.lees

Unfortunately I cannot offer more advice as I don’t use this method. I don’t think i could get it working just like you and instead  opted to export the dxf file from the flat pattern part which has the added benefit of removing dimensions and title blocks. The down side is you need to construct the .ini file options within the code before saving as dxf.

 

Edit:

Here is a link to this method. It is currently set up for part only export but you could chamge that to pivk up the reference view of the drawing. And here is the help page to create the dxf settings

 

If you still want to get the dxf from the drawing maybe @MjDeck might offer assistance with what might be causing the unit of measure scale issue. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 5 of 7
darren.lees
in reply to: darren.lees

Hi @A.Acheson ,
Thank you for you help anyway!!

 

Unfortunately, the link you have included doesn't work.

 

Could you repost it??

 

THank you

Message 6 of 7
darren.lees
in reply to: A.Acheson

Hi @A.Acheson,

 

So, this morning I managed to figure out where the problem lay with regards to the DXF scaling.


This line in the code:

 

"Dim oTempDDoc As DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, , False)"

 

...requires a template file between ".kDrawingDocumentObject, <template file> , False".

 

Thanks again for your help!!

Message 7 of 7
A.Acheson
in reply to: darren.lees

I fixed the link in that post. Glad you got that to work. Interesting to see if you end the rule after the temp drawing is created what are the document units? When you don't supply  template path an internal template us used and it is this template that could be set to imperial and not metric to match your dimension styles. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report