How to get a Workbench system name inside a Python Code object while Mechanical is in batch mode?

I am trying to get the Workbench block name using the following command in a python code object in Mechanical.
While my_block_name = Model.Analyses[0].SystemCaption
works when Mechanical UI is running, it fails in batch mode when running the analysis from Workbench.
Is there a Workaround?
Best Answer
-
The .SystemCaption property does not have a value in batch mode because it is used for the Mechanical UI Window title. Since there is no Mechanical UI in batch mode, this parameter is never initialised.
Building on Landon's post, you can use the wbjn module to pass Workbench commands from your Mechanical Script. This way, you can access the block name, even though the Mechanical UI will not be open.
Here's an example script:
import wbjn WB_cmds = ''' system1 = GetAllSystems()[0] my_block_name = system1.DisplayText returnValue(my_block_name) ''' block_name = wbjn.ExecuteCommand(ExtAPI,WB_cmds)
0
Answers
-
Building up further on this topic, you can use the
.format
routine to inject variables in the commands sent to Workbench.
For example, if you are looking for the name of a specific system (let's say its ID is stored in acurrent_sys
variable), you can use the following alternative to search for this system ID in Workbench and retrieve the corresponding block name.import wbjn WB_cmds = """ all_wb_sys = GetAllSystems() for wb_sys in all_wb_sys: if wb_sys.UserId == '{0}': target_system = wb_sys my_block_name = target_system.DisplayText returnValue(my_block_name) """.format(current_sys) block_name = wbjn.ExecuteCommand(ExtAPI,WB_cmds)
0