Jump to content

Creating parameters with a Shelf Button in python


merlino

Recommended Posts

Hi guys, I'm trying to create a shelf button that quickly create a parameter into the selected node. To start, I'm happy with the initial solution, taken from 

https://www.sidefx.com/index.php?option=com_forum&Itemid=172&page=viewtopic&t=22539

n = hou.selectedNodes()[0]
group = n.parmTemplateGroup()
n_fol = hou.ui.readInput("Folder name: ", title=('Add Float:'))[1]
n_par = hou.ui.readInput("Parm name: ", title=('Add Float:'))[1]
folder = hou.FolderParmTemplate(n_fol, n_fol)
folder.addParmTemplate(hou.FloatParmTemplate(n_par, n_par, 1))
group.append(folder)
n.setParmTemplateGroup(group)

but I have a problem, when I run again to add a second parameter, the folder takes name from the first one adding '_1' instead of taking the name I put in the folder name. The label it's ok, with the name I insert. Any idea why is this happening?

 

Thanks!

Link to comment
Share on other sites

Hi guys, I'm trying to create a shelf button that quickly create a parameter into the selected node. To start, I'm happy with the initial solution, taken from 

https://www.sidefx.com/index.php?option=com_forum&Itemid=172&page=viewtopic&t=22539

n = hou.selectedNodes()[0]
group = n.parmTemplateGroup()
n_fol = hou.ui.readInput("Folder name: ", title=('Add Float:'))[1]
n_par = hou.ui.readInput("Parm name: ", title=('Add Float:'))[1]
folder = hou.FolderParmTemplate(n_fol, n_fol)
folder.addParmTemplate(hou.FloatParmTemplate(n_par, n_par, 1))
group.append(folder)
n.setParmTemplateGroup(group)

but I have a problem, when I run again to add a second parameter, the folder takes name from the first one adding '_1' instead of taking the name I put in the folder name. The label it's ok, with the name I insert. Any idea why is this happening?

 

Thanks!

Generally you should not care about folder names, only Labels are important, 99% of the time working with parm templates. Houdini manages those names automagically somehow  :)

Edited by Stalkerx777
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

You need to check if the folder/item exists before you blindly create a new one. If it does exist, fetch the existing one instead of creating a new one. Otherwise default name management will haunt you and multiple copies will build up. For instance, you should examine group before you append to it.

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...