iLogic IDW to DXF error

iLogic IDW to DXF error

JoãoASilva
Advocate Advocate
1,569 Views
12 Replies
Message 1 of 13

iLogic IDW to DXF error

JoãoASilva
Advocate
Advocate

Hi!

 

I've been using the forums to get some iLogic rules to do some tedious steps for me.

On my last step to get the code completly working as intended, I get an error on Draftsight when opening my dxf file. This error only occurs when I export to dxf using the code, but if I use Save Copy As I get no error at all.

 

This drawing file version is not supported.

 

Code explanation:

- Go through each sheet and get model in view part number and revision;

- If part then it opens the part, saves it as .step  and closes;

- If sheetmetal then it saves copy of sheet as .dxf;

- Save each sheet individually to .pdf;

 

' 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 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

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

If TypeOf ThisDoc.Document Is DrawingDocument Then
        Dim dwgDoc As DrawingDocument = ThisDoc.Document
        For Each dwgSheet As Sheet In dwgDoc.Sheets
            If dwgSheet.DrawingViews.Count > 0 Then
                modelFile = dwgSheet.DrawingViews(1).ReferencedDocumentDescriptor.FullDocumentName
                modelDoc = dwgSheet.DrawingViews(1).ReferencedDocumentDescriptor.ReferencedDocument
                prtNumber = modelDoc.PropertySets("{32853F0F-3444-11D1-9E93-0060B03C1CA6}").ItemByPropId(5).Value
		Rev = modelDoc.PropertySets.Item("Summary Information").Item("Revision Number").Value
            'MessageBox.Show(modelDoc.Subtype)
				If modelDoc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Then
					Dim oPart As PartDocument
					Dim oPartPath As String

					' Get drawing path
					oPartPath = modelFile

					' Set a reference to the target part
					oPart = ThisApplication.Documents.ItemByName(oPartPath)

					' Open the target part
					ThisApplication.Documents.Open(oPartPath)

					' Save a copy of oPart as a step file
					oPart.SaveAs(Replace(oPartPath, ".ipt","." & Rev & ".step"), True)

					' Close oPart
					oPart.Close
				End If
				If modelDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
					oContext = ThisApplication.TransientObjects.CreateTranslationContext
					oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
					'Set the destination file name
					oDataMedium.FileName = prtNumber & "." & Rev & ".dxf"
					'Publish document.
					DXFAddIn.SaveCopyAs(modelDoc, oContext, oOptions, oDataMedium)
				End If
			End If
        Next
    End If
	
	'['Sub Variables
oRefDocs = ThisApplication.ActiveDocument.AllReferencedDocuments
Dim oDoc As Document
oFolder = ThisDoc.Path
oAddIns = ThisApplication.ApplicationAddIns
oTG = ThisApplication.TransientObjects']
'['PDF Export
'['PDF Options
PDFAddIn = oAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oContext = oTG.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = oTG.CreateNameValueMap
oDataMedium = oTG.CreateDataMedium
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 4800
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintCurrentSheet']
For Each oDoc In oRefDocs
	idwPathName = Left(oDoc.FullDocumentName, Len(oDoc.FullDocumentName) -3) & "idw"
	If System.IO.File.Exists(idwPathName) Then
		oDrawDoc = ThisApplication.Documents.Open(idwPathName, True)
		For Each oSheet As Sheet In oDrawDoc.Sheets
			oSheet.Activate
			oSheetName = oSheet.Name.Split(":")(0)
			oDataMedium.FileName = oFolder & "\" & oSheetName & ".pdf"
			Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
		Next
	End If
Next']

I've tried exporting the face of the 3D model, but it's not what we want.

João Silva

Mechanical Engineer

 

0 Likes
1,570 Views
12 Replies
Replies (12)
Message 2 of 13

philip1009
Advisor
Advisor

For the sheet metal parts, how are you manually saving the dxf file?

0 Likes
Message 3 of 13

JoãoASilva
Advocate
Advocate

Have the 2D done (idw), then go to File > Save As > Save Copy As > (.DXF). (I use the Shortcut: Alt > F > F >C)

I usually save using the 2000 version.

Doing that way causes me no trouble.

 

ATM I'm trying to create a rule just for dxf saving and calling it whenever needed (no progress so far).

João Silva

Mechanical Engineer

 

0 Likes
Message 4 of 13

philip1009
Advisor
Advisor

I'm guessing your goal with that code is to get a DXF file of the flat pattern, exporting the flat pattern directly from the part should yield better results depending on your workflow:

 

SyntaxEditor Code Snippet

