hou.pwd() in .py script

   5860   6   0
User Avatar
Member
326 posts
Joined: May 2007
Offline
i created a python HDA, i can use “hou.pwd()” to find current node.
now i want import one module from .py to this HDA. how can i do the same thing(hou.pwd()) in .py file to find curent HDA node?

wish you know what i said.
https://vimeo.com/user3971456/videos [vimeo.com]
User Avatar
Member
1926 posts
Joined: Nov. 2006
Offline
The best solution is for the module you are importing to have functions that have a hou.Node argument so you can just pass the node you already have.
import mymodule

node = hou.pwd()
mymodule.foo(node)
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
326 posts
Joined: May 2007
Offline
thank you for your quick reply graham, that's a good idea.
but there is another problem
in my .py file:
import hou
def foo(a):
print a.name()
in hda is:
node = hou.pwd()
import test
def bar():
test.foo(node)
it only print a “/” not the real node name, except i reedit operator properties. what's wrong with me?
https://vimeo.com/user3971456/videos [vimeo.com]
User Avatar
Member
1926 posts
Joined: Nov. 2006
Offline
By in your hda what do you mean exactly? I was under the impression you were talking about calling the code from the Cook section of a Python operator, but it seems like this is a happening in a PythonModule that is being called somehow? More clarification as to exactly where from and how you are calling your code would be appreciated.
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
326 posts
Joined: May 2007
Offline
graham
By in your hda what do you mean exactly? I was under the impression you were talking about calling the code from the Cook section of a Python operator, but it seems like this is a happening in a PythonModule that is being called somehow? More clarification as to exactly where from and how you are calling your code would be appreciated.

sorry
1, i create one “test.py” in HFS/houdini/python2.6libs with this
import hou
def foo(a):
print a.name()
2, in houdini i create a new operator type named “pytest”.
3, in “pytest” i create one button parameter with this Callback Script
kwargs.hdaModule().bar()
4, in “pytest” scripts tab i create a PythonModule with
node = hou.pwd()
import test
def bar():
test.foo(node)

when i restart my houdini then click pytest's button i assume it will print like “pytest1” but it print “/” only
maybe this is not the right way, i just need run my .py script in houdini by one button click.
https://vimeo.com/user3971456/videos [vimeo.com]
User Avatar
Member
1926 posts
Joined: Nov. 2006
Offline
This is to be expected. You are initializing ‘node’ in the PythonModule which has no relation to any actual instance of the node. Because of this, ‘hou.pwd()’ is going to evaluate to the root node ‘/’. Now you could move your ‘node = hou.pwd()’ call to be inside your definition of bar() but using hou.pwd() inside the PythonModule is bad form. You should always pass the node or kwargs to any of your functions that rely on an instance of the asset.
hou.phm().bar(hou.pwd())
# or
kwargs.hdaModule().bar(kwargs)
# or
hou.pwd().hdaModule().bar(kwargs)
# etc…
and then have your function accept whatever you pass it:
import test

def bar(node):
test.foo(node)

# or

def bar(kwargs):
node = kwargs
test.foo(node)
# or
test.foo(kwargs)

For more information about how hou.pwd() works check out this post: http://forums.odforce.net/index.php?/topic/15210-python-checking-if-the-content-of-a-network-changed/page__view__findpost__p__93995 [forums.odforce.net]
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
326 posts
Joined: May 2007
Offline
thank you very very much graham, you should go sleep earlier
https://vimeo.com/user3971456/videos [vimeo.com]
  • Quick Links