AnsweredAssumed Answered

OpenDoc6 only works after manual file open

Question asked by Peter Brinkhuis on Feb 27, 2017
Latest reply on Nov 2, 2017 by Peter Brinkhuis

Hi guys,

 

I'm getting my hands dirty with C# add-ins and I'm running into the most basic stuff. I'm trying to open a drawing from a part file. This is the code that does the work, I've removed the checks and most try catch blocks for clarity.The strange thing is that the code usually goes into the catch block, unless I've opened and closed the drawing file in this current SolidWorks session. If I've opened it before, it just works. There is a FileNotFoundException and the error variable remains at zero. Any idea what could be going wrong here?

 

  SldWorks swApp;

  ModelDoc2 swModel;

  DrawingDoc drawing;

  int errors = 0;

  int warnings = 0;

 

  // Get currently running SW app

 

  swApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application");

  swModel = (ModelDoc2)swApp.ActiveDoc;

 

  // Create drawing path

  drawingLocation = Path.ChangeExtension(swModel.GetPathName(),"slddrw");

 

  try

  {

     swModel = swApp.OpenDoc6(drawingLocation, (int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);

  }

  catch

  {

  MessageBox.Show($"Open didn't work, error = {errors}");

  return;

  }

Outcomes