Python concatenation

   2419   6   0
User Avatar
Member
55 posts
Joined: Oct. 2018
Offline
Hi, I´m learning python and there is something I don´t know how to do.

I´m creating this two variables:

char = hou.node('/obj/Char_Rig_01')
R_clavicle_bone = hou.node('/obj/Char_Rig_01/R_clavicle_bone')


But I want in the second variable to use the data from the first variable, something like this
R_clavicle_bone = hou.node('char/R_clavicle_bone')

The first node is subnetwork and the second is a bone inside the subnet. Please help with this ...
User Avatar
Member
899 posts
Joined: Feb. 2016
Offline
Hello, do you want to concatenate the paths to the nodes?

When you use the char variable between the "", python wouldn't read it as variable, instead it would return just the word "char" and not the object.
Also char is a node object in your case, and concatenating it with a string type doesn't really make sense.

I guess you want to use char.path() to return the path to the char node in string format.
You could do something like this:
#first build your path
path = char.path() + '/R_clavicle_bone'
#then ask for the node object
R_clavicle_bone = hou.node(path)
Edited by Andr - Oct. 8, 2021 07:47:31
User Avatar
Member
9384 posts
Joined: July 2007
Offline
You can also do
char = hou.node('/obj/Char_Rig_01')
R_clavicle_bone = char.node('R_clavicle_bone')
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
55 posts
Joined: Oct. 2018
Offline
Andr you are right, that will give me a string (I´m still learning the difference), so this doesn´t work to set parameters later. tamte´s solution is what I needed, thanks!
User Avatar
Member
55 posts
Joined: Oct. 2018
Offline
Hi ... so I´m back with another issue.

This works for what I need to work with the bones inside the "Char_Rig_01"
char = hou.node('/obj/Char_Rig_01')

And now I need to add a line where it presses a button, this work
hou.parm('obj/Char_Rig_01/Geo/capture_cache1/stashinput').pressButton()

But of course, I want to use the char variable I set at the beginning ... but this doesn´t work
hou.parm(char'/Geo/capture_cache1/stashinput').pressButton()

So, how can I concatenate the "char" variable + '/Geo/capture_cache1/stashinput' ?
User Avatar
Member
9384 posts
Joined: July 2007
Offline
Angel Fucaraccio
But of course, I want to use the char variable I set at the beginning ... but this doesn´t work
hou.parm(char'/Geo/capture_cache1/stashinput').pressButton()
you can use the same logic as before
char.parm("Geo/capture_cache1/stashinput").pressButton()

alternatively (not preferred) just for reference how to recreate full parameter path:
hou.parm(char.path() + '/Geo/capture_cache1/stashinput').pressButton()
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
55 posts
Joined: Oct. 2018
Offline
Thanks a lot. I still can´t figure this things by myself.
  • Quick Links