Color coding new objects
Hey folks, something I've been wanting to do for a while to make my patches more legible is to color code a majority of my objects. For example, I tend to do a majority of my work in list processing with zl objects and then having the lists control timing / MSP objects. I'd really like to have a system where I can create a new zl object or any random ~ object and automagically have it be an arbitrary color, instead of changing them all manually after it's been created.
Is there a way to do this? I think that can be done if there's a method to effectively listen to a patch, such that whenever a new object is created, that object could then immediately be edited to have the correct color based on the type of object it is, but I'm not aware of any method that's capable.
There isn't a way to observe/get notifications when something in the patch changes AFAIK, but it wouldn't be too difficult to make code that sets colors / styles of different object types programmatically when it is run. You could either schedule such a thing to run once every minute or just call it on-demand when you want and it would then update your whole patch.
If I were to do this, I would probably do this by defining object styles and setting the Max objects' style attribute rather than specifically changing object's brgb and textcolor attributes since would be more efficient and flexible.
To do it in Max code you'd need to store a bunch of messages (likely in a [dict] or [coll] structure) to send to a [universal] object in the target patch that apply styles/colors. Or via javascript you would use Patcher object and it's applyif() or applydeepif() method.
With Javascript you can be more clever about where your color-code-setting logic lives --- you could run it from a patch in the 'Extras' menu and have it apply to the front patcher, for instance, without needing to add any Max objects into that patcher.
Oh my Lordy thank you so much for reminding me of the existence of the universal object. That was definitely the piece of the puzzle I was missing. I also spent some time remembering that you have to use the "sendbox" message to address common attributes for boxes directly. Quick example attached for anyone who may want to reference in the future.