9 Replies Latest reply on Feb 1, 2018 1:22 PM by Ioan Bordei

    Get active document from silent open file

    Ioan Bordei

      Hello!

      From an external app (.exe file) i try to open some files silently using the following code:

      HRESULT hr = S_OK;

      CComPtr<IModelDoc2> iSwModel;

      hr=iSwApp->DocumentVisible(VARIANT_FALSE,swDocPART);//if this line is commented the code runs perfectly but SolidWorks window will be visible when the file is open

      hr=iSwApp->put_UserControl(VARIANT_FALSE);

      hr=iSwApp->put_UserControlBackground(VARIANT_TRUE);

      iSwApp->OpenDoc6(L"D:\\myPart.SLDPRT",swDocPART, swOpenDocOptions_Silent, L"Default", &lErrors, &lWarnings,&iSwModel);

       

      If I commented the DocumentVisible () line above, the iSwModel data returned from OpenDoc6() is valid but the SolidWorks window is not completely hidden and for the short period of time - when the file is opening - it is visible and only after the loading process is finished it will close itself. If the line is not commented, and the code execute as above, the iSwModel data is not valid - it is different than in the previous case (it is not NULL but it is different)

       

      The valid data expected in the main program, after the code above, must be something like:

       

      iSwApp->get_IActiveDoc2(&iSwModel);

       

      so the program needs to have access to the active document obtain from OpenDoc6() function but it seems that DocumentVisible() modify it in such way that OpenDoc6 () returns a document which it is not the active document.

       

      What I'm missing here? What is wrong? It could be a workaround to open a file in background and access it as an active document even it is not visible in that way no SolidWorks window display on the screen? I try also OpenDoc7() and the result was the same..

      Any idea is much appreciated!

      Ioan