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?
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
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.Value = 200
Thank you! It is working. It changes the value but the label in the manager doesn´t change. Rebuild model doesn´t help here, I need to open load manager and after I close it, tha label also changes.
Yes, I plan on bringing this issue to Solidworks API support. The label doesn't change real time which is a nuisance.
Retrieving data ...