Change Attribute of Many Objects at Once

Joe Kaplan's icon

I have 30 LEDs, and I want to change the OnColor of all of them at once.

I'm trying to think of efficient ways to do this. The most obvious solution is to attach a "receive oncolor" object to each one of them. And then send "oncolor $1 $2 $3 $4" to "send oncolor"

I thought the pattr system would offer a good solution here, but I'm not seeing any clear advantage. Pattr and Pattrforward have to be bound to a single scripting name. (I'll go with pattrforward for now, since I may also want to change the off color. And it looks Pattr has to be to a single attribute to single, whereas pattrfoward can send messages to all the attributes.)

So either I need one pattrforward for each object, and then I still have to send the "oncolor" message to each of them. And if I create a new led, I have to assign it a scripting name, create a new pattrforward and bind it, and hook it up to the oncolor message.

Alternatively I could use one pattrfoward object, and rebind it as I iterate through the list of LED scripting names using UZI and a umenu or something (bang, change target, bang, change target, etc). But then I have to maintain a list of LED Scripting names. Count them and adjust uzi.

It's all very messy.

I noticed autopattr makes it really easy to assign formalized scripting names. LED[1], LED[2], LED[3]. I feel like I should be able to leverage this to send a message to all objects of the name LED[$i], without having to keep track of just how many of them there are.

Then I could create a new LED and it would automatically be hooked into my color-changing scheme without a bunch of additional fussing.

Is this possible?
Thanks!


Luigi Castelli's icon

I have 30 LEDs, and I want to change the OnColor of all of them at once.

Use the [universal] object.

Joe Kaplan's icon

Thanks! I can see how that could be useful. Playing around some more, is there any way to exclude objects from [universal]?

Say I want to change 20 LEDs to one color and 10 LEDs to another?

11OLSEN's icon

A js can iterate all objects and identify objects using the scripting name. You can add your tags or whatever as scripting name. When you duplicate objects, Max will add index numbers to the scripting name.

function showp2()
{
    this.patcher.apply(eachobj);
    function eachobj(obj)
    {
        if ( obj.varname.indexOf("__p2") > -1 )
        {
//name has a tag
            //post("moving up");
            c = obj.getattr("presentation_rect");
            if (c[1]> 170)
            obj.message("sendbox","presentation_position",c[0],c[1]-170.0);
            
        }    
        return true;
    }
}

Here i'm looking for objects with a tag and move them up in presentation view.

Roman Thilenius's icon


whats wrong with making 30 connections?

11OLSEN's icon

That would be to easy!