EXPORT IDW TO DWG USING DWG ADDIN

EXPORT IDW TO DWG USING DWG ADDIN

BWMcDowell
Enthusiast Enthusiast
1,181 Views
4 Replies
Message 1 of 5

EXPORT IDW TO DWG USING DWG ADDIN

BWMcDowell
Enthusiast
Enthusiast

I am using Inventor 2015 run as administrator and I keep getting the error:

Error in rule: DWG EXPORT, in document: 99999.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.ApplicationAddIns.get_ItemById(String ClientId)

at LmiRuleScript.Main()

at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)

at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

this is the code:

    ' Get the DWG translator Add-In.
    Dim DWGAddIn As TranslatorAddIn
    DWGAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3?AC2-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 = 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
    Dim strIniFile As String
    'strIniFile = "O:\Templates\INVENTOR\EXPORT TEMPLATES\" & iProperties.Value("CUSTOM", "INI FILE")
    strinifile = "O:\TEMPLATES\INVENTOR\EXPORT TEMPLATES\6=1-0EXPORT.INI"
    ' Create the name-value that specifies the ini file to use.
    oOptions.Value("Export_Acad_IniFile") = strIniFile
    

    'oDataMedium.FileName = iProperties.Value("CUSTOM", "DWG PATH") & iProperties.Value("CUSTOM", "DWGNO") & ".DWG"
    oDataMedium.FileName = "O:\TEMPORARY.DWG"

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

  Any help will be appreciated

 

0 Likes
Accepted solutions (1)
1,182 Views
4 Replies
Replies (4)
Message 2 of 5

Owner2229
Advisor
Advisor

Hi, to save assembly as DWG you can use simply "Save As":

Dim FN As String = "O:\TEMPORARY.DWG"
ThisDoc.Document.SaveAs(FN , True)

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 3 of 5

BWMcDowell
Enthusiast
Enthusiast

Will that use whatever ini file I specify because I have 30 different ini files that will need to be used

0 Likes
Message 4 of 5

Owner2229
Advisor
Advisor
Accepted solution

Ah, I see now, this should do it:

 

' Set a reference to the DWG translator add-in. 
Dim oDWGAddIn As TranslatorAddIn 
Dim i As Long 
For i = 1 To ThisApplication.ApplicationAddIns.count 
    If ThisApplication.ApplicationAddIns.Item(i). _ 
    ClassIdString = _ 
    "{C24E3AC2-122E-11D5-8E91-0010B541CD80}" Then 
        oDWGAddIn = ThisApplication. _ 
                  ApplicationAddIns.Item(i) 
        Exit For 
    End If 
Next 
    
' Check to make sure the add-in is activated. 
If Not oDWGAddIn.Activated Then 
    oDWGAddIn.Activate 
End If 
    
' Create a name-value map to supply information to the translator. 
Dim oNameValueMap As NameValueMap = ThisApplication. _ 
    TransientObjects.CreateNameValueMap 

Dim strIniFile As String = "O:\Templates\Inventor\Export templates\DWGExport.ini"

' Create the name-value that specifies the ini file to use. 
Call oNameValueMap.Add _ 
    ("Export_Acad_IniFile", strIniFile) 

' Create a translation context and define 
' that we want to output to a file. 
Dim oContext As TranslationContext = ThisApplication.TransientObjects. _ 
    CreateTranslationContext 
oContext.Type = kFileBrowseIOMechanism 
    
     
' Define the type of output by specifying the filename. 
Dim oOutputFile As DataMedium = ThisApplication. _ 
    TransientObjects.CreateDataMedium 
oOutputFile.FileName = "O:\TEMPOMARY.DWG" 
    
   
    
' Call the SaveCopyAs method of the add-in. 
Call oDWGAddIn.SaveCopyAs _ 
    (ThisApplication.ActiveDocument, _ 
          oContext, _ 
          oNameValueMap, _ 
          oOutputFile) 

 

But the INI file muss be in the refered place or the rule will crash.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 5 of 5

BWMcDowell
Enthusiast
Enthusiast

Changed my code out for your and changed out variabbles and found I had a type in a variable.

Thanks

0 Likes