I am writing a Python script that runs outside Houdini.
It reads camera data from another app and hopefully transforms it into something that a Houdini camera can understand.
My question is this. Once I got my camera data, how can I pass it on to the Houdini camera?
For example, among many other camera parameters, I have this file with x,y,z position data as a dictionary, like so:
Px = {frame:position_x}
Py = {frame:position_y}
Pz = {frame:position_z}
Do I need to create a geometry operator, object operator? Or a different way altogether? Override existing camera? Create a new camera via python? Read into CHOPs?
Python: data from File to node
5735 7 1-
- Soothsayer
- Member
- 875 posts
- Joined: Oct. 2008
- Offline
-
- graham
- Member
- 1926 posts
- Joined: Nov. 2006
- Offline
If you are operating outside of Houdini it is possible to import the hou module from a regular Python shell. You can use this method to then create/load a scene, create your camera and apply the position data as keyframes to the camera parameters.
You could also user repr() on your data structures to output them to a file that you can then read and eval back into Houdini and apply them as well.
You could also user repr() on your data structures to output them to a file that you can then read and eval back into Houdini and apply them as well.
Graham Thompson, Technical Artist @ Rockstar Games
-
- koen
- Member
- 798 posts
- Joined: April 2020
- Offline
I a similar situation, I created a new camera object hda. In the python module of the script section of the you can stick all the pyhton code you want. I ended up putting a null in the network to do some calculations, create dummy attributes on the null that I set from the script, and then link the camera transforms etc to those attributes.
However, it sounds like in this case. you could consider putting all the python you need directly onto the camera parameters you would like to drive. I have found that to be a bit more reliable in updating, although the other way is working flawlessly now as well.
Hope that helps.
Koen
However, it sounds like in this case. you could consider putting all the python you need directly onto the camera parameters you would like to drive. I have found that to be a bit more reliable in updating, although the other way is working flawlessly now as well.
Hope that helps.
Koen
-
- Soothsayer
- Member
- 875 posts
- Joined: Oct. 2008
- Offline
Hey thanks for the quick response.
So, if I understand correctly: the best thing to do is to right-click the camera node, select Type Properties, and enter my code in there?
edit: No wait…that didnt work…I misunderstood something
edit2: Koen, I tried your first method. It seems to work. I'd like to put them directly onto the camera parameters but haven't managed to find out how yet.
So, if I understand correctly: the best thing to do is to right-click the camera node, select Type Properties, and enter my code in there?
edit: No wait…that didnt work…I misunderstood something
edit2: Koen, I tried your first method. It seems to work. I'd like to put them directly onto the camera parameters but haven't managed to find out how yet.
--
Jobless
Jobless
-
- koen
- Member
- 798 posts
- Joined: April 2020
- Offline
To add python code directly to the paramters, set the expression language for the node to python (the big “H” icon on top of the parameter pane). Go to the parameter you would like to edit, press “alt-e” to bring up the code editor and start coding :-)
for expressions / scripts that are longer than 1 line, you have to return the value, for example
a = 10
b = 15
return a*b
you can use the same code you have in the script section of your otl, or you can simplify it a bit because in the parameters “hou” is always imported.
Hope that helps.
Koen
for expressions / scripts that are longer than 1 line, you have to return the value, for example
a = 10
b = 15
return a*b
you can use the same code you have in the script section of your otl, or you can simplify it a bit because in the parameters “hou” is always imported.
Hope that helps.
Koen
-
- Soothsayer
- Member
- 875 posts
- Joined: Oct. 2008
- Offline
-
- Soothsayer
- Member
- 875 posts
- Joined: Oct. 2008
- Offline
How about this idea:
Can I run a Python script from a menu?
I could write my converter and run it from somewhere like File>MyConverter. It then converts and saves the data which I can then read into the parameters, or perhaps even via chops.
Would that be possible? (I don't see any such option in the “New Operator Type” )
Can I run a Python script from a menu?
I could write my converter and run it from somewhere like File>MyConverter. It then converts and saves the data which I can then read into the parameters, or perhaps even via chops.
Would that be possible? (I don't see any such option in the “New Operator Type” )
--
Jobless
Jobless
-
- koen
- Member
- 798 posts
- Joined: April 2020
- Offline
-
- Quick Links

