3 Replies Latest reply on Mar 13, 2015 3:54 PM by Attilio Colangelo

    how to select defined loads?

    Frantisek Menda

      Hi all,

      I have manually defined different external loads in simulation static study. I want to write a script that will do several studies, always with different external load. Can I select somehow by API previously defined external loads?

        • Re: how to select defined loads?
          Attilio Colangelo

          This is a sample for programmatically getting an existing pressure load and changing it's value.  Note that the "pressureLoad" is Dim'd as CWPressure and any load you are trying to retrieve needs to Dim'd accordingly.

           

          Dim ActDoc                  As CosmosWorksLib.CWModelDoc

          Dim COSMOSWORKS             As Object

          Dim CWObject                As CosmosWorksLib.CWAddinCallBack

          Dim pressureLoad            As CosmosWorksLib.CWPressure

          Dim LBCMgr                  As CosmosWorksLib.CWLoadsAndRestraintsManager

          Dim swModel                 As SldWorks.ModelDoc2

          Dim StudyMngr               As CosmosWorksLib.CWStudyManager

          Dim Study                   As CosmosWorksLib.CWStudy

          Dim errCode                 As Long

           

          Sub main()

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc         'Should be a partdoc object

          Set CWObject = swApp.GetAddInObject("SldWorks.Simulation") 'This works for Solidworks Simulation 2015

          Set COSMOSWORKS = CWObject.COSMOSWORKS

          Set ActDoc = COSMOSWORKS.ActiveDoc()

          Set StudyMngr = ActDoc.StudyManager()

          Set Study = StudyMngr.GetStudy(0) 'Zero based index of the number of studies in the model

          Set LBCMgr = Study.LoadsAndRestraintsManager

          Set pressureLoad = LBCMgr.GetLoadsAndRestraints(1, errCode) 'This is a zero based index. Pressure is

                                                                      'the second load or restraint

              pressureLoad.PressureBeginEdit

              pressureLoad.Value = 200

              pressureLoad.PressureEndEdit

          End Sub