Hey guys,
Im just wondering why the shelf tools dont recognise that I have imported my python module using the pythonrc.py at start up.
I can run what ever i want in the expression fields, in the shell with out having to import my module but as soon as I place it into the shelf it states its not defined?
I shouldnt have to import my module in the tool if its been imported by using pythonrc.py right?
Cheers
Nick
bug? pythonrc.py and shelf tools
12642 7 0- niko3d
- Member
- 338 posts
- Joined: Sept. 2006
- Offline
- graham
- Member
- 1906 posts
- Joined: Nov. 2006
- Offline
I'm pretty sure the shelf tools are just self contained python scripts, thus they don't use the pythonrc file. It works both ways in that if you click on the Box tool, it imports soptoolutils and runs the generic tool from there, but afterwards if you try and access soptoolutils from the shell, it is not imported. You would have to import your pythonrc file in the tool code to access features from it.
Graham Thompson, Technical Artist @ Rockstar Games
- niko3d
- Member
- 338 posts
- Joined: Sept. 2006
- Offline
- graham
- Member
- 1906 posts
- Joined: Nov. 2006
- Offline
Importing from the shelf should work exactly the same as importing from the shell. The pythonrc file is a little different I believe. When Houdini starts, it executes the script, where as if you want to use it in a shelf tool you have to import it and treat it as a module.
I have my pythonrc.py file at $HOME/houdini9.1/scripts/python/pythonrc.py
pythonrc:
testvar = 5
Shelf tool:
import pythonrc
print pythonrc.testvar
Pressing the tool prints ‘5’ as expected
I have my pythonrc.py file at $HOME/houdini9.1/scripts/python/pythonrc.py
pythonrc:
testvar = 5
Shelf tool:
import pythonrc
print pythonrc.testvar
Pressing the tool prints ‘5’ as expected
Graham Thompson, Technical Artist @ Rockstar Games
- niko3d
- Member
- 338 posts
- Joined: Sept. 2006
- Offline
Abit of a user error on my side there i think. Tho it does still seems alittle long winded to have to import your modules, or importing the pythonrc.py when they are imported automatically when houdini starts.
especailly if your having to do
import pythonrc
pythonrc.blahblah.myfunction(pythonrc.hoha.monkey(01,02))
thanks for clearing that up tho much appreciated.
I cant quite see the advantage of the tools not having access to the imported modules through pythonrc.py
It a shame and caught me off guard abit too.
Cheers
Nick
especailly if your having to do
import pythonrc
pythonrc.blahblah.myfunction(pythonrc.hoha.monkey(01,02))
thanks for clearing that up tho much appreciated.
I cant quite see the advantage of the tools not having access to the imported modules through pythonrc.py
It a shame and caught me off guard abit too.
Cheers
Nick
- mtucker
- Staff
- 4438 posts
- Joined: July 2005
- Online
I think there are good reasons for having shelf tools run in a separate “context” from the Python Shell context. Similarly python expressions in nodes are in a third context. This helps avoid polluting namespaces, and having your shelf tools stomp on the variables and methods used by your rendering scripts. There may be other reasons for the separation, but this is what makes sense to me.
But I also think what you say makes sense, and I'm not sure why the shelf and expression contexts don't _also_ automatically source in the pythonrc scripts. You'd still have three separate contexts (so you couldn't share information between them through the pythonrc module) but each context would have access to any methods or modules in pythonrc. I'll submit this as an RFE.
Another option is to use the hou.session module, which is accessible and shared between all three contexts (if you need that functionality). You can also use this as a workaround to your current problem by having pythonrc modify hou.session instead of defining symbols/functions in its own namespace. So pythonrc could have:
hou.session.a = 5
instead of
a = 5
Then you can access “hou.session.a” in the python shell, shelf tools, or expressions. Not quite as convenient as just “a”, but at least it works right now.
Mark
But I also think what you say makes sense, and I'm not sure why the shelf and expression contexts don't _also_ automatically source in the pythonrc scripts. You'd still have three separate contexts (so you couldn't share information between them through the pythonrc module) but each context would have access to any methods or modules in pythonrc. I'll submit this as an RFE.
Another option is to use the hou.session module, which is accessible and shared between all three contexts (if you need that functionality). You can also use this as a workaround to your current problem by having pythonrc modify hou.session instead of defining symbols/functions in its own namespace. So pythonrc could have:
hou.session.a = 5
instead of
a = 5
Then you can access “hou.session.a” in the python shell, shelf tools, or expressions. Not quite as convenient as just “a”, but at least it works right now.
Mark
- niko3d
- Member
- 338 posts
- Joined: Sept. 2006
- Offline
Cool, thanks for the tip on the houdini sessions Mark. I do agree they should have there seperate contexts and can see why that is. Keeping them seperate but still having access to the pythonrc imports sounds like what I expected from the shelf. Hopefully a RFE will get this sorted at some point :¬)
Cheers
Nick
Cheers
Nick
- lucas
- Staff
- 270 posts
- Joined: July 2005
- Offline
Note that one of the benefits of pythonrc.py is that you can be sure it's automatically run exactly once (unlike 123.py, 456.py, etc.) So, I'm quite hesitant about running it from shelf tools automatically.
However, you should be able to run it explicitly from your shelf tool with: execfile(“pythonrc.py”).
If you're just using pythonrc.py to import modules, I'd recommend importing them manually into your shelf script. If pythonrc.py sets global variables, though, you can import __main__ from your shelf script and use it to access them.
However, you should be able to run it explicitly from your shelf tool with: execfile(“pythonrc.py”).
If you're just using pythonrc.py to import modules, I'd recommend importing them manually into your shelf script. If pythonrc.py sets global variables, though, you can import __main__ from your shelf script and use it to access them.
-
- Quick Links