Reading Multiparm without replaced "#" in Python

   442   4   1
User Avatar
Member
16 posts
Joined: Sept. 2023
Offline
Hey!

I'm trying to get the unformatted multiparm parameter name from a hou.Parm object (my_multiparm_#_#). There might be an easy solution to do this but so far I'm having difficulty finding one..

Say I have a custom HDA with a string multiparm: my_string1, my_string2, my_string3. in Python, I can write:
my_hda_node = hou.node("/obj/geo1/my_hda")
for parm in my_hda_node.parms():
    print(parm.tuple().parmTemplate().name())

For my use case, I'd like to get:
"my_string#, my_string#, my_string#"
, rather than:
"my_string1, my_string2, my_string3"

But it appears in the documentation that we'll always get the "#" replaced. Additionally, there are nested multiparms with multiple pound signs, and I'd like to read those without the number replacements as well. Does anyone have any tips? Thanks!
Edited by nd_sliu - April 29, 2024 19:31:53
User Avatar
Member
213 posts
Joined: June 2023
Offline
IiRC you can get the original name from ParmTemplate.
User Avatar
Member
16 posts
Joined: Sept. 2023
Offline
@kodra. I believe that's what I'm doing here.
I tried parm.tuple().parmTemplate().name() and parm.parmTemplate().name()
both gives me something like my_string1 instead of my_string#

Afaik ParmTemplate describes the parameter as it is in the asset definition, so having it return the parameter name as if it's instanced feels confusing..
User Avatar
Member
213 posts
Joined: June 2023
Offline
Well, sorry, I thought it'd work.

There is a working solution:

node = hou.node("../multiparm_test")
parmTuple = node.parmTuple("parm1_2_3")
indices = parmTuple.multiParmInstanceIndices()
name = parmTuple.name()

for i in range(len(indices)-1, -1, -1):
    index = indices[i]
    old_suffix = f"_{str(index)}" if i > 0 else str(index)
    name = name.removesuffix(old_suffix)

name += '_'.join(["#"] * len(indices))
    
print(name)

Might not be the most elegant snippet of code though.
Edited by kodra - May 1, 2024 02:41:26

Attachments:
multiparm_name.hip (89.7 KB)

User Avatar
Member
16 posts
Joined: Sept. 2023
Offline
I thought so too! Thank you for the code snippet. Maybe this can be something for SideFX to dig into so the code can be a lot shorter.
  • Quick Links