How to set parameters on pxrTexture node in Katana using python

469 views Asked by At

I am trying create a node and set a value using this function:

def createTextureNode(textureNode):
keyword = textureNode
for fname in os.listdir(assetFilePath):
   if keyword in fname:
       texFilename = fname + ".tex"
       newTexNode = NodegraphAPI.CreateNode("PrmanShadingNode", rootNode)
       newTexNode.getParameter('name').setValue(assetCode + '_' + textureNode, 0)
       newTexNode.getParameter('nodeType').setValue("PxrTexture", 0)
       newTexNode = NodegraphAPI.GetNode(assetCode + '_' + textureNode)
       if textureNode == "Albedo":
        newTexNode.getParameter("parameters.linearize.enable").setValue(True,0)
        newTexNode.getParameter("parameters.linearize.value").setValue(True,0)

Its pretty simple, if a particular file exists it will create a node for it. However, I am unable to set the "linearize" value (or any other value under the "parameters" group)

If I manually create a node and manually set it to be a PxrTexture and use this code:

node = NodegraphAPI.GetNode("PrmanShadingNode")
node.getParameter("parameters.linearize.enable").setValue(1,0)
node.getParameter("parameters.linearize.value").setValue(1,0)

Then it works, the check box turns on, but if I set the nodeType via script then it fails. But if I run it a second time it works! The error I keep getting is:

AttributeError: 'NoneType' object has no attribute 'setValue'

I know this means that its returning "None" but the tool tip in Katana says that its "parameters.linearize" and the first two parameters were able to be set... but these are under a Group, I think?

Since it works with the manual create, it must be something I am missing in my script, but I can not figure it out. I have also tried using finalizeValue after setting my nodeType but his has no affect

I am using this as my reference: Getting and Setting Parameters

1

There are 1 answers

0
David Tonkin On

GOT IT!

When setting a Dynamic Parameter Pragmatically, you have to run checkDynamicParameters() after you set the value that makes the new parameters appear

This updates the UI Loop and makes the new parameters available. When doing this via the UI, it happens on the fly, and thats why it works when doing it manually

ANSWER REFERENCE