eDrawings viewer automation in C++ hangs on OpenDoc

Hi,

With below in C++ it creates the object ok and can get the eDrawings version fine from within the code, but as soon as it tries to opens the edrw file nothing happens at all - just stops without any errors.  any ideas?

#include "emodelview.h"   // this is created from a class type library import from the EModelView.dll

void CTestedrwDlg::OnButton1()

{

  CoInitialize(NULL);

  IEModelViewControl e;

  // Get the IDispatch pointer and attach it to the objWord object.

  if (!e.CreateDispatch("EModelView.EModelViewControl"))

  {

  AfxMessageBox("Couldn't get object");

  return;

  }

  CString v = e.GetVersion();

  AfxMessageBox(v);

  try

  {

  e.OpenDoc(_T("c:\\\\test.edrw"), false, false, false, _T(""));

  AfxMessageBox("open ok");

  e.Print5(false, _T("test"), false, false, true, 1, 0, 0, 0, true, 0, 0, _T(""));

  AfxMessageBox("print ok");

  }

  catch(...)

  {

  AfxMessageBox("error");

  }

}

SolidworksApi macros
Answers 3
ST
ST 2015-05-28 Best Answer

I don't know about C++, but in .Net you have to register for the OnFinishedLoadingDocument event.

Maybe that is related?

SF
SF 2015-05-29

hmmm, didn't work for me.   i'm a novice with c#, how are you registering/capturing the event in c# ?

ST
ST 2015-05-29

I usually use VB.Net. In there you just have to create a function that Handles yourcontrol.OnFinishedLoadingDocument

But in C++ I think you actually have to do something to subscribe to that event.

I'm not sure it will solve the problem you are describing, but you definitely need to do it, because you shouldn't do anything else until that function is called.