Purpose:
- Save open Drawing file as PDF (complete)
- Show user list of "open" referenced documents (complete)
- Have user select from list on userform (complete)
- Switch to (or create) model window of selected document.
- Save Selected document as eDrawing (complete)
So the only Open file or Document window I have open is my drawing. I have tried using the swApp.OpenDoc6 call as shown in the numerous Open file macros on the forum. However I get the following error:
swFileLoadError_e Enumeration
| swFileWithSameTitleAlreadyOpen | 65536 or 0x10000 = A document with the same name is already open |
When I call swFrame.GetModelWindowCount I am informed that I only have 1 model window active.
So my question is this: How do I get a new model window for a file that is referenced by an open document?
Thanks in advance for all your head scratching.

Excerpt from the API help on OpenDoc6:
Yup Moderation cause my question to lag over the weekend. I did get it resolved... I'm just honestly not sure what it was that I did that fixed it....
Sorry, Arthur, not sure if you have the issue resolved. I believe due to moderation it all got messed up. Please let me know if you have any outstanding issues.
So... After messing with the code extensively.... I can't get it to break anymore, and I'm not sure what it was that I did to fix it.
I took the code from the CodeStack Macro and overwrote a bunch of my failing to fix it code. I can't figure out what it is that is different than what I had though.
Working macro attached.
Bring document foreground (activate document) using SOLIDWORKS API
Found this Macro on Codestack, going to see if going through it will help me get this figured out.
Asked a question of Artem but it's waiting in moderator limbo
Thanks how would I change the code so that I could give it a file name instead of a View.ReferencedDoc?
Ok, so it works, right? I believe you might have opened the drawing in lightweight mode so it took some time to load an assembly. You should have similar performance when doing manual activation as well. If you restart SW (as it is not cached in memory and will be instant).
So , I downloaded the code, ran it line by line till it got to: swDoc.Visible = True then Sw froze for 7 minutes.
edit: While typing this message SW finally loaded the assembly.
Try attached macro on your model. Does it work?
& , if the following part of code makes no sense that's cause it's me messing around trying to figure out what to do.
Attached module & settings text.
Can you please attach/share the SWP file?
So I have discovered where my code fails more closely. (Calls within userform "trimmed down" for clarity)
the next if statement is where the problem arises. If the previous Set swModel = swApp.GetOpenDocumentByName(ChosenDoc) is a "Nothing" it enters this if logic that keeps failing.
Problem area:
If I try this with OpenDoc6 I get the fileerror as:
I tried with IActivateDoc3 but I can't seem to get the arguments set up correctly to use it.
When I use ActivateDoc3 I get a "With variable not set up".
ChosenDon is filled by this code:
Since Deepak asked for all the code... Here is the monstrosity.
The part I'm having a problem with will be isolated in my reply to this.
Main module:
Form1: FrmDrwChk
Form2:Frm_eDraw_file_choose
Form3:Frm_FoldersOpen
The "Publish-Settings.txt" is formatted as this:
Hi,
OpenDoc6 should open the referenced model. The issue you are facing might be because the drawing file and the referenced model have the same name. It is always advised to use the complete file path name (Path Name + File Name + Extension) in OpenDoc6 file name parameter so that all discrepancies are automatically (and logically) cleared by SW.
Hope it helps!!!
Rajat Jain
I presume your reference is invisible. Try to set the IModelDoc2::Visible property of this document to True before calling the ActivateDoc API.
Below are the codes I had been using with no errors. So what error you are getting? Share your completed macro to debug.
I have tried using IActivateDoc3 as well but keep getting errors as well.