5) Running Inventor programatically

Top  Previous  Next

Inventor has to be running  before you can get at objects inside it. ConnectToInventor will try to run Inventor if it is not already running.

 

On some computers  starting Inventor can take several seconds.

 

This is what actually starts Inventor:

 

   hRes = CoCreateInstance (InvAppClsid, NULL, CLSCTX_LOCAL_SERVER, __uuidof(IUnknown), (void **) &pInvAppUnk);

   if (FAILED (hRes)){

       pInvApp = nullptr ;

       ShowCOMError (hRes,L"ConnectToInventor,CoCreateInstance failed") ;

       return false;

   }

 

If you are not familiar with COM have a quick read of this explanation of the FAILED macro, and other HRESULT codes and macros.

 

The function ReturnAndShowCOMError is used to give you more information about any failure, and to return the fail code. More here.

 

6) Creating a part document and a sketch

 

 

 

 

Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)