Export DXF to path

Export DXF to path

Anonymous
Not applicable
2,104 Views
13 Replies
Message 1 of 14

Export DXF to path

Anonymous
Not applicable

I am trying to edit some Ilogic code to export drawings to dxf files on a location on our network.

So far I can't get the code to run even with the same location, It's giving me an invalid argument error and I just can't see where the problem is.

 

As for the path, the problem is that the drawing numbers are just sequentially numbered, and organized into blocks of 500. I had thought to try to use a custom parameter to get the file path by rounding the drawing number down to the nearest 500, but I have no idea how to get that inserted into the file path command. Any ideas?

 

Thanks for any help.

 

Here is the code I am starting with:

 

' 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" 'same folder, or uncomment:  
'oDataMedium.FileName = "C:\myDXFfolder\" & ThisDoc.FileName(False) & ".dxf" 'fixed folder  
'Publish document.  
DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)  
0 Likes
Accepted solutions (1)
2,105 Views
13 Replies
Replies (13)
Message 2 of 14

Anonymous
Not applicable

Should have also mentioned I'm using IV 2019

0 Likes
Message 3 of 14

sajith_subramanian
Autodesk Support
Autodesk Support

Hi @Anonymous,

 

You could face an invalid argument error if there are issues with the ini file that is being used.

To check the same, there would be a sample ini file in this location: C:\Users\Public\Documents\Autodesk\Inventor 2019\Design Data\DWG-DXF\exportdxf.ini.

You could try using the above file in your code.

 

So your code would be something like:

 

Dim strIniFile As String 
strIniFile = "C:\Users\Public\Documents\Autodesk\Inventor 2019\Design Data\DWG-DXF\exportdxf.ini" 

 

Let me know if this helps resolve your error.

 

Regards,

Sajith


Sajith Subramanian
Autodesk Developer Network
0 Likes
Message 4 of 14

Anonymous
Not applicable

The error has changed, anyway. So I think that was at least part of it.

The error is now this:

 

Error in rule: dxf, in document: 10010159

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

 

The More info screen:

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)

 

I wish I knew if that was supposed to be something useful.

0 Likes
Message 5 of 14

sajith_subramanian
Autodesk Support
Autodesk Support

Hi @Anonymous,

 

I can reproduce the same error only when the oDataMedium.FileName does not point to a valid location.  Could you confirm if it is pointing to a valid existing location and you have  all required access rights to save the created DXF in it.

 

Regards,

Sajith


Sajith Subramanian
Autodesk Developer Network
0 Likes
Message 6 of 14

Anonymous
Not applicable

It was set to the same location, I switched the comment to a directed location and it worked, so thanks for that.

 

So my last issue figuring out how to get it to insert a value to the save location string based on the part number.

 

I can get it to create a parameter, and round it down so it matches the folder name, but I'm just not sure how to get it to use that in the save path

0 Likes
Message 7 of 14

sajith_subramanian
Autodesk Support
Autodesk Support

Hi @Anonymous,

 

If I understand correctly, instead of creating a parameter, you can use iProperties.Value("Project", "Part Number") to fetch the part number, do the necessary manipulation and append it as a string to the file save path.

 

Regards,

Sajith


Sajith Subramanian
Autodesk Developer Network
0 Likes
Message 8 of 14

Anonymous
Not applicable

Indeed, that's where I'm lost.

0 Likes
Message 9 of 14

sajith_subramanian
Autodesk Support
Autodesk Support

Take a look at the below code snippet, which does something similar.

Dim prt_num As Double
prt_num = CDbl(iProperties.Value("Project", "Part Number"))
prt_num = Round(prt_num / 500, 0) * 500 ' round off to nearest 500
'Set the destination file name  
oDataMedium.FileName = ThisDoc.Path & "\" & prt_num.ToString & ".dxf" 'same folder, or uncomment:  

Let me know if this helps.

 

Regards,

Sajith


Sajith Subramanian
Autodesk Developer Network
0 Likes
Message 10 of 14

Anonymous
Not applicable

Well I thought I was pretty close, but I've gotten a bunch of errors.

First I tried editing your code to be rounding down, but it told me that I was trying to divide by zero, but I couldn't find out how that was happening.

One time I thought I had it, it said that the &prt.ToS part was not valid.

 

Now I just get an unspecified error again.

 

Here is the snippet

