7 Replies Latest reply on Feb 6, 2015 4:24 PM by Matthew Stokes

    Cosmos Modify Restraint BUG

    Matthew Stokes

      Here is a link to the exact section of the [API][1]. I'm really starting to believe this is a bug and I don't have a license type which allows me to file bugs apparently (?)


      I just want to modify an existing restraint.

      I'm able to load the COSMOS addin, load the part, load a pre-existing non linear study so I know this is done correctly.


            // E.g I'm able to change the study duration

            CComPtr<ICWNonLinearStudyOptions> non_linear_study_options;

            CComPtr<ICWStudy> study;   





      I now simply want access to a ICWRestraint but can't seem to get this. I go through the LoadsAndRestraintsManager to get a LoadsAndRestraints. Using this I'm able to call the functions get_Name and get_Type which return the proper name and type for the restraint so I know this is correct, but calling  get_EntityCount returns a count of 0 and GetEntityAt returns NULL.


           CComPtr<ICWStudy> study;

           CComPtr<ICWLoadsAndRestraintsManager> restraints_manager;

           CComPtr<ICWLoadsAndRestraints> restraint;




            long error = 0;

            long num = 0;

            restraints_manager->get_Count(&num);  // num == 4 (4 restraints in my FEA study)

            restraints_manager->GetLoadsAndRestraints(1, &error, &restraint);  // gets the second restraint entry (reference geometry)

            BSTR name =L"";

            restraint->get_Name(&name);  // name == foo

            restraint->get_Type(&num); // type == 2 (restraint)

            restraint->get_EntityCount(&num);  // num == 0


            long sel = swSelSIMELEMENT;

            struct IDispatch *restraint_dispatch;

            restraint->GetEntityAt(0, &sel, &restraint_dispatch);  // restraint_dispatch == NULL


      I just want to modify/have access to an existing restraint. Any help would be greatly appreciated.


      [1]: http://help.solidworks.com/2011/english/api/swsimulationapi/SolidWorks.Interop.cosworks~SolidWorks.Interop.cosworks.ICWLoadsAndRestraints.html

        • Re: Cosmos Modify Restraint BUG
          Attilio Colangelo

          I am currently working on a VBA macro with pressure loads (type 1).  The EntityCount is working.  I tried poking holes in it (changing entities in the dialog box, etc) but it's holding up (SW2015 SP1.1).  I don't know C++ but I imagine the call should behave the same.  What version of SW are you using?

          • Re: Cosmos Modify Restraint BUG
            Matthew Stokes

            As I keep diving deeper down the rabbit hole I believe I have uncovered two issues in the C++ implementation for the GetLoadsAndRestraints function in the LoadsAndRestraintsManager interface.


            1) The suppression state in the documentation is incorrect and/or inconsistent. The two states listed are:



                  swsSupressionStateSuppressed 0 = Suppressed


                  swsSupressionStateUnsuppressed  1 = Unsuppressed


            However a return value of 0 (suppressed) corresponds to the unsuppressed state, and a return value of 1 (unsuppressed) corresponds to the unsuppressed state. I can see this by not silently opening the part, and toggling the suppression state. E.g.



                  restraint->get_State(&state);  // 0 (shows unsuppressed in the study manager GUI)



                  restraint->get_State(&state);  // 1 (shows suppressed in the study manager GUI)


            2) Summarizing from above, a call to get_EntityCount on LoadsAndRestriants returns 0 while calls to get_Name and get_Type return the appropriate name and type. Calling GetEntityAt will then returns NULL since there are no entities. So my guess then is that the call to GetLoadsAndRestraints from the LoadsAndRestraintsManager perhaps does not bind correctly.


            The other tricky part I notice and this seems like a bit of a void in the API, is the GetEntityAt function itself. The documentation doesn't outline what second parameter (swSelectType_e) corresponds to selecting Restraints. I'm guessing its a swSelSIMELEMENT? This function then returns a dispatch pointer which I would also now need to Query for the uuid of a Restraint?


            I should have access to a ICWRestraint from the ICWLoadsAndRestraints but can't seem to bridge this gap. Currently I am unable to modify a pre-existing restraint. When creating a new restraint I then get access to an ICWRestraint, but I don't want to go down the route of adding/deleting restraints rather than simply modifying.