2 Replies Latest reply on Nov 21, 2013 9:25 AM by David Moak

    Quick question about API in C# for conversions...

    David Moak

      I've got SolidWorks.Interop.sldworks and 'using SolidWorks.Interop.Sldworks;' in my project... I can open .slddrw files with opendoc6 too.... (and startup SW--using ver 20.5.0 a.k.a. sw2012)


      I need to do a file save/conversion... from looking at the macro-recorder's output... I need to use Part.SaveAs3(outputfile,0,0)...


      what I have in C# looks like this:

      Type swType = Type.GetTypeFromProgID("SldWorks.Application");

      ISldWorks app = (ISldWorks)Activator.CreateInstance(swType);


                  if (app != null)


                      app.Visible = true;

                      app.OpenDoc6(sourceFile, 3, 0, "", ref openErrors, ref openWarnings);

                      saveStatus = app.ActiveDoc.Part.SaveAs3(destinationFile, 0, 0);

                      closeSuccessful = app.CloseAllDocuments(true);



      The variable sourceFile is a full path to the file... and I've tried destinationFile as just a filename and as a full path&filename....  anyway.. here's the problem:


      I can get SW started up and the file opens... butI get this exception thrown when executing the app.ActiveDoc.Part.SaveAs3 method:

      System.Runtime.InteropServices.COMException was unhandled

        Message=Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))




      Am I using the right call for this task?