Using Workbench Mechanical scripting how can I get information from the project page? How can I make changes to the project page?
The answer is to utilize the wbjn module, whose source code can be found in the ACT installation directory (e.g. C:\Program Files\ANSYS Inc\v232\Addins\ACT\libraries\Mechanical). In theory, you can run project page commands from Mechanical like this:
WB_cmds = '''My Workbench commands here'''
However, the above snippet is pretty useless so far, because:
A ) It does not allow us to return any information to Mechanical
B ) If the Workbench commands modified project in any way, Mechanical and/or Workbench would crash. This is due to a threading issue.
To retrieve information from the Project Page and return it to Mechanical, we use the returnValue function. Here is a common example:
WB_cmds = '''
my_directory = GetUserFilesDirectory()
UserDirectory = wbjn.ExecuteCommand(ExtAPI,WB_cmds)
If we want to make modifications to the Project Page, we need to interact with the Project Page on a separate thread from Mechanical. Here is an example to change the name of a system in the Project Page from within Mechanical:
from System.Threading import *
thread = System.Threading.Thread(System.Threading.ThreadStart(Internal_RunWBJN))
project_cmds = '''
system1 = GetAllSystems()
system1.DisplayText = "my name"
Here are some other examples:https://discuss.ansys.com/discussion/2477/in-wb-mechanical-scripting-how-can-i-change-the-transformation-angles-of-an-external-data-filehttps://discuss.ansys.com/discussion/2476/in-workbench-mechanical-scripting-how-can-i-get-the-location-of-an-external-data-file/p1?new=1