Forums > Javascript

Accessing object attributes?

October 29, 2011 | 9:39 pm

Just wondering if it’s possible to access an object’s attributes.
For example, dynamically changing the presentation rect of an object?


October 29, 2011 | 11:09 pm

What I’ve figured out so far:

1.) this.patcher.getnamed("obj") returns the object within the patcher with the scripting name "obj"
2.) obj.getattr("rect") returns that object’s rect… except I don’t know if it’s the patching rect or presentation rect, and the values returned don’t match up to either one
3.) obj.getattr("Presentation Rectangle") just spits out a null object

Are there some sort of reference pages for this? Somewhere that actually lists the corresponding tokens to pass to getattr()? It’d really take the guess work out of the equation.

EDIT: getattr("presentation_rect") correctly returns the presentation rect.
HOWEVER, setattr spits out the error: "JavaScript type error: setattr is not a function" =/


October 30, 2011 | 12:16 am

It seems getting attributes is a piece of cake as long as you know the token to pass getattr.
Setting attributes, however…. No amount of google searches has answered this for me yet.
Starting to believe that this feature doesn’t exist?


October 30, 2011 | 12:21 am

This works for me

– Pasted Max Patch, click to expand. –

October 30, 2011 | 12:31 am

Interesting… so I guess I could send the desired changes directly to the object, physically…. But what about virtually? Directly from javascript code?
I’d hate to write an entire "connection manager" system, just to change a few object attributes.


November 1, 2011 | 4:03 pm

Yeah,
i have the same problem. i want to read out the messege inside of a messege box with this code.

inlets = 1;
outlets = 2;

function liste(){
var Liste = this.patcher.getnamed("message");
var arr = Liste.getvalueof();
outlet(1, arr);
}

the message box has the scriptingname "mesage" and i sent the message "liste" to my js object, but i get jsobject 0 on outlet 1.
i didnt figure out where the failure is. any suggestions?


January 8, 2014 | 4:37 am

Setting attributes of objects from javascript works like this:

yourObjHandle.message("presentation_rect", 20, 20, 20, 20);

You could also adress object attributes by their scripting name (you have to specify the scripting name in the inspector at patcher level):

h_obj = this.patcher.getnamed("yourObjVarname");
if (!h_obj) post("Error: patcher does not contain an obj with scripting name yourObjVarname");
h_obj.message("presentation", 0);


Viewing 7 posts - 1 through 7 (of 7 total)