How can I pass the wb namespace from a main wb journal file to a submodule?
Rohith Patchigolla
Member, Moderator, Employee Posts: 193
✭✭✭✭
in Structures
If I create a wbjn file which accesses other python files, I am able to import modules like os, sys etc. but the commands like GetProjectDirectory() are no longer accesible to me, within this module.
How do I get acces to the functions and methods of workbench from sublevel python scripts?
Tagged:
0
Best Answer
-
Here are the steps to achive this.
- Create a function called Initialize in the .py file which is being imported as shown below. This takes global name space as an input coming from the main wbjn file.
def Initialize(gb): print(gb["GetProjectDirectory"].__call__())
- Try passing globals() to the module after import as shown below in the main wbjn file as shown below.
import mypythonmodule as pymod pymod.Initialize(globals())
In this way we can get access to functions and methods also in the sublevel python scripts.
Some more discussion can be found in the below thread.
https://discuss.ansys.com/discussion/2172/how-to-create-and-use-python-modules-files-in-mechanical2