Using Python to set values and trigger cooking?

   9957   5   0
User Avatar
Member
196 posts
Joined: Aug. 2011
Offline
Hi!

Is the following example possible?

given network, example:
sphere connected to file out node, saving the sphere out as a file.
now, using python to loop n times, each time changing the radius and the output file name, then cooking the network every time to get the n different files on disk.
(yes, this could be done with a for loop SOP, but I'd like to use python code to do the loop, not a SOP)


the idea is to drive the network's values and specifically force recooking, not like in the python SOP to just do something within one node..

possible?

any input welcome!
User Avatar
Member
2631 posts
Joined: June 2008
Offline
You can place a force cook in the Pre-Frame event of the ROP output driver where you are writing the file to disk. This will cause the python node to be evaluated before the file is written to disk. Do python work to change your geo then let the ROP write that to disk. The filename for the output will be the frame number. Or you can place another force cook to another python node in the Post-Render event and run code to rename the file on a per-frame basis.
hou.node('/obj/my_python_node').cook(force=True)

Here is a link [forums.odforce.net] to a thread where the python script re-writes the OBJ output to include additional information after the ROP has already written the file.
Edited by Enivob - Dec. 16, 2016 16:30:57
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
196 posts
Joined: Aug. 2011
Offline
Hi,

Thanks for the input.

I have never used a ROP to export files. I'm not familiar with the idea behind this.

The only method to export files so far was via file SOP with the setting ‘write’. but I also never export animated data, I just create variations of geometries with different values.

What's the main advantage of using a ROP to export files?
User Avatar
Member
196 posts
Joined: Aug. 2011
Offline
on an other notice.

I need to send these assets later on to maya, with intact normals and material assignments (I don't care about the material values, just which material name is connected to which faces).

which file format is best used for this ?

in the end, for my workflow, I need obj files, but Houdini does not export mtl and normals for obj files. bummer.
User Avatar
Member
2631 posts
Joined: June 2008
Offline
The File SOP has a Scripts TAB as well, so you can still force cooks via code if you want. The Output ROP is an older method for the same task. I actually believe the File SOP uses a Output ROP if you dive inside and take a look.

If you are going to Maya just use the Alembic file format. (.abc)

The OBJ format does support Normals and Material names just make sure you have the Normals properly applied to the geometry prior to export. You may have to promote/demote normals between point and primitive.

Natively Houdini does not export the OBJ materials correctly, but the script at the above link addresses this issue by writing a usemtl tag into the file each time it detects a group. This causes other apps to detect the material group on import.
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
196 posts
Joined: Aug. 2011
Offline
thanks a lot for your inputs. I will look into the details.

btw. I just had the idea that houdini engine for maya may be even more elegant to port procedurally created geometries.

thanks again!
matt
  • Quick Links