Dim prt_num As Double
prt_num = CDbl(iProperties.Value("Project", "Part Number"))
inc = 500 ' rounding increment ( .125, .25, .5, etc)
roundedDown = Floor(Round(prt_num,0) / inc) * inc ' round down to nearest 500
'Set the destination file name  
oDataMedium.FileName = "O:\Burn Data\Dxfs\" & prt_num.ToString & "\" & ThisDoc.FileName(False) & ".dxf" 'fixed folder  
'Publish document.  
0 Likes
Message 11 of 14

sajith_subramanian
Autodesk Support
Autodesk Support

Hi @Anonymous,

 

I can reproduce the unspecified error if the location is not an already existing valid location. That is the line of code  "O:\Burn Data\Dxfs\" & prt_num.ToString.....  should point to an existing folder.

If you are looking to create folders on the fly using the prt_num, you could try the below code.

Dim prt_num As Double
prt_num = CDbl(iProperties.Value("Project", "Part Number"))
inc = 500 ' rounding increment ( .125, .25, .5, etc)
roundedDown = Floor(Round(prt_num,0) / inc) * inc ' round down to nearest 500
'Set the destination file name  
Dim fldrpath As String
fldrpath = "C:\Temp\" & prt_num.ToString
If Not System.IO.Directory.Exists(fldrpath) Then
    System.IO.Directory.CreateDirectory(fldrpath)
End If
oDataMedium.FileName = fldrpath & "\" & ThisDoc.FileName(False) & ".dxf" 'fixed folder  

 Let me know if this resolves your issue.

 

Regards,

Sajith


Sajith Subramanian
Autodesk Developer Network
0 Likes
Message 12 of 14

Anonymous
Not applicable

I don't really want it creating folders, but I ran it just to see what would happen, and I think that may have shed some light on why it wasn't working.

 

It created a folder named 10010261 (The original part number, not rounded down) and a DXF in it with no file name, which can't be opened.

 

So it was looking for this folder that would never exist, it seems to be just skipping that step for some reason. It should look for folder 10010000, then save as 10010261.dxf at that location.

 

' 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 = "O:\$Inventor Design Data & Templates\Design Data New\DWG-DXF\exportdxf.ini"  
' Create the name-value that specifies the ini file to use.  
oOptions.Value("Export_Acad_IniFile") = strIniFile  
End If  
Dim prt_num As Double
prt_num = CDbl(iProperties.Value("Project", "Part Number"))
inc = 500 ' rounding increment ( .125, .25, .5, etc)
roundedDown = Floor(Round(prt_num,0) / inc) * inc ' round down to nearest 500
'Set the destination file name  
Dim fldrpath As String
fldrpath = "O:\Burn Data\Dxfs\" & prt_num.ToString
oDataMedium.FileName = fldrpath & "\" & ThisDoc.FileName(False) & ".dxf"  
'Publish document.  
DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
0 Likes
Message 13 of 14

sajith_subramanian
Autodesk Support
Autodesk Support
Accepted solution

Hi @Anonymous,

 

The reason the original part wasn't being rounded down was that it was assigned to the roundedDown variable but wasn't being used. 

 

I have updated the code below, which seems to work for me.  Just update the code for the file paths for the ini file and output file and try it out at your end.

 

' 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\Public\Documents\Autodesk\Inventor 2019\Design Data\DWG-DXF\exportdxf.ini"     
' Create the name-value that specifies the ini file to use.  
oOptions.Value("Export_Acad_IniFile") = strIniFile  
End If  
Dim prt_num As Double
prt_num = CDbl(iProperties.Value("Project", "Part Number"))
inc = 500 ' rounding increment ( .125, .25, .5, etc)
prt_num = Floor(Round(prt_num,0) / inc) * inc ' round down to nearest 500
'Set the destination file name  
Dim fldrpath As String
fldrpath = "C:\Temp\" & prt_num.ToString
If Not System.IO.Directory.Exists(fldrpath) Then
    System.IO.Directory.CreateDirectory(fldrpath)
End If
oDataMedium.FileName = fldrpath & "\" & ThisDoc.FileName(False) & ".dxf"  
'Publish document.  
DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

Regards,

Sajith


Sajith Subramanian
Autodesk Developer Network
0 Likes
Message 14 of 14

Anonymous
Not applicable

Brilliant, that's done it.

 

Thanks a million.

0 Likes