Ok, so I am trying to build a custom processor for running a PDG process in Hython and I am having some issues. I have tested the workflow using TOPs and the methodology I am trying to use works perfectly in a Python Processor TOP node. I was trying to figure out how to get it to work in a standalone .py file and came across this page [www.sidefx.com] which details creating a custom processor, complete with the on generate and onCookItem callback info. So I set to coding. Everything seems to be right, all of the code 'runs' and all of the object types pass through my function calls and the data at the error is all correct. The work items that are being run through are the correct ones from the File Pattern node, the code for the loop is identical to what is in the onGenerate() function on the Python Processor node in my TOPs network, and the item_holder is the right object and has the functions. Ideas?
importpdgfrompdg.processorimportPyProcessorclassCustomProcessor(PyProcessor):def__init__(self,node):PyProcessor.__init__(self,node)defonGenerate(self,item_holder,upstream_items,generation_type):forupstream_iteminupstream_items:new_item=item_holder.addWorkItem(parent=upstream_item,inProcess=True)# ^^^ Error occurs here ^^^returnpdg.resultdefonCookTask(self,work_item):#proprietary code goes herepasspathMed='$HIP/geo/hythonTest.filecache1.*.bgeo.sc'whereItWorks=pdg.GraphContext("testBed")whatWorks=whereItWorks.addScheduler("localscheduler")findem=whereItWorks.addNode("filepattern")whereItWorks.setValue(findem.name,'pattern',pathMed,0)findem.cook(True)item_holder=pdg.WorkItemHoldertest=CustomProcessor(findem).onGenerate(item_holder,findem.workItems,pdg.generationType.Static)
Error: Python error: Traceback (most recent call last):
File "", line 66, in
File "", line 39, in onGenerate
TypeError: _addWorkItem() missing 1 required positional argument: 'self'
So I realized after submitting that I might need to register the custom processor as a node and then add it to the graph using .addNode() as I did previously to get it to work. Unfortunately this created an eerily similar issue error:
Python error: Traceback (most recent call last):
File "", line 24, in
File "", line 22, in registerTypes
TypeError: _registerNode() missing 1 required positional argument: 'node_type' It definitely has the positional argument, and it is correct. pdg.nodeType.Processor is definitely the right one and definitely is in the right place.
Ok, solved several other issues. Looks like most of them have been the fact that I had to find the right way to instantiate the objects. Which brings me to pdg.WorkItemHolder. It has no constructor, so when I use item_holder = pdg.workItemHolderit is building some sort of object with the type . This ends up not being the right type for when I go to call the member function pdg.WorkItemHolder.addWorkItem()from the created object, the type is wrong for selfand it throws an error saying that it does not have the selfargument. When I try to use pdg.workItemHolder()it throws an error saying there isn't a constructor. Through Python it should still work, but Hython is throwing a fit. I have used the inspect library to dig into the code which is running in the frame and stack and have narrowed down the information for pdg.WorkItemHolder.__init__()to being held in C:/Program Files/Side Effects Software/Houdini 19.0.561/houdini/python3.7libs/_pdg.pyd, which I am obviously not getting into without violating EULA, so that is my end point for investigation.
I really need to get this working, so if there isn't any help here I will have to make a ticket shortly. I'm sure it is possible, just need to figure out how to get all the right objects for the arguments in the onGenerate() code.