Tricky parameter shenanigan

   1260   11   1
User Avatar
Member
207 posts
Joined: 11月 2015
Offline
Hi.

I have kind of a tricky setup I'm trying to puzzle through. I have a "global control node" in my scene that's powered predominantly with Python. One of the things it does is pick a random image from a folder, analyze the image, and generate a selection of colors drawn from the image:



This works great in and of itself; I can poke the Randomize button and get a new color palette each time.

Throughout my scene, I would like to be able to refer to these colors, ideally in a nice user-friendly way. Sometimes I want to manually choose one of the colors, other times I want to say "give me a random color from the current 'scene palette'". So, I have a separate HDA I'm trying to build that can do this. Let's call this my ColorPicker node. It also is handled primarily with Python:



Where I'm having trouble is trying to figure out how to connect the two. I can create a callback on the ColorPicker whereby I specify the path to the "Controller" node so that it populates itself internally; but if I re-randomize the controller, all the child colorpicker nodes don't go along for the ride...I have to manually go refresh them all to get them to 'pull' new colors from the controller node.

I reasoned that maybe making a direction connection (via a channel reference or something) might cause the child ColorPicker nodes to update themselves when the Controller node is refreshed, but I'm having trouble figuring out how to do that efficiently...it seems that connecting multiparms programmatically doesn't work quite as simply as channel references, or at least I'm having trouble figuring out how to get this working.

I've also tried managing this with Context Options, but that's messy in a different way (Context Options don't have a Color type, so it's a little messier to see what I'm doing when I try to store a list of colors in a Context Option). My current multiparm on the Controller node is the best solution I've found to visualize a variable list of colors.

Anyway. This is a weird problem; I'm curious if anyone has ideas for how I might do this?

Attachments:
color_1.png (58.3 KB)
colors_2.png (15.2 KB)

User Avatar
Member
8555 posts
Joined: 7月 2007
Offline
Channel references (expressions) should work fine, especially since you are picking just a single color from multiparm
They can also be done with Python if you are more comfortable with it, it's definitely a way to keep the link live rather than populating the value using a callback
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
207 posts
Joined: 11月 2015
Offline
Cool, thanks! Is there a way to channel reference an entire multiparm from one node to another using python?

I seem to be able to read the multiparm “counter”, then can iterate through each of the multiparm params themselves to connect the one by one, but I have to have something to “trigger” this process, which is where I’m stuck.
Edited by dhemberg - 2023年2月26日 16:22:46
User Avatar
Member
8555 posts
Joined: 7月 2007
Offline
dhemberg
Cool, thanks! Is there a way to channel reference an entire multiparm from one node to another using python?

I seem to be able to read the multiparm “counter”, then can iterate through each of the multiparm params themselves to connect the one by one, but I have to have something to “trigger” this process, which is where I’m stuck.

that's a different question, I thought your second HDA was referencing a specific one parameter from multiparm (even if random)
for which you can just have an expression in that HDA parameter that pulls the right value from the right multiparm instance based on that HDA settings


however to link all instances of 2 multiparms together use: opmultiparm [www.sidefx.com] command, which you can also run from Python using hou.hscript() [www.sidefx.com]
which again, doesn't seem to be the case you described
Edited by tamte - 2023年2月26日 16:32:57
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
207 posts
Joined: 11月 2015
Offline
tamte
that's a different question, I thought your second HDA was referencing a specific one parameter from multiparm (even if random)
for which you can just have an expression in that HDA parameter that pulls the right value from the right multiparm instance based on that HDA settings

Hm, yeah, see this is my problem. The number of colors is not static; it can vary (sometimes the randomizer picks 5 colors from an image, sometimes it picks 9, etc). So my ColorPicker HDA needs to "ask" how many colors are available before it can know how to randomly choose one.

How it does this 'asking' is what I'm struggling with. I can have all my ColorPicker nodes do this with an OnLoaded script in the HDA, but this isn't all the way ideal in general, and it fails to 'notice' when the Controller node is re-randomized (or, at least, I'm unsure how to create a dependency between the two nodes without directly connecting a parameter).

The other way around it that I've played with is trying to mirror the Colors multiparm on the ColorPicker HDA, then connect the whole multiparm via channel references. This way, the ColorPickers should go along for the ride whenever the Controller is re-randomized, without the need for callbacks (I think). But I wasn't able to figure out how to connect an entire multiparm (the structure of which might change) in Python once, at node creation time, without using a callback.
User Avatar
Member
8555 posts
Joined: 7月 2007
Offline
dhemberg
Hm, yeah, see this is my problem. The number of colors is not static; it can vary (sometimes the randomizer picks 5 colors from an image, sometimes it picks 9, etc). So my ColorPicker HDA needs to "ask" how many colors are available before it can know how to randomly choose one.

that "asking" is what expressions are for
expression can lookup how many instances there are, generate random number within that range based on current HDA settings and then lookup such instance value and return it, live in the parameter
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
207 posts
Joined: 11月 2015
Offline
Heh, let's say you tried the opmultiparm command, hypothetically, and - hypothetically, of course - you mis-ordered the parameters and now have made a connection you don't want to make. How, hypothetically, do you permanently UN-opmultiparm connect a multiparm?
User Avatar
Member
207 posts
Joined: 11月 2015
Offline
tamte
that "asking" is what expressions are for
expression can lookup how many instances there are, generate random number within that range based on current HDA settings and then lookup such instance value and return it, live in the parameter

OHHHH, I think it just clicked; the stuff I'm trying to do via callbacks should just be in expressions on the params themselves. Ok, I think I got it...thank you!
User Avatar
Member
8555 posts
Joined: 7月 2007
Offline
here is an example

Attachments:
ts_pick_color_from_library.hipnc (106.2 KB)

Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
207 posts
Joined: 11月 2015
Offline
tamte
here is an example

Amazing! This is so super helpful, thank you so much! Also, re-posing the silly question I asked above: Is there a way to disconnect a multiparm that's been previously connected via opmultiparm? I managed to be my arg order backwards and now no amount of expressiom-deleting seems to break the connection...
User Avatar
Member
8555 posts
Joined: 7月 2007
Offline
you can use opmultiparm to remove such links also, just use empty strings "" as targets
then once you will be able to delete existing channels and they will not recreate
Edited by tamte - 2023年2月26日 22:05:17
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
207 posts
Joined: 11月 2015
Offline
Heh, *facepalm*. Awesome, thank you! And, thanks again for your help with my bigger question, it's working great! I was overcomplicating it a bit and lost sight of the forest for the trees.
  • Quick Links