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?
Tricky parameter shenanigan
1529 11 1- dhemberg
- Member
- 207 posts
- Joined: Nov. 2015
- Offline
- tamte
- Member
- 8768 posts
- Joined: July 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
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
FX Supervisor
Method Studios, NY
- dhemberg
- Member
- 207 posts
- Joined: Nov. 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.
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 - Feb. 26, 2023 16:22:46
- tamte
- Member
- 8768 posts
- Joined: July 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 - Feb. 26, 2023 16:32:57
Tomas Slancik
FX Supervisor
Method Studios, NY
FX Supervisor
Method Studios, NY
- dhemberg
- Member
- 207 posts
- Joined: Nov. 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.
- tamte
- Member
- 8768 posts
- Joined: July 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
FX Supervisor
Method Studios, NY
- dhemberg
- Member
- 207 posts
- Joined: Nov. 2015
- Offline
- dhemberg
- Member
- 207 posts
- Joined: Nov. 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!
- tamte
- Member
- 8768 posts
- Joined: July 2007
- Offline
- dhemberg
- Member
- 207 posts
- Joined: Nov. 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...
- tamte
- Member
- 8768 posts
- Joined: July 2007
- Offline
- dhemberg
- Member
- 207 posts
- Joined: Nov. 2015
- Offline
-
- Quick Links