Why use InitAttr()? [SOLVED]

On 30/10/2014 at 18:02, xxxxxxxx wrote:

Why should one use InitAttr() and subscripting to access object data over GetDataInstance() and then the Get/Set() type specific methods (ie, GetBool())?

I keep seeing plugins that do either or, sometimes both. There will be one plugin that calls InitAttr() in the Init() method to setup subscripting access (I'm assuming that's what InitAttr() does, since if you don't do that then any attempts to access that data via subscripting just return "None" instead), then access all the object data like obj[c4d.SomeObjectParameter] = 40.0.

Then there's plugins that just forego this and call bc = op.GetDataInstance() and access the data via the various type specific getters and setters, like bc.SetBool(c4d.SomeObjectParamter, False).

What's the difference? Why should I use one or the other? It seems like MAXON's examples tend to access things via GetDataInstance() rather then subscripting. Various third party plugins tend to use the alternative though, presumably because it's less typing.


On 31/10/2014 at 02:22, xxxxxxxx wrote:


using InitAttr() you make the sure that a parameter is initiated with an element of the correct type and a default value.

When you handle an object in Cinema 4D you can't be sure if a value is stored in it's BaseContainer or somewhere else. So when you are handling a BaseContainer and you know the value you want is stored in that BaseContainer (like in your own object etc.) it's fine to access the BaseContainer.

But when you handle another object you should ask the object for the parameter, not it's BaseContainer. This way you ensure that the object can react to this request properly and can deliver the correct value. Please read this thread about the issue.

Also, since Release 16 Python supports SetParameter() and GetParameter(). Using this functions you can now set different flags.

best wishes,