write idw to dxf using translator addin with c#

write idw to dxf using translator addin with c#

KarlR.J.Wehr
Enthusiast Enthusiast
1,633 Views
7 Replies
Message 1 of 8

write idw to dxf using translator addin with c#

KarlR.J.Wehr
Enthusiast
Enthusiast

Hi,

 

I'm trying to export an idw file to dwg using c# and the dwg translator addin. running the code below there is a COMException (E_UNEXPECTED) while executing dwgAddIn.SaveCopyAs.

Similar code works fine with the pdf translator and it also works fine translated to VBA and runnig as a macro within Invetor.

I will apreciate any idea...

 

Here's the code:

 

publicstaticvoid SaveAsDwg(Inventor.Application InvApp, Inventor.DocumentInvDoc)

{

Inventor.TranslatorAddIn dwgAddIn =

(Inventor.TranslatorAddIn)InvApp.ApplicationAddIns.get_ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}");

 

if (dwgAddIn == null)

thrownewException("Could not access DWG translator.");

 

Inventor.TranslationContexttranslationContext = InvApp.TransientObjects.CreateTranslationContext();

translationContext.Type = Inventor.IOMechanismEnum.kFileBrowseIOMechanism;

Inventor.NameValueMapoptions = InvApp.TransientObjects.CreateNameValueMap();

 

if(dwgAddIn.get_HasSaveCopyAsOptions(InvDoc, translationContext, options))

{

options.set_Value("Export_Acad_IniFile", @"c:\temp\dwg.ini");

Inventor.DataMediumdataMedium = InvApp.TransientObjects.CreateDataMedium();

dataMedium.FileName =@"C:\temp\test2.dwg";

dwgAddIn.SaveCopyAs(InvDoc, translationContext, options, dataMedium);

}

 

}

 

 

Karl

0 Likes
1,634 Views
7 Replies
Replies (7)
Message 2 of 8

jeffrey.sun
Alumni
Alumni

I executed the code in C# project. It works on my machine. I think the problem is the parameters or the inventor application. Which inventor build are you using? Do you log on windows with an administrator account?

 

I have some suggestions to diagnose the issues.

1. Verify the ini file "c:\temp\dwg.ini" exists. And the paramter InvDoc is not null at the runtime.

2. If different inventor builds are installed, please verify the correct inventor.exe is started in the code. Set the breakpoint at the entry of function SaveAsDwg. Then you can get the chance to check the process property of inventor.exe in the Windows Task Manager. Verify the expected "Location" (In the Inventor.exe Properties | General tab) is the exact inventor you want to start.

 

 

 

 


Please mark this response as "Accept as Solution" if it answers your question.
-----------------------------------------------------------------------------------------



Jeffrey Sun
SW Engineer
Manufacturing Industry Group
Autodesk, Inc.

0 Likes
Message 3 of 8

KarlR.J.Wehr
Enthusiast
Enthusiast

Hi Jeffrey,

 

many thanks for your replay.

Unfortunately I still can't get it to run. I tested with Inventor 2012 on two workstations and additionally with inventor 2011 SP2.

 

The ini file "c:\temp\dwg.ini" exists and works while using it with manual export (or with vba code within a macro). InvDoc is set to a document at runtime. The correct inventor.exe is used – I’m getting the application with

(Inventor.Application)System.Runtime.InteropServices.Marshal.GetActiveObject(progId)

 

I’m using Windows 7 x64. Could that be an issue?

 

Karl

0 Likes
Message 4 of 8

jeffrey.sun
Alumni
Alumni

Hello Karl,

    What is the message of the exception?

    Do you log on windows with an administrator account? If not, please run the execution built by the c# project in Administrator mode.

 

 

 


Please mark this response as "Accept as Solution" if it answers your question.
-----------------------------------------------------------------------------------------



Jeffrey Sun
SW Engineer
Manufacturing Industry Group
Autodesk, Inc.

0 Likes
Message 5 of 8

KarlR.J.Wehr
Enthusiast
Enthusiast

Hello Jeffrey,

 

both inventor and visual studio are running 'as administrator'. I also turned off the user acount control, so not sufficient right shouldn't be the cause.

 

This is the error (in german):

 

System.Runtime.InteropServices.COMException wurde nicht behandelt.
  Message="Schwerwiegender Fehler (Ausnahme von HRESULT: 0x8000FFFF (E_UNEXPECTED))"
  Source="mscorlib"
  ErrorCode=-2147418113
  StackTrace:
       bei System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
       bei Inventor.TranslatorAddIn.SaveCopyAs(Object SourceObject, TranslationContext Context, NameValueMap Options, DataMedium TargetData)
       bei WindowsFormsApplication2.test.SaveAsDwg(Application InvApp, Document InvDoc) in H:\entwickl\entegra\temp\WindowsFormsApplication2\test.cs:Zeile 51.
       bei WindowsFormsApplication2.test.run() in H:\entwickl\entegra\temp\WindowsFormsApplication2\test.cs:Zeile 27.
       bei WindowsFormsApplication2.Program.Main() in h:\entwickl\entegra\temp\windowsformsapplication2\Program.cs:Zeile 19.
       bei System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       bei System.Threading.ThreadHelper.ThreadStart()
  InnerException:

0 Likes
Message 6 of 8

jeffrey.sun
Alumni
Alumni

Hello Carl,

    Could you upload your c# project and the related ini and idw files? I'll have a try with your porject to see if it can reproduce on my machine.


Please mark this response as "Accept as Solution" if it answers your question.
-----------------------------------------------------------------------------------------



Jeffrey Sun
SW Engineer
Manufacturing Industry Group
Autodesk, Inc.

0 Likes
Message 7 of 8

KarlR.J.Wehr
Enthusiast
Enthusiast

Hello Jeffrey,

 

many thanks for your efforts.

 

I finally found out the reason. I opened the inventor document with the option visible = false. Opening the file that way you can export to pdf but you can't to AutoCAD (dwg or dxf). Opening the file with visible = true solves the problem.

 

kind regards

Karl

0 Likes
Message 8 of 8

jeffrey.sun
Alumni
Alumni

Hi Carl,

 

I can reproduce your issue if open the drawing document in the invisible mode. Originally, I set this option with true. That's the reason why it works on my machine. Thanks for your reply.


Please mark this response as "Accept as Solution" if it answers your question.
-----------------------------------------------------------------------------------------



Jeffrey Sun
SW Engineer
Manufacturing Industry Group
Autodesk, Inc.

0 Likes