Page 1 of 1

User Defined functions in makehuman

PostPosted: Fri Sep 28, 2018 6:14 am
by Shreyansh_Dubey
How can i use Python 2.7 functions which are user defined in Makehuman shell as well as in scripts?

I want to create some functions involving loops and they would include some Python 2.7 predefined functions as well as some Makehuman mhapi functions, that I can call directly in makehuman scripting. Where should i save any such function so that it is accesible in script as well as in Makehuman shell.
Please guide me.


Re: User Defined functions in makehuman

PostPosted: Fri Sep 28, 2018 9:05 am
by joepal
I'd say the most efficient way would be writing a new plugin, which extends MHAPI on load.

In a file called for example "" placed under "plugins":

Code: Select all
# -*- coding: utf-8 -*-

from core import G

# The reason for the folloring arcane snippet is that python
# refuses to import from modules with a name that starts
# with a number.

mhapimodule = __import__("1_mhapi")

    attrlist = mhapimodule.__all__
except AttributeError:
    attrlist = dir (mhapimodule)
for attr in attrlist:
    globals()[attr] = getattr (mhapimodule, attr)

# Extending Namespace is stricly speaking not necessary, but it's the structure
# that the rest of MHAPI follows. In __init__ we'll also make a convenience assignment
# so you can access the whole of MHAPI via "self.mhapi" in all the methods.

class MyUserFunctions(namespace.NameSpace):

    def __init__(self,api):
        self.mhapi = api

    def oneOfMyFunctions(self):
        print("I'm alive!")

def load(app): = MyUserFunctions(

def unload(app):

Now, after startup, you can call this like any other MHAPI module. For example in the shell tab:

Code: Select all
from core import G

... will respond by printing "I'm alive"

Re: User Defined functions in makehuman

PostPosted: Mon Oct 01, 2018 7:18 am
by Shreyansh_Dubey
Thankyou :P :geek: