Hello,
I would like to fetch files using python into work items.
I have an array of file paths and I want to create a work item per file basically to process them.
Same way as the “filepattern” top but with python processor.
I can not find the python way to do that.
Thank you guys
Python processor fetch files
1568 2 0- Mikel Zuloaga
- Member
- 9 posts
- Joined: July 2016
- Offline
- tpetrick
- Staff
- 585 posts
- Joined: May 2014
- Offline
Assuming the files array is stored as an attribute on the input work items, you could do something like the following in the Python Processor node:
That will create work items from the “files” attribute on each of the input work items.
If you want to find the files on disk in the same way as the file pattern node, something like the following would work if the node has no input work items:
for upstream_item in upstream_items: for file_path in upstream_item['files'].values: new_item = item_holder.addWorkItem(parent=upstream_item) # Set the file as an attribute on the new work item new_item.setStringAttrib("file", file_path) # or, to add it as an output file on the new item new_item.addResultData(file_path, "file/txt", 0, False)
That will create work items from the “files” attribute on each of the input work items.
If you want to find the files on disk in the same way as the file pattern node, something like the following would work if the node has no input work items:
import hou import glob for file_path in glob.glob(hou.text.expandString('$HFS/houdini/pic/*.png')): new_item = item_holder.addWorkItem() # Set the file as an attribute on the new work item new_item.setStringAttrib("file", file_path) # or, to add it as an output file on the new item new_item.addResultData(file_path, "file/txt", 0, False)
Edited by tpetrick - Sept. 17, 2020 17:16:10
- Mikel Zuloaga
- Member
- 9 posts
- Joined: July 2016
- Offline
Houuu thanks man ! Excatly what I want!
Now I want to perform operations with COP and export these files using “rop composite output”.
I have houdini 17.5.460 at work and it looks like it doesn't work with .exr … just .jpg
I tried on my own machine with houdini 18 and everything is fine.
Is there any bug on 17.5 ?
Now I want to perform operations with COP and export these files using “rop composite output”.
I have houdini 17.5.460 at work and it looks like it doesn't work with .exr … just .jpg
I tried on my own machine with houdini 18 and everything is fine.
Is there any bug on 17.5 ?
-
- Quick Links