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?
<p>Imports SolidWorks.Interop.sldworks<br>Imports SolidWorks.Interop.swconst<br>Imports Cosmos = SolidWorks.Interop.cosworks<br>Imports System<br>Imports System.Diagnostics<br><br>Partial Class SolidWorksMacro<br> Public swApp As SldWorks<br><br> Sub main()<br> Dim CosAddin As Cosmos.CwAddincallback = CType(swApp.GetAddInObject("CosmosWorks.CosmosWorks"), _</p><p> Cosmos.CwAddincallback)<br> Dim CosWorks As Cosmos.CosmosWorks = CosAddin.CosmosWorks<br> Dim ActDoc As Cosmos.CWModelDoc = CosWorks.ActiveDoc<br> Dim StudyMan As Cosmos.CWStudyManager = ActDoc.StudyManager<br> Dim errRes As Integer</p><p></p><p> 'The following assignment fails, but Study is created and errRes returns 0</p> Dim Study As Cosmos.CWStudy = StudyMan.CreateNewStudy2("NewStudy1", 3, errRes)<br><br> 'This is the workaround to get a reference to the Study<br><p> If Study Is Nothing Then Study = StudyMan.GetStudy(StudyMan.ActiveStudy)</p><p> Debug.Print("New Study Added: " & Study.Name)</p><p> End Sub<br>End Class<br></p>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