AnsweredAssumed Answered

Transient time step and temp set up

Question asked by Kyle Thomson on Jun 29, 2020

Hi all, 

     I am working on a transient study thermal VBA code. I have managed to get my code to switch from steady state to transient. however, I cannot get it to allow me to set a time step, total time, or to call in initial temperatures from a previous study. I will list my code below. Thanks for any assistance.

 


Set motionStudyMgr = Part.Extension.GetMotionStudyManager()
Set ActiveDocObj = COSMOSWORKSObj.ActiveDoc()
Set StudyManagerObj = ActiveDocObj.StudyManager()
StudyManagerObj.ActiveStudy = 0
'sets study name
NewStudyName = "Thermal 3"
Set CWNewStudy = StudyManagerObj.CreateNewStudy3(NewStudyName, 3, 0, ErrorCodeObj)

 

Set StudyObj = StudyManagerObj.GetStudy(0)
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
Set ActiveDocObj = COSMOSWORKSObj.ActiveDoc()
Set StudyManagerObj = ActiveDocObj.StudyManager()
StudyManagerObj.ActiveStudy = 1

Set ThermalOptionsObj = StudyObj.ThermalStudyOptions()
ThermalOptionsObj.SolverType = 3
'ThermalOptionsObj.ThermalSolution = 0
ThermalOptionsObj.SolutionType = swsThermalSolutionType_e.swsThermalSolutionTypeTransient

 

 

 

 

               Two potential solution I found but cant get to work

                  'Option 1 
                     ' Total_Time = 100
                       ' Time_Step = 5
                        ' Step_Count = Total_Time / Time_Step

 

                  'Option 2 from solidworks
                        ' ThermalOptions.TotalTime = 3600
                          ' ThermalOptions.TimeIncrement = 600

 

 

 

'*************************************Calling in old data to define the thermal study*****************
'https://help.solidworks.com/2020/english/api/swsimulationapi/SolidWorks.Interop.cosworks~SolidWorks.Interop.cosworks.ICWThermalStudyOptions~UseTemperatureFromThermalStudy.html
'Dim instance As ICWThermalStudyOptions
'Dim value As System.Integer
'
'instance.UseTemperatureFromThermalStudy = value
'
'value = instance.UseTemperatureFromThermalStudy


''Says that the previous study was called thermal 1 for initializing initial conditions
'ThermalOptionsObj.ThermalStudyNameUsedForInitialTemperature = "Thermal 1"
'1 = Use initial temperature from the thermal study
'0 = Do not use initial temperature from the thermal study
'*****************************************************************************************************

Outcomes