Exporting multi-sheet IDW to dxf (ilogic)

Exporting multi-sheet IDW to dxf (ilogic)

per.widegren
Contributor Contributor
739 Views
6 Replies
Message 1 of 7

Exporting multi-sheet IDW to dxf (ilogic)

per.widegren
Contributor
Contributor

Hi Guys,

Im totaly new on this with ilogic and I whant to try having dxf files out from my IDW drawing by using this code...

I want the code to create an dxf folder, Puting the DXF file incl. rev into that folder. But.... somethink gores wrong....

any idea´s????

 

The code look like this  🙂

 

SyntaxEditor Code Snippet

' 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:\Users\Per\Documents\Vault\Inventor Templates\ilogic Rules\dxf_out.ini"


' Create the name-value that specifies the ini file to use.
oOptions.Value("Export_Acad_IniFile") = strIniFile
End If



 'Set the DXF target file name
oDataMedium.FileName = oFolder & "\" & oFileName & _
"_rev_" & oRevNum & ".dxf" 




'get DXF target folder path
oFolder = ThisDoc.Path & "\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)

 

It gives me this error.

Error in rule: 01_dxf, in document: MEP00131.idw

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

 

 

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.TranslatorAddIn.SaveCopyAs(Object SourceObject, TranslationContext Context, NameValueMap Options, DataMedium TargetData)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

 

 

0 Likes
740 Views
6 Replies
Replies (6)
Message 2 of 7

bradeneuropeArthur
Mentor
Mentor
' 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:\Users\Per\Documents\Vault\Inventor Templates\ilogic Rules\dxf_out.ini"


' Create the name-value that specifies the ini file to use.
oOptions.Value("Export_Acad_IniFile") = strIniFile
End If

Dim oRevNum As Inventor.Property
oRevNum = iProperties.Value("Project", "Revision Number")

Dim oFolder As String = ThisDoc.Path & "\DXF"
Dim oFileName = oDocument.FullDocumentName

 'Set the DXF target file name
oDataMedium.FileName = oFolder & "\" & oFileName & _
"_rev_" & oRevNum & ".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)

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 3 of 7

Anonymous
Not applicable

Hello,

There is a problem with this rule in Inventor 2021 😞

The problem is in "DXFAddIn.SaveCopyAs" string, ilogic gives an error "Exception from HRESULT: 0x80070057 (E_INVALIDARG)"

Do you know how to fix it?

0 Likes
Message 4 of 7

per.widegren
Contributor
Contributor
Hmm No idea. It works for me in 2021.
I'm using this code.... Saving the DXF files locally.


SyntaxEditor Code Snippet

' Get the DXF translator Add-In.Dim DXFAddIn As
TranslatorAddInDXFAddIn =
ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")

'Set a reference to the active document (the document to be
published).Dim oDocument As DocumentoDocument =
ThisApplication.ActiveDocumentDim oContext As
TranslationContextoContext =
ThisApplication.TransientObjects.CreateTranslationContextoContext.Type
= IOMechanismEnum.kFileBrowseIOMechanism

' Create a NameValueMap objectDim oOptions As NameValueMapoOptions =
ThisApplication.TransientObjects.CreateNameValueMap

' Create a DataMedium objectDim oDataMedium As DataMediumoDataMedium =
ThisApplication.TransientObjects.CreateDataMedium

' Check whether the translator has 'SaveCopyAs' optionsIf
DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) ThenDim
strIniFile As StringstrIniFile =
"C:\Users\Per\Documents\Vault\Inventor Templates\ilogic
Rules\dxf_out.ini"

' Create the name-value that specifies the ini file to
use.oOptions.Value("Export_Acad_IniFile") = strIniFileEnd If

oContext.Type = IOMechanismEnum.kFileBrowseIOMechanismDim oData As
DataMediumoData = ThisApplication.TransientObjects.CreateDataMedium


FilePath= ThisDoc.Path 'This .IDW's pathOutputPath = FilePath & "\"
& "DXF" 'Output destination for the new DXFOutputFileName =
iProperties.Value("Project", "Part Number") '& "Rev" & oRevnum &
".stp" 'Output File Name as specified in Custom iProperties, as
specified by the iLogic rule OutputFileName
'Check for existance of DXF folder and create if not foundIf Not
System.IO.Directory.Exists(OutputPath) Then
System.IO.Directory.CreateDirectory(OutputPath)End If

oRevNum = iProperties.Value("project", "revision number")
'Set the destination path & file nameoData.FileName = OutputPath & "\"
& OutputFileName & "_Rev_" & oRevNum & ".dxf"
'Publish document.DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oData)
'Publish Document'oSTEPTranslator.SaveCopyAs(oModelDoc, oContext,
oOptions, oData)
'Open File Management'Process.Start("explorer.exe", ThisDoc.Path)i =
MessageBox.Show("Open Containing Folder?", "Open File
Management",MessageBoxButtons.YesNo,MessageBoxIcon.Question)If i =
vbYes Then Process.Start("explorer.exe", ThisDoc.Path)



'Set the destination file nameoDataMedium.FileName =
ThisDoc.PathAndFileName(False) & ".dxf"

'Launch the dxf file in whatever application Windows is set to open
this document type withi = MessageBox.Show("Preview the DXF file?",
"DXF Preview",MessageBoxButtons.YesNo,MessageBoxIcon.Question)'If i =
vbYes Then ThisDoc.Launch(oDataMedium.FileName)If i = vbYes Then
ThisDoc.Launch(oData.FileName)



0 Likes
Message 5 of 7

Anonymous
Not applicable

It's very strange, I can't fugure out where is the cause. I'm trying with your and mine (little bit modificated) the same result 😞 All works perfect on Inventor 2020. Here is my rule:

' Get the DXF translator Add-In.
oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension'
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

'get CNC target folder path
oFolder = Left(oPath, InStrRev(oPath, "\", -1)) & "CNC"

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

If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
	Dim strIniFile As String
	strIniFile = "C:\Users\Dmitrij\OneDrive\Ribbons\DXF_EXPORT.ini"
	oOptions.Value("Export_Acad_IniFile") = strIniFile
End If

oDataMedium.FileName = oFolder & "\" & ".dxf"

Call DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

Maybe you can check it?

0 Likes
Message 6 of 7

bradeneuropeArthur
Mentor
Mentor

this file is different for you!

 

"C:\Users\Per\Documents\Vault\Inventor Templates\ilogic
Rules\dxf_out.ini"

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 7 of 7

Anonymous
Not applicable

Yes, sure, I know that. I was chaned to mine with the mine path.

0 Likes