SaveCopyAs API for AutoCAD dwg returns a zip file

SaveCopyAs API for AutoCAD dwg returns a zip file

johnster100
Collaborator Collaborator
1,141 Views
8 Replies
Message 1 of 9

SaveCopyAs API for AutoCAD dwg returns a zip file

johnster100
Collaborator
Collaborator

Hi,

I'm trying to export some Inventor dwg's to AutoCAD dwg's.

 

The issue is they are always created in a zip file. I have tried the following and it does not work:

 

Dim DWGAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")

Dim oDwgOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap

oDwgOptions.Value("USE TRANSMITTAL") = "No"

 

Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext

oContext.Type = Inventor.IOMechanismEnum.kFileBrowseIOMechanism

 

Call DWGAddIn.SaveCopyAs(oDwgDog, oContext, oDwgOptions, oData)

 

I would rather not use an ini file as this will be run on many different computers .

 

any help would be greatly appreciated,

thanks,

John

0 Likes
Accepted solutions (2)
1,142 Views
8 Replies
Replies (8)
Message 2 of 9

GeorgK
Advisor
Advisor

In the ini file when I set "USE TRANSMITTAL=No", it outputs as a dxf. But when i set to "USE TRANSMITTAL=Yes" , it creates a zip file.

 

https://forums.autodesk.com/t5/inventor-customization/export-pack-and-go-dxf-with-ilogic/td-p/711859...

0 Likes
Message 3 of 9

marcin_otręba
Advisor
Advisor

use:

 

 oDwgOptions.Value("Pack_and_Go") = False

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 4 of 9

johnster100
Collaborator
Collaborator

i still get the same result 😞

0 Likes
Message 5 of 9

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@johnster100,

 

There is no option to mention "USE TRANSMITTAL" in DWG translator addin. This value is edited in .ini file which can be used to mention configuration settings for translation. So, edited .ini file is zipped and attached with this post and mention the downloaded path in the below VBA code. It translates .idw file into .dwg file without zip file.

 

Public Sub PublishDWG()
    ' Get the DWG translator Add-In.
    Dim DWGAddIn As TranslatorAddIn
    Set DWGAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")

    'Set a reference to the active document (the document to be published).
    Dim oDocument As Document
    Set oDocument = ThisApplication.ActiveDocument

    Dim oContext As TranslationContext
    Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = kFileBrowseIOMechanism

    ' Create a NameValueMap object
    Dim oOptions As NameValueMap
    Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap

    ' Create a DataMedium object
    Dim oDataMedium As DataMedium
    Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

    ' Check whether the translator has 'SaveCopyAs' options
    If DWGAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then

        Dim strIniFile As String
        strIniFile = "Downloaded path\exportdwg.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 = "c:\tempdwgout.dwg"

    'Publish document.
    Call DWGAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 6 of 9

Anonymous
Not applicable
Accepted solution

this used to frustrate the life out of me. 

when the code created a zip file, I had to 'manually' go through the process of creating a dwg then cancelling out at the last moment, not sure why it worked, but it fixed it every time.

 

so, hit save copy as, hit options, hit next, hit cancel and then hit cancel again... then run your code and it'll work...no idea why, but this does work...

 

to fix the code, I check the output directory for a zip file, if it finds one, then unzip it and delete all zip files from the folder. if it doesn't find one, it does nothing because a dwg exists...

 

I know it doesn't directly fix the issue, but it does work..

 

add this to the top of your code

 

 

Imports System.IO
AddReference "System.IO.Compression"
AddReference "System.IO.Compression.FileSystem"

then after the export to dwg/dxf has taken place, add the following

 

'Set the ZIP target file name
unzipfile1 = fname & oFileName & _
" Rev " & iProperties.Value("Project", "Revision Number") & " " & iProperties.Value("Project", "Description") & " (UNCONTROLLED COPY)" & ".zip"

'Check if file exported was a zip
If System.IO.File.Exists(unzipfile1)

'extract zip file
System.IO.Compression.ZipFile.ExtractToDirectory(unzipfile1, fname)


'Delete zip file if it exists
If System.IO.File.Exists(unzipfile1)
   System.IO.File.Delete(unzipfile1)

End If
End If

 

you will need to modify the line below to find your zip file (the above is a straight copy out of my code...if you are struggling thoguh, post our code up if you'd like to add the unzip workaround...

 

unzipfile1 = fname & oFileName & _ " Rev " & iProperties.Value("Project", "Revision Number") & " " & iProperties.Value("Project", "Description") & " (UNCONTROLLED COPY)" & ".zip"

 

 

0 Likes
Message 7 of 9

marcin_otręba
Advisor
Advisor

For me it  works :

Public Sub PublishDWG()
    ' Get the DWG translator Add-In.
    Dim DWGAddIn As TranslatorAddIn
    Set DWGAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")

    'Set a reference to the active document (the document to be published).
    Dim oDocument As Document
    Set oDocument = ThisApplication.ActiveDocument

    Dim oContext As TranslationContext
    Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = kFileBrowseIOMechanism

    ' Create a NameValueMap object
    Dim oOptions As NameValueMap
    Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap
     oOptions.Value("USE TRANSMITTAL") = no
    ' Create a DataMedium object
    Dim oDataMedium As DataMedium
    Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

    ' Check whether the translator has 'SaveCopyAs' options
  

    'Set the destination file name
    oDataMedium.FileName = Replace(oDocument.FullFileName, "idw", "dwg")

    'Publish document.
    Call DWGAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 8 of 9

marcin_otręba
Advisor
Advisor

oh , sorry it doesn't work.. i didint noticed that i have ini file.

But if you run once export manualy and unselect pack&Go option it will start to work as should without ziping.

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 9 of 9

johnster100
Collaborator
Collaborator

thanks for that.

 

I think i'll try using an ini file that sits next to the .exe and make this part of the installation.

 

thanks,

John

0 Likes