Multiparm default quantity expression?

   3941   7   0
User Avatar
Member
337 posts
Joined: June 2013
Offline
Diving in into multiparms again. How can set the default amount value to an expression?
Atm I'm linking it to the number of keys in a ramp, with python, AFTER the node is created:
hou.parm("./dist_ramp")
return len(parm.eval().keys())

So the multiparm amount is in sync with a Ramp. But only after I set the expression myself since the default of multiparm folder does not have the expression buttons like other parameters (hscript, python, literal) in the Channels tab.

So, what's the best way to sync it by default?
Keep in mind I'm looking for a solution that also works for multiparms inside multiparms, so that maybe just a OnCreated won't be enough.

Thanks
Edited by probiner - July 25, 2019 20:05:02
User Avatar
Member
337 posts
Joined: June 2013
Offline
Well
ended up using callback script which is not a pretty line (and some functions seem to fizzle without warning), but hey, works…

 parm = kwargs["parm"] ; suffix = "_".join([str(i) for i in parm.multiParmInstanceIndices()]) ; hou.parm("./multi_dist" + suffix).set(len(parm.eval().keys()))

So the ramp parameter I'm applying this callbackscript to is called ramp_dist# but I don't know how to easily get the suffix index of the parm, hence the
suffix = "_".join([str(i) for i in parm.multiParmInstanceIndices()])
bit to get just that… and then I set the size of the multiparm called multi_dist# with the same suffix.


This way I have a multparm size driven by the number of keys in the ramp.

Cheers
Edited by probiner - July 26, 2019 00:14:51
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
probiner
Well
ended up using callback script which is not a pretty line (and some functions seem to fizzle without warning), but hey, works…

I feel your same pain of writing a single long inline callback.
I now do the following:
I create a string parm, set it to multi-line and language python. I type there my callback code.
Then I simply ‘exec’ that evaluated string parm inside the callback field. Once happy I set string parm to invisible.
It's a little bit longer setup, but this I way I can type and visualize easily the callback code.

Attachments:
multilinecallback.JPG (79.4 KB)

User Avatar
Member
337 posts
Joined: June 2013
Offline
Thanks that's an idea. Might streamline an issue I was finding with multiParmInstanceIndices() being unsorted and the sort() does not seem to be working on callback script…(?). So that should ease up the development of such solutions.

Or let me know if there's another way to get the parameter suffix reliably. I can't get info about the parm without the index, other wise I would do suffix = parmfullname.

Cheers
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
not sure if it can help, do you know that you can use the keyword
kwargs['script_multiparm_index']
to get the index of a multiparm instance?
Edited by Andr - July 26, 2019 10:16:29
User Avatar
Member
337 posts
Joined: June 2013
Offline
Andr
not sure if it can help, do you know that you can use the keyword
kwargs['script_multiparm_index']
to get the index of a multiparm instance?

The issue is that multiple levels of nester multiparm you will have several `script_multiparm_index`, that's what I'm retrieving with multiParmInstanceIndices() but I was wondering if there was a better/proper way.

Thanks!
User Avatar
Member
337 posts
Joined: June 2013
Offline
From the kwargs, `script_multiparm_nesting` states how many indices or script_multiparm there are in the sufix and then one can iterate all the `script_multiparm`s, get their value and construct the parm suffix. If the group name is needed then just need to slice the parm name according to the size of the suffix.
Edited by probiner - Aug. 3, 2019 00:21:06
User Avatar
Member
337 posts
Joined: June 2013
Offline
One can use dataBlocks to store info in nodes. So that's nice
.
Cheers

dataBlockKeys(blocktype)  tuple of str
dataBlockType(key)  str
dataBlock(key)  str
setDataBlock(key, block, blocktype)
  • Quick Links