🎉Community Raffle - Win $25

An exclusive raffle opportunity for active members like you! Complete your profile, answer questions and get your first accepted badge to enter the raffle.
Join and Win

Importing custom python modules for Hypermesh 2024

User: "ActuallyAbe"
Altair Community Member

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.

Find more posts tagged with

Sort by:
1 - 3 of 31
    User: "almeidaaap"
    Altair Employee

    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

    User: "ActuallyAbe"
    Altair Community Member
    OP

    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

    User: "almeidaaap"
    Altair Employee

    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