AnsweredAssumed Answered

Get active document from silent open file

Question asked by Ioan Bordei on Jan 31, 2018
Latest reply on Jan 31, 2018 by Jacob Corder


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


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



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:




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!