Python: Add parameters from a list into the same folder

   367   1   1
User Avatar
Member
4 posts
Joined: May 2019
Online
Hi everyone! I'm actually struggling with some code. I have multiple parameters created into the same list, but I can't add them in the same folder as it gives me an error. Here's a part of the code:

    text = selectedNode[0].path()
    textAddParm = hou.node(text); #Use the node selected
    wedgePath = hou.node(textAddParm.parm('soppath').eval()); #Take the path from a parameters in a node
    
    tempGrp = textAddParm.parmTemplateGroup() #Create temporary group to append new parameters
    tempGrp.remove("wedge"); #Delete existing folder if it exist
    
    folder = hou.FolderParmTemplate("wedge", "Wedges Paramaters References"); #Recreate the folder
    tempGrp.append(folder);
    wedgeParm = [] #Set wedgeParm fonction to be a list
    
    for child in wedgePath.children(): #There is 3 child in the soppath directing to the subnetwork
        paramaterName = child.parm("name1").eval();
        parameterNameEval = "@" + paramaterName;
        parmTemplate = hou.FloatParmTemplate(str(child), paramaterName, 1, default_expression=[parameterNameEval]);
        wedgeParm.append(parmTemplate); #Append each parameter to wedgeParm list

With this, I have 3 diffents parameters:

wedgeParm[0]
wedgeParm[1]
wedgeParm[2]

And when I try to add more than one parameters:

tempGrp.appendToFolder(folder, wedgeParm[0]);
tempGrp.appendToFolder(folder, wedgeParm[1]);
tempGrp.appendToFolder(folder, wedgeParm[2]);
textAddParm.setParmTemplateGroup(tempGrp);

It gives me an error (but as long as I use one parameter only, it works):

  File "<console>", line 1, in <module>
  File "hou.session", line 258, in nameTest
  File "C:\PROGRA~1/SIDEEF~1/HOUDIN~1.332/houdini/python3.11libs\hou.py", line 23461, in appendToFolder
    return _hou.ParmTemplateGroup_appendToFolder(self, *args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
hou.OperationFailed: The attempted operation failed.
Invalid indices/name/parm template

So, do you have any idea why I can add one parameter to the list, but can't add the rest of it? Thanks!
If it work it ain't broken
User Avatar
Member
4 posts
Joined: May 2019
Online
Re: Thanks to the user Core, a workaround was found, rathen than using

tempGrp.appendToFolder(folder, wedgeParm[0]);
tempGrp.appendToFolder(folder, wedgeParm[1]);
tempGrp.appendToFolder(folder, wedgeParm[2]);
textAddParm.setParmTemplateGroup(tempGrp);

I should've used

for parm in wedgeParm:
        folder.addParmTemplate(parm)
textAddParm.setParmTemplateGroup(tempGrp);
If it work it ain't broken
  • Quick Links