RSS

SolidWorks API: Loading/getting Simulation (CosmosWorks) object, failure?

25 Jul

As the SolidWorks 2009 Simulation API help states, the typical use of Cosmos Works begins by creating an instance of the ICosmosWorks class:

private object iCosWorks = null;
iCosWorks = (ICosmosWorks) SwApp.GetAddInObject(“CosmosWorks.CosmosWorks”);

However if you try the code above, you will find that the iCosWorks object is always null .

Where does the string (“CosmosWorks.CosmosWorks”) come from, and how is it named? It is not very clear in the documentation: The help manual tells us that the signature of this function is:

virtual object GetAddInObject(
   string clsid          
)
"This method also accepts the ProgID, both version independent and version dependent, for clsid."
So I wonder, the ProgID has updated in the new 2009 API, while the documentation falls behind and remain intact. What lazy engineers! It costs me much time...

So I tried to get the string by myself. In SolidWorks 2009, the Simulation DLL is ‘cosworks.dll’,

  • Search the registry with this dll as the keyword
  • The ProgID as well as VerionIndependentProgID can be found.

Now, retry the following code:

iCosWorks = (ICosmosWorks) SwApp.GetAddInObject(“SldWorks.Simulation.2“); or
iCosWorks = (ICosmosWorks) SwApp.GetAddInObject(“SldWorks.Simulation“);
Debug.Assert(iCosWorks != null);

It works now!

Advertisements
 
5 Comments

Posted by on July 25, 2009 in CAD, Dotnet/C#

 

Tags: , , , , , , ,

5 responses to “SolidWorks API: Loading/getting Simulation (CosmosWorks) object, failure?

  1. villli

    September 3, 2009 at 8:09 am

    Hallo, i see you are wery god.

    I have the problem like you are repairing with this.
    But i am not a programmer(absolutely do not understand what it is “iCosWorks = (ICosmosWorks) SwApp.GetAddInObject(”SldWorks.Simulation.2“); or
    iCosWorks = (ICosmosWorks) SwApp.GetAddInObject(”SldWorks.Simulation“);
    Debug.Assert(iCosWorks != null);” and what to do.

    😦 pleeeeeeease could you make a tutorial how to do it for an program lama?

    Thank you villli

     
  2. xinyustudio

    September 3, 2009 at 10:11 am

    The above code seems self-explanatory, so what is your problem?

     
  3. villli

    September 3, 2009 at 3:05 pm

    🙂 my problem is that i would like use it but I do not know how…

     
  4. xinyustudio

    September 4, 2009 at 9:18 am

    Just use the above code will do, if you cannot understand it, you can have a look at SolidWorks API help, there are many examples. Hope it helps.

     
  5. xinyustudio

    January 22, 2010 at 12:01 pm

    Also make sure Simulation addin is automatically loaded on solidworks startup. Otherwise
    iCosWorks = (ICosmosWorks) SwApp.GetAddInObject(“SldWorks.Simulation.2“); or
    iCosWorks = (ICosmosWorks) SwApp.GetAddInObject(“SldWorks.Simulation“);
    Debug.Assert(iCosWorks != null);

    will always cause assertion fails.

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: