How to get attributes that are dictionaries?

Joe Kaplan's icon

How can I get an attribute that is stored as a dictionary?

I have a panel. After lots of careful tweaking I got a color that's very pleasing to me. I want to use that color elsewhere in my patch. I figured I would use [getattr] to get the 4 value list that I could pass around to anything else that I wanted to match to that color. But [getattr] doesn't output anything. If I use the inspector to "create a message box with this attribute's current value" I get "bgfillcolor dictionary."

Okay, so panel colors are stored as dictionaries. I read a bit about dictionaries. Dictionaries look neat! I thought maybe if I hook up a [dict.view] to [getattr] I'd be able to see the attributes values. But alas, it still is empty.

So... the question remains? How can I get the values of attributes that are stored as dictionaries?

I know there are ways, for example I could open the patch as a text file and find the values that ways. But if I want to manage these attributes programmatically I need to be able to get them within the program.

Thanks for any tips.

Max Patch
Copy patch and select New From Clipboard in Max.

Luigi Castelli's icon

Yes, I also experienced the same as you are describing. It is impossible with the [getattr] object to query the color attribute of the [panel] object when in "Color Fill" mode.
You may fill a feature request with C74, however I believe there is no immediate workaround for this.

kleurbleur's icon

Still not possible. The multi views of [attrui] shows only one value.
Workaround is the [colorpicker] and use the dropper but that is a manual non programmatically way.

11OLSEN's icon

You can get it with js. For this solution you have to set a scripting name for the [panel]:

get_bgfillcolor.js
application/x-javascript 0.28 KB

Max Patch
Copy patch and select New From Clipboard in Max.

🐰

kleurbleur's icon

Applause! Though I do think Cycling should include these properties in the [attrui] object.

klaus filip's icon

yes wonderful, theAttr.getkeys() in the code of 11Olsen.

is there also a chance to set such an attribute?

d = object.getattr("bgfillcolor");
d.set("angle", 12.);
object.setattr("bgfillcolor",d);

was a try, but results in the error "jsobject: bad number"

TFL's icon

Maybe the last dot in theAttr.set("angle", 12.) is too much. For me it works:

Max Patch
Copy patch and select New From Clipboard in Max.

klaus filip's icon

i found a workaround binding a pattr object to the dict-parameter. pattr accepts the changed dict.

testparam.js
js
Max Patch
Copy patch and select New From Clipboard in Max.

klaus filip's icon

let TFL be thanked !

works great

klaus filip's icon

a follow up:
why is this not working?

Max Patch
Copy patch and select New From Clipboard in Max.

klaus filip's icon

well, this is working...

Max Patch
Copy patch and select New From Clipboard in Max.