Cosmos Works CreateNewStudy Problems

Hi all,

When I call CreateNewStudy or CreateNewStudy2 from CosmosWorks add-in, it should return an object of type Study, problem is, it returns null(C#) or Nothing(VB.NET,VBA). This seems like a bug. As a workaround, I have to check the Study return object and if null, call GetStudy passing the Active Study number. I could have also enumerated the Studies and look for the one I just added by name, but I don't like to do that. Has anyone else seen this behavior?

Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports Cosmos = SolidWorks.Interop.cosworks
Imports System
Imports System.Diagnostics

Partial Class SolidWorksMacro
  Public swApp As SldWorks

  Sub main()
    Dim CosAddin As Cosmos.CwAddincallback = CType(swApp.GetAddInObject("CosmosWorks.CosmosWorks"), _

                                                   Cosmos.CwAddincallback)
    Dim CosWorks As Cosmos.CosmosWorks = CosAddin.CosmosWorks
    Dim ActDoc As Cosmos.CWModelDoc = CosWorks.ActiveDoc
    Dim StudyMan As Cosmos.CWStudyManager = ActDoc.StudyManager
    Dim errRes As Integer

    'The following assignment fails, but Study is created and errRes returns 0

    Dim Study As Cosmos.CWStudy = StudyMan.CreateNewStudy2("NewStudy1", 3, errRes)

    'This is the workaround to get a reference to the Study

    If Study Is Nothing Then Study = StudyMan.GetStudy(StudyMan.ActiveStudy)

    Debug.Print("New Study Added:  " & Study.Name)

  End Sub
End Class

Also, the Primary Interop Assembly for Cosmos doesn't appear to be in the GAC, I have had to reference it from the API folder.

Clif

SolidworksApi macros