If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
	oCompDef = oDoc.ComponentDefinition
	If oCompDef.HasFlatPattern = False Then Continue For
	If oCompDef.HasFlatPattern = True Then
		ThisApplication.Documents.Open(oDoc.FullFileName, True)
		oCompDef.FlatPattern.Edit
	End If
	oCompDef.DataIO.WriteDataToFile("FLAT PATTERN DXF?AcadVersion=2000" _
	+ "&InvisibleLayers=IV_TANGENT;IV_BEND;IV_BEND_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL" _
	+ "&OuterProfileLayer=0" _
	+ "&InteriorProfilesLayer=0" _
	+ "&FeatureProfilesLayer=0" _
	+ "&FeatureProfilesDownLayer=0" _
	+ "&SimplifySplines=True" _
	+ "&LINEAR TOLERANCE=0.010" _
	+ "&MergeProfilesIntoPolyline=True" _
	+ "&RebaseGeometry=False" _
	+ "&TrimCenterlines=True", "PUT FOLDER PATH HERE" + oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value + ".dxf")
End If
oDoc.Close(True)
0 Likes
Message 5 of 13

JoãoASilva
Advocate
Advocate

My goal is to export DXF from IDW.

 

There is a custom snippet that already came with Inventor, called " Export DXF from IDW":

' 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.ActiveDocument
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
'Set the destination file name
oDataMedium.FileName = ThisDoc.PathAndFileName(False) & ".dxf"
'Publish document.
DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'Launch the dxf file in whatever application Windows is set to open this document type with
i = MessageBox.Show("Preview the DXF file?", "Title",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
If i = vbYes Then ThisDoc.Launch(oDataMedium.FileName)

If I change "ThisDoc.PathAndFileName(False)" to "ThisDoc.PathAndFileName(True)" it stil works, but if I change it to "ThisDrawing.ActiveSheet.Name.Split(":")(0)" then it doesn't work, nor if i try using any kind of text instead of the function.

 

If this worked, i could call it from the other rule, wich filters part and sheetmetal.

João Silva

Mechanical Engineer

 

0 Likes
Message 6 of 13

philip1009
Advisor
Advisor

Just for the sake of double checking, could you post the contents of the dxfout.ini file you're using?  There might be something in there causing problems with Draftsight.

0 Likes
Message 7 of 13

JoãoASilva
Advocate
Advocate

I tried changing the .ini file and the code a bit, but still no success.

 

[EXPORT SELECT OPTIONS]
AUTOCAD VERSION=AutoCAD 2000
CREATE AUTOCAD MECHANICAL=No
USE TRANSMITTAL=No
USE CUSTOMIZE=No
CUSTOMIZE FILE=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=LooksBest
MODEL GEOMETRY 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
[EXPORT LINE TYPE & LINE SCALE]
LINE TYPE FILE=COMPATIBILITY\Support\invANSI.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,

João Silva

Mechanical Engineer

 

0 Likes
Message 8 of 13

philip1009
Advisor
Advisor

Basically my understanding is there's a setting in the manual export that isn't being specified in the export code and Inventor is just using a default that's wrong, or something in the ini file is wrong.  I'd suggest you do manual exports with different settings until you find something that breaks compatibility with Draftsight, then once we find out what that issue is, either fix the ini file, or specify more oOptions.Value settings in the code that we're not aware of yet.  I doubt the ini file is the problem since manual exports are fine.

 

EDIT:  Other than that, I'll keep digging around, I'm sure there's a solution somewhere.

0 Likes
Message 9 of 13

JoãoASilva
Advocate
Advocate

Thank you for all your answers so far!

 

And how about the snippet to "ExportDXF from IDW"?

Is there anything I can write so it doesn't chooses to export all sheets, just the current one?

Or maybe in the .ini file?

Is there something I can add to the text part of oOptions.Value("here") to make it do what I want?

 

I'm no power user, I just have common knowledge regarding coding in general, so there a lot of variables that I don't even know about.

João Silva

Mechanical Engineer

 

0 Likes
Message 10 of 13

philip1009
Advisor
Advisor

The Export DXF snippet is basically doing the same thing your original code is doing by calling up the add-in, specifying your options with the ini file and oOptions.Value, then executing the save copy.

 

For exporting a single sheet, there's a line in the ini file labeled

ALL SHEETS=Yes

 Change that to No.

 

I do think there's something available in oOptions that has to be specified.  I'm looking around to find the list of options that can be specified.

0 Likes
Message 11 of 13

JoãoASilva
Advocate
Advocate

I changed it to No and it still exports all sheets... (that's weird)

Since ALL SHEETS = NO it should export the current active sheet of the document.

João Silva

Mechanical Engineer

 

0 Likes
Message 12 of 13

aronmatheus
Advocate
Advocate

Hi, João. I liked this way .ini stayed better the template, using sheet-scale.

[EXPORT SELECT OPTIONS]
AUTOCAD VERSION=AutoCAD 2007
CREATE AUTOCAD MECHANICAL=No
USE TRANSMITTAL=No
USE CUSTOMIZE=No
CUSTOMIZE FILE=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=Layout
SCALING=Sheet Scale
ALL SHEETS=Yes
MAPPING=MapsBest
MODEL GEOMETRY 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 2019\COMPATIBILITY\Support\invDIN.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.

0 Likes
Message 13 of 13

JoãoASilva
Advocate
Advocate

Hi @aronmatheus ,

 

That's exactly what I have now 😊

João Silva

Mechanical Engineer

 

0 Likes