Workbench script (SendCommand: send python script) does not work

Options
Ansys hardworker
Ansys hardworker Member Posts: 3

Hello!

I am running the wbjn script from workbench. The rest runs well, but it appears that ‘post_script.py’ is not being imported to the model, as ‘post_script.py’ is not executed. So, I think it’s probably a problem with ‘Model_exp.SendCommand’. Can I ask for advice on the cause?

encoding: utf-8

2021 R2

SetScriptVersion(Version="21.2.209")

sys_exp = GetSystem(Name="SYS")
sys_imp = GetSystem(Name="SYS 1")

CleanSystem(Systems=[sys_exp])
CleanSystem(Systems=[sys_imp])

designPoint1 = Parameters.GetDesignPoint(Name="0")
designPoint1.SetParameterExpression(Parameter=Parameters.GetParameter(Name="P10"),Expression="10 [degree]")
designPoint1.SetParameterExpression(Parameter=Parameters.GetParameter(Name="P11"),Expression="10 [mm]")

Model_exp = sys_exp.GetContainer(ComponentName="Model")
Model_exp.Edit(Hidden=False)

Update() # Solving

script = open("post_script.py", "r")
cmd = script.read()
script.close()

Model_exp.SendCommand(Language="Python", Command=cmd)

Comments

  • Rajesh Meena
    Rajesh Meena Moderator, Employee Posts: 67
    First Anniversary Solution Developer Community of Practice Member Ansys Employee 5 Likes
    Options

    @Ansys hardworker The commands looks okay. In such case, I normally write back script to a text file using cmd string. This allows me to see if there are any issue while Coverting file content to string. Hope that helps.