Get Index of Current MultiParm

   7152   5   3
User Avatar
Member
2162 posts
Joined: Sept. 2015
Offline
I'm using a default expression for a multi parm(whose total numbers will be dynamically created) but in order to work as intended I need to know how to get the 'current' index of a specific multi parm.

I've included an example file in which everything is set up and the only missing piece is the specific index.
(In the example just to get values output, for the index, I'm using the 'master' parm which gives the total parms created.)


Default Expression:
Tgt_Node    = hou.node('/obj/geo1/Adjust_Specific_Profiles/')
Index       = Tgt_Node.parm('per_prim_adjust').eval()
# Preffered > Index = Tgt_Node.parm('profile_id#').eval()
Index -= 1
  
Tgt_Detail  = Tgt_Node.geometry()
Value       = Tgt_Detail.intListAttribValue('Modify_Curvature_List')[Index]

return Value
Edited by BabaJ - Sept. 23, 2022 17:37:14

Attachments:
MultiParm_Index.hiplc (136.6 KB)

User Avatar
Member
899 posts
Joined: Feb. 2016
Offline
oh that's an interesting issue. Now I would like to know too.
kwargs dict would be useful, but it's only provided with callback scripts afaik.
So we should find a way to retrieve the name of the parm from its very input field. I cannot believe there's no function for that.
If we had the name of the parm, we could extrapolate the index.

As dumb workaround I can only think of the following (but disclaimer: I haven't tested):
1) Append a Python Sop upstream of that wrangle
2) evaluate the "per_prim_adjust" parameter.
3) perform a loop over each multiparm instance and set the custom value.


point 2 is important so that every time you add a new multiparm instance, the upstream python sop is triggered and run.
Edited by Andr - Sept. 24, 2022 06:39:12

Attachments:
pythoupdatemultiparm.JPG (64.1 KB)

User Avatar
Member
2162 posts
Joined: Sept. 2015
Offline
When I looked at your example I was puzzled as to how you can get what you show without error.
The reason is because you are accessing a nodes downstream value which depends on an upstream value that could be dynamically changed.

In other words, there's an infinite recursion happening.

So I thought I would give it a try hoping there was some 'exception' to using a python node that could do something like this that I wasn't aware of.

But alas as I thought, I get an infinite recursion error on the python node when I try what you have. But it's strange that you don't show an error in your example.

The only thing I can think of is you removed the expression that was in the parameter of 'per_prim_adjust' of the 'Adjust_Specific_Profiles' node.

The intent of my setup( a simplified version of another file) was to keep that input on the said parameter I mentioned set to be dynamically changeable from upstream data and not have to manually enter the number of 'sub-parms'.

I thought I could take advantage of the multi-parm block parameter and only if I could get the index value as I mentioned before, might save myself some work of not having to dig into learning a bit more Python.

It seems if I really want to do the setup as I want, instead of the code you provided, go more in depth by using 'Parm-Templates'?

And instead of setting up the parms with expressions on the 'Adjust_Specific_Profiles' node itself; I simply create the parms(This time not a multi-parm block per se) and set the values from Python. Since in that Python code I will be accessing the arrays from upstream, and the code could easily adjust for more or less parms even though other parms which reference those parms created would have to be re-entered. Which is ok, as the dynamic part of the setup I want is more about having a 'user-end interface' ready to go.

So I think for now I will just go with manually setting up the number of multi-parms I need to match the number of array elements and when I feel like investing some more time working with some Python code I'll do that.

Thanks for your input.
Edited by BabaJ - Sept. 25, 2022 10:56:31
User Avatar
Member
2162 posts
Joined: Sept. 2015
Offline
Ok...I thought of a solution without having to get into Python.

I added a for each loop using the iteration attribute as an index.

Attachments:
MultiParm_Index.hiplc (137.8 KB)

User Avatar
Member
151 posts
Joined: June 2019
Online
Not sure, but is this what you want? (in the attachement)

Couple of caveats:
- hou module globally imported in the parameters evaluating context (no need to prepend hou.)
- pwd() is better than direct link
- evaluatingParm() is basically $CH for python returning current hou.Parm object

Attachments:
MultiParm_Index.hiplc (136.4 KB)

User Avatar
Member
2162 posts
Joined: Sept. 2015
Offline
elovikov
Not sure, but is this what you want? (in the attachement)

Couple of caveats:
- hou module globally imported in the parameters evaluating context (no need to prepend hou.)
- pwd() is better than direct link
- evaluatingParm() is basically $CH for python returning current hou.Parm object

Yep, that's the python function that returns the 'current' index of the multi-parm. Thanks.

For those interested:

Index = Parm.multiParmInstanceIndices() - 1

It's on this page in the docs:

https://www.sidefx.com/docs/houdini/hom/hou/Parm.html [www.sidefx.com]
  • Quick Links