Can I get "SldWorks" from "ModelDoc2" or another function?
If you in VBA macro just use Application.SldWorks from anywhere in the code. If you are using .NET application, get the process id of current process and use Running Object Table to get the pointer to ISldWorks.
That doesn't seem likely. It's supposed to work the other way around, but you already know that.
Are you in a function that only has a ModelDoc2 object as a parameter? And you need a SldWorks object to get what, the selection manager?
When I see questions like these, I've learned that you are usually building functions that do more than one thing. Function should do only one thing and functions should be very short. When you start writing function of 1 to max 10 lines, you'll see that your code becomes so much cleaner and so much more understandable.
HI Peter, Thanks for your suggest.
I can't imagine how you got a ModelDoc2 without having a SldWorks already...
Some time ,I have to input "sldworks" and ''Modeldoc2" in a function at the same time.
for example:the "modeldoc2" is not ActiveDoc。Simultaneously，I need use "sldworks:getmathutility" to operate some entity which in this "modeldoc2".
if I can get "sldworks" through other ways，I just need input ''Modeldoc2" only.
Of course, this is not necessary, it just for the convenience of my function.
Hi Artem, thank you very much.
It it successful use the follow code(C#):
SldWorks newSwApp = (SldWorks)System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application");
I have actually asked SOLIDWORKS API support to add support for a method that would be the answer to your question. A lot of PDM API objects have a field for the vault object. Why not the same for the SOLIDWORKS API? This makes methods extending ModelDoc2, that would otherwise require a pointer to SldWorks, more concise and performant.
Retrieving data ...