Forums > Dev

Deleting attributes

Apr 19 2012 | 9:23 am

Hello everybody,

Is there a way to remove an attribute in a Max external ?
I know how to register an attribute using CLASS_ATTR_FLOAT and other macros, but I’m looking for a way to unregister this attribute.
Does anyone have any idea on how to do this ?


Apr 20 2012 | 5:45 am

Hi there,

if you check out the ext_obex.h file in the Max SDK you’ll see two functions:
object_deleteattr() and object_chuckattr().

If you simply want to unregister an attribute removing it from the namespace:
object_unregister() will do that for you.

Hope this helps

– Luigi

Apr 24 2012 | 1:09 pm

Thanks a lot !
I tried out these functions a bit, but I was left with a slight problem :
Class_attr adds an attribute to the instance of my class which was generated upon initialization (a t_class) with class_new, whereas object_chuckattr (or object_addattr for that matter) work on objects (t_object)
I messed a bit around with my code, and made an t_object instance of my class using object_new(CLASS_BOX, faustclasssym). I can create / remove attributes on this object, however I cannot "associate" them to my max class : the attributes I register do not show up in the list inside my Max patcher (as if my t_object wasn’t linked to my max class).
Do you have any idea how to deal with this ?

My purpose is that I want to make an external which allows to create or unregister dynamically attributes

Thanks again !

Apr 25 2012 | 3:21 pm

No one has a clue ?
My objective is to be able to add/remove dynamically attributes to an object.
So far, the only attributes which have actually "showed up" inside my patcher were the ones I added with class_addattr (or the CLASS_ADD_… macros), however it doesn’t seem these are dynamic.
Whereas it seems that even if I can create attributes with the object_addattr function (the returned error code is 0, so it should be fine), they don’t show up inside Max, so I can’t use them this way.

Apr 25 2012 | 6:47 pm

Ok, since nobody else will chime in…

it seems you might be confusing "class" and "object". Hierarchically a class is a higher entity than an object.
The Max API has functions to create attributes for classes and attributes for objects. A class is generally defined in the main() function. If you create an attribute for a class, then all objects belonging to that class will feature the same attribute. On the other hand, if you create attributes for an object, it’s absolutely correct that they won’t show up belonging to the class because they don’t. I think that’s what you mean when you say "they don’t show up inside Max". That’s the expected behavior. Object attributes only belong to THAT object instance of the mother class.
Remember that if you create/remove a dynamic class attribute, that will affect all the objects belonging to that class. If you create an object attribute Max won’t show it because Max only shows class attributes.

Now, that’s the theory… I am pretty sure that the Max API doesn’t even allow to create dynamic class attributes, so you are out of luck there. So your only possibility is to create object attributes which – as you have seen – they don’t show up in Max.

I suspect that you might need to come up with a different mechanism (probably a custom mechanism) to display your object attributes. This way your attributes can be showed by Max, but they are still local to one object instance. One idea that comes to mind is using a popup menu that opens when you click (or double-click) on the object and only shows the attributes local to that object instance. If you check out the jgraphics.h API you will find facilities to create custom popup menus. I am just thinking out loud here… your mileage might vary.

Hope this helps at least a little bit.

– Luigi

Apr 26 2012 | 8:30 am

Thanks, I’m going to try this out.
The final objective is to create an external able to dynamically create and delete attributes, inlets and outlets. I’ve already seen methods which could supposedly work for inlets/outlets (inlet_append, inlet_delete, even though they are currently undocumented in the API).
Something a bit akin to Gen in fact, which can resize dynamically its inlet/outlet structure upon changing the gen subpatch.
Do you think it could be possible (even by creating a custom mechanism) ?


Apr 26 2012 | 8:43 am

Yes, I think it’s totally possible.
Good luck with your project.


– Luigi

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

Forums > Dev