Python Script problems

   2256   7   1
User Avatar
Member
9 posts
Joined: Sept. 2016
Offline
So the situation is like this. I have a selection of files that I need to process with SOP network, then open that geometry in python and write out a json file per work item. It all works fine except for that python script. Python script for some reason doesnt update PDG attributes that I use in SOP network to load a correct file per work item. All my json files a exactly the same size, so it looks like that python script updates only the first active work item attributes and the rest of the items get exactly the same set of attributes, because all resulting JSON files are the same size and comes from the very last work item I have manually checked. I tried everything and I have no idea how to fix this. All my PDG attributes are correct as well.
User Avatar
Staff
585 posts
Joined: May 2014
Offline
Can you attach a simple example .hip file that demonstrates what you're trying to do?
User Avatar
Member
9 posts
Joined: Sept. 2016
Offline
There you go. Hope you can figure something out.

Attachments:
PDG_Python.zip (27.1 KB)

User Avatar
Member
9 posts
Joined: Sept. 2016
Offline
Check the resulting JSON files - they all the same. And they shouldn't be.
User Avatar
Member
603 posts
Joined: Sept. 2016
Offline
The problem is that pythonscript1 is being evaluated in-process. This means all the items are working in your current houdini session, so /obj/topnet/PrepareGeometry/file1 is evaluating `@pdg_input` to whatever your current selected item is. This is why all the json files are the same.

If you want to modify the geometry you can use an Invoke TOP node. With an Invoke you would need to put your attribwrangle into a Compiled Block.

Then you should use another Geometry Import to bring the attributes you want back into PDG where you can safely use a pythonscript to write out a text file or whatever.
User Avatar
Member
9 posts
Joined: Sept. 2016
Offline
Is it possible to use pythonscript not in-process somehow? It always gives me errors that way.
User Avatar
Staff
585 posts
Joined: May 2014
Offline
You can uncheck the “Evaluate In Process” toggle on the Python Script node. The script will be run in a separate hython child process created by the local scheduler. If you want to access your hip file, you'll need to something like the following:


import hou
hou.hipFile.load("$HIPFILE")

That will load the current .hip file into that Hython session.
User Avatar
Staff
585 posts
Joined: May 2014
Offline
I've fixed your .hip file so it works in process. You can use the Geometry Import to fetch your Prepare_Geometry and have it evaluate against the work item attributes. This will give you a work item per point, which you can then partition and dump to JSON.

Attachments:
PDG_Python_v001_fixed.hip (223.5 KB)

  • Quick Links