Search - User list
Full Version: HDA hou.pwd() problem
Root » Technical Discussion » HDA hou.pwd() problem
danilo2
Hi!

I've got 2 HDAs made by me.
I don't understeand why when I write in one of them
import hou

print hou.pwd()

oon the beginning of HDA Python Module then it pronts ITS NAME.

In the second HDA the same code prints “/”. Could somebody tell me if I'm making something wrong, or this is a bug?

Thnak you
graham
Using hou.pwd() from inside an assets PythonModule is not advised. The PythonModule is just that, a module, that is associated with an asset definition, not an instance of that definition. When you call hou.pwd() inside that module there is no certainty in knowing what it will return as it is returning the current working directory of Houdini in general, which might not be an instance of your asset. If you are calling into a function in the PythonModule from a parameter callback, then for the code executed in that callback, hou.pwd() will return an instance of that asset. Unless you are changing around things normallly running hou.pwd() in the shell will result in it returning a reference to the scene root, “/”. Calling hou.pwd() from a parameter returns the instance of the node that parameter belongs to because that is the currently evaluating node in the scene. After it does its thing it returns to the root. This is why you are getting different results.

So depending on your situation you can get away with calling hou.pwd() in an asset module, but personally I will never do it just in case things can happen or you might want to call a function outside of your actual instance. I would recommend not using hou.pwd() in any part of your PythonModule and instead require all functions to take a node argument.
danilo2
Thank you very much graham!
I will not do it never I promise ;]

Please tell me - is there any method to write on the beginning of HDA (not in body of a function) something like:
this = ….
and this “this” keyword will show always instance of this HDA?

I was using hou.pwd() to do exactly this thing:
this = hou.pwd()

def foo():
print this

thank you
graham
There isn't. It's a module, not really different then the sys, os, math, etc modules. Just a place to run code. Calling hou.pwd().hadModule().foo() is equivalent to calling math.foo() for example. The code is just assosiated with a node type so that node type can always have the code it needs. This is also useful because you can call functions in an assets module externally and without caring about that asset.

That's why a “this” pointer wouldn't really work. In Houdini an assets PythonModule is evaluated when the asset is loaded into Houdini, so there most likely isn't even an instance of that asset. Also, the module belongs to the definition, not the asset so there's no direct link to a particular node.

To do what you want you'd need to pass in a node instance.

def foo(node):
print node

And then from a callback or somewhere else do
node = hou.pwd() # or something else (hou.node(“/obj/myasset”) node.hdaModule().foo(node)
danilo2
Thank you very much!
I didn't know that hda is so simmilar to module!

I simply wanted to avoid to pass always “this” parameter as function param but as I see I cannot ;]

Thank you once again
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB