29 """This is the Python equivalent of PDG_PartitionByParity.C which uses
33 1) Create a directory on the Houdini search path for custom PDG Python
34 nodes, if one does not already exist. For example, ~/houdini20.0/pdg/types
35 2) Save this file to that directory as partitionbyparity.py
36 3) Within Houdini the custom node will now show up in the TAB menu in
42 from pdg.partitioner
import PyPartitioner
44 class PartitionByParity(PyPartitioner):
46 Partitioner implementation that groups upstream work items based on the
47 parity of an attribute value
49 def __init__(self, node):
51 __init__(self, pdg.Node) -> NoneType
53 Initializes the partitioner
55 PyPartitioner.__init__(self, node)
58 def templateName(cls):
60 templateName(cls) -> str
62 return "partitionbyparity"
65 def templateBody(cls):
67 "name": "partitionbyparity",
70 "name" : "attributename",
71 "label" : "Attribute Name",
78 def onPartition(self, partitions, work_items):
79 attribute_name = self[
'attributename'].evaluateString()
81 for work_item
in work_items:
82 attrib = work_item.attrib(attribute_name)
85 "'{}' has no attribute with the name '{}'",
86 work_item.name, attribute_name)
89 index = 0
if int(attrib.asNumber(0)) % 2 == 0
else 1
90 partitions.addItemToPartition(work_item, index)
92 return pdg.result.Success
94 def registerTypes(type_registry):
95 type_registry.registerNode(
97 pdg.nodeType.Partitioner,
98 label=
"Partition by Parity")