python in HDAs

   3701   5   1
User Avatar
Member
36 posts
Joined: Feb. 2009
Offline
Hey,

I'm writing some python for my HDA and have a very basic Q…

How do I get access to a parameter that's on the HDA itself?

say I have a HDA called “myHDA” which
lives at:
“obj”

if I put this code into the HDA python module:

def printHDA():
HDAName = hou.node(“..”)
print HDAName

and then connect this to a button.
It prints:
“obj”

shouldn't it be?:
“obj/myHDA”

I'm just trying to change a parameter on the HDA so I'll
need the code to be aware of what the HDA is called (in case its name changes)

I also tried:
def printHDA():
nodeN = hou.pwd()
nodeNFullPath = “obj/%s” % nodeN
HDAName = hou.node(nodeNFullPath)
print HDAName

this prints “None”…?
The next step would be adjust the parameter. But I can't get it to recognize the HDA.

I'm must be missing something really basic.

Thanks
Pav
User Avatar
Member
792 posts
Joined: April 2020
Offline
Hello Pav,

In both cases you where close.

In side your hda, you can use:

thisNode = hou.node(“.”)

this will return the current node.

The pwd() way works as well, it just does not return a node name but a node.

so
n = hou.pwd()
print n.name()

also works.

To get to the parameters, you can use the parm function on a node:

p = n.parm(“parmName”)
value = p.eval()

Hope that helps.

Cheers,
Koen
User Avatar
Member
36 posts
Joined: Feb. 2009
Offline
even simpler example…

if you have a HDA called myHDA in “/obj”

in the python shell:

myHDA = hou.node(“obj/myHDA”)
print myHDA
#results in: myHDA

myHDA
#results in: <hou.ObjNode of type myHDAOTL at /obj/myHDA>

in the HDA python module of myHDA:

def printMyHDA():
myHDA = hou.node(“obj/myHDA”)
print myHDA

#will print “None”

:cry:
User Avatar
Member
36 posts
Joined: Feb. 2009
Offline
oh I see, yeah that worked…
Thanks koen!

Do you know why using the absolute path doesn't work?

Cheers
Pav
User Avatar
Member
7868 posts
Joined: July 2005
Offline
Because you gave it a relative path instead of an absolute path? I think you're missing the slash in front of obj. ie. you want:

myHDA = hou.node("/obj/myHDA")
User Avatar
Member
36 posts
Joined: Feb. 2009
Offline
oh I see.
Thanks.
  • Quick Links