Slight shelf/python problem.

   1259   4   1
User Avatar
Member
96 posts
Joined: Nov. 2017
Offline
My script is called tm_addRig.py

The script is in the $HSITE dir folder ……/scripts/python/tm_rigging. In the tm_rigging folder is an empty __init__.py file + all my rigging scripts.

My shelf tool has the following lines of code added to the scripts section:

from tm_rigging import tm_addRig

a) If my script doesn't contain a def (as if it would be in the shelf tool itself) it executes.

b) If my script is inside a def tm_addRig(): “wrapper” and the last line of code is

tm_addRig()

it executes.

c) If my script is inside a def tm_addRig(): “wrapper” and I alter the shelf tool script to:

from tm_rigging import tm_addRig

tm_addRig()

it doesn't execute.

How do I need to call the script that it does execute?

tm_rigging.tm_addRig doesn't work either (name tm_rigging is not defined)

If I neither can call it by tm_addRig nor tm_rigging.tm_addRig, how then???

Cheers

Tom
User Avatar
Member
96 posts
Joined: Nov. 2017
Offline
Strange.

import tm_rigging

tm_rigging.tm_addRig()

doesn't work either.

(Module not callable)
User Avatar
Member
96 posts
Joined: Nov. 2017
Offline
O.k., The error message made me understand that the python script, though it just contains the one def is a module, and not the script itself. Logical mistake since file and script are called the same.

tm_addRig.tm_addRig() did the job, BUT this kind of naming convention or better calling convention is hell, if scripts exists only once by their name.

If you call “Peter!” because you just know this Peter, you shouldn't be surprised if a few million Peters follow your call and appear. So GreatBritain.London.EssexStreet.FirstFloor.Peter will likely be more precise, but if you have the ability to name all Persons on this planet and you just name one of them Peter, Peter is precise.

Would I need to alter the __init__.py file so that I'm able to just use tm_addRig() to call the script or which would be the proper way to handle this?

Keep you updated in case I find out about a solution before someday else probably does. : )
User Avatar
Member
96 posts
Joined: Nov. 2017
Offline
As I said, I'd keep you informed about the “progess” (cough, cough).

I altered the __init__.py.

Now it's in the form of

from tm_addRig import tm_addRig

and not empty anymore.

In this case the first appearance is the file name (module), the second is the def name.

If the shelf tool is altered to:

import tm_rigging

reload(tm_rigging)

tm_rigging.tm_addRig()

it works.
Edited by Tom Mangold - April 27, 2020 10:56:36
User Avatar
Member
96 posts
Joined: Nov. 2017
Offline
While this works I still can't call the script by it's very own def name.

from tm_rigging import tm_addRig()

tm_addRig()

on the shelf will finally work BUT it lacks the reload so far.

This seems to be a bit more complicated. So inbetween the lines of code above I add three lines, giving me that:

from tm_rigging import tm_addRig()

import sys
reload(sys.modules['tm_rigging'])     
from tm_rigging import tm_addRig()

tm_addRig()

Well, if there's a more elegant way, I might stumple across it sometime. At least it seems to work now for me.

PYthon is such a great way to push Houdini soooo much further, but the syntax hell is something which needs to be endured…
Edited by Tom Mangold - April 27, 2020 10:55:25
  • Quick Links