Importing custom python modules for Hypermesh 2024

I am writing a python script that attempts to import custom python modulus that I wrote. When I run my main python script that imports these modules from within Hypermesh 2024, I get an error "ModuleNotFoundError: No module named 'module_name_here'". Do I have to place my custom module into hypermesh's python module file library? Any tips would be greatly appreciated.
Answers
-
Hi,
What kind of modules are you creating? It´s not a recommended practice to implement your own functions in the installation folder. Maybe, just creating some functions or classes could be a better solution.
Arthur
0 -
I am creating modules that are located in separate python files for modularity. I could in theory implement everything in one file, but I would prefer to call on separate python files. One workaround I found was modifying the system path to search for custom directories that I would manually input.
Do you know how to retrieve the filepath of a python script that the user would load in?
For example in Hypermesh 2025, if they click Load→Python Script→ Select Python file, how would I retrieve the path directory of that original file location. Is there a tcl command or python api command I can call?
Thanks
0 -
Got it,
Yes, you can call the script directory, add these commands lines:
import os
scriptDir = os.path.abspath(os.path.dirname(__file__))
modelFile = os.path.join(scriptDir,'..','folder1','folder2','modelfile.fem') resultFile = os.path.join(scriptDir,'..','folder1','folder2','resultfile.h3d')I hope this can help.
Arthur
0