Forums > Dev

query width and height of UI object box

March 6, 2010 | 9:28 am

after a longer break, i’m working on a UI external again, and my brain still seems to be a little rusty…
while initializing the object variables in the new-routine, i need to query the width and height of the current objects box. therefore i guess i need a patcherview (in order to be able to call jbox_get_rect_for_view()).
is it possible to get a patcherview at this stage of object instantiation (in the new-routine), or would i have to somehow get hold of the patcher_rect attribute from the inspector?

March 6, 2010 | 5:08 pm

Hi Volker,

you do not need a patcherview. You need a dictionary.
You need to query the values you need from the dictionary that you create in the myobject_new routine. They are all there.

Look at the jslider example in the SDK and specifically at the jslider_stdargs() method to get a clue on where the values you need might be.

Hope this helps.
Let me know if that solves your problem.

- Luigi

March 6, 2010 | 9:53 pm

ciao luigi
thanks for the hint. dictionary looks interesting, but somewhat complicated…
from the api get the impression, i need something like dictionary_copyatoms, to get hold of the patcher_rect attributes.
so i tried:

t_atom **r = NULL;
long num = 4;
long k;
dictionary_copyatoms(d, gensym("patching_rect"), &num, r);
for(k=0; k<4; k++)
post("k: %ld — %f", k, atom_getfloat((t_atom *)r+k));

which crashes…
the atom_getfloat() call causes me trouble.
is that going into the right direction at all?
it’s not urgent, as i found a workaround for what i was trying to do, but comments on how to get values from the dictionary would still be welcome.

March 6, 2010 | 11:37 pm

The only reason why you get a crash is because of some dereference confusion.
Do the same but replace atom_getfloat((t_atom *)r+k) with atom_getfloat((*r)+k)

Other than that, you are definitely in the right direction…

You might also want to consider using dictionary_getatoms().
This way you don’t need to allocate any memory.
You just get a pointer to the patching rect which, in most cases, it’s all you need.


- Luigi

March 8, 2010 | 8:08 pm

> Do the same but replace atom_getfloat((t_atom *)r+k) with atom_getfloat((*r)+k)

hm, i’ve tried that before, and it crashes here just the same.
any more clues anyone?

March 9, 2010 | 12:51 pm

Do you know which line it crashes on? The crash report probably tells you.

However, I can see a couple of suspicious things about your call to dictionary_copyatoms().

t_atom *r = NULL;
long num = 0;
long k;

dictionary_copyatoms(d, gensym("patching_rect"), &num, &r);
for (k=0; k<4; k++)
    post("k: %ld -- %f", k, atom_getfloat((*r)+k));
if (r)

This is email-client coding, but notice that I pass a size (num) initialized to zero and also that for 'r' I am passing the address of a valid pointer (which is pointing to NULL).

Hope this helps

March 9, 2010 | 1:37 pm

thanks, tim. your version won’t compile here, but it got me on the right track.
i got a little confused by the pointer to point to t_atom thing from the dictionary_copyatoms() call, and wasn’t sure how to properly dereference it. but this, too, of course is only an address.
so this works for me:

t_atom *r = NULL;
long num = 0;
long k;

dictionary_copyatoms(d, gensym("patching_rect"), &num, &r);
for (k=0; k<4; k++)
post("k: %ld -- %f", k, atom_getfloat(r+k));
if (r)

dictionary seems to be quite powerful. i think a future version of the sdk would benefit from some more examples on how it can be used.
thanks again,

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