script object in parent patcher...

MIB's icon

I'm not sure this is possible (well, maybe with js) but here it goes anyway:

I have an abstraction that is used for debugging purposes only. whenever it is created, I would like to have a message box scripted and connected to the rightmost outlet of the abstraction. I don't think thispatcher will be of much help since that only works on the same level the object is in. I need to script the new object in the PARENT.

Any ideas? Thanks

Luke Hall's icon

Is there no way you could load this abstraction into a [bpatcher] so you can leave the message box inside the abstraction and have it clickable from the parent patcher without having to worry about extra scripting?

MIB's icon

it's not impossible, but since it's for debugging only it's less of a hassle if it's an abstraction. It's really not a big deal to add a message box manually, just wondering if there was a way to automate it... always trying to improve things ;)

Luke Hall's icon

Try something like the code below. You might have to change the spacing values but these work fine on my current set up. It assumes your object has 3 inlets. I'm not quite sure how you'd get it to fire when you instantiated the abstraction though.

function bang() {
    p = this.patcher.parentpatcher;
    if (p) {
        b = this.patcher.box;
        loc = b.rect;
        a = p.newdefault(loc[2]-19,loc[1]-20,"message");
        a.set("this is the text");
        p.connect(a,0,b,2);
    } else {
        post("uhoh!n");
    }
}
MIB's icon
Max Patch
Copy patch and select New From Clipboard in Max.

have been playing with the js object a bit and seems to be working fine. haven't done any extensive testing yet (it's rather late).

/*************save js as parentTest.js***********************/

function bang() {

var parent = this.patcher.parentpatcher;

var objCoords= this.patcher.box.rect;

var a = parent.newobject("message", objCoords[2] - 19, objCoords[3] + 5, 70, 16);

parent.connect(this.patcher.box, 2, a, 0);
}

MIB's icon

seems like you just beat me to it ;)

MIB's icon

to get it to fire I use a patcherargs -> [sel done]. seems to work for now. again, have to do serious testing tomorrow. for now I'm happy and will get some sleep!!!

Thanks

Luke Hall's icon

Great idea! I'm sure there's a way to force the object width if you're adding text to the message box too. It can be done with @fixwidth 1 using [thispatcher] so I image you can achieve the same thing in javascript too somehow.