< Previous | Contents | Next >

Attributes

Attributes store information about the capabilities of a certain type, as well as some common flags that contribute to the object’s state.

For example, in the case of a Tool the attributes may include the typename of the object, its name in the composition, its abbreviation shown in the Toolbar, its PassThrough and selection state, etc.

Attributes have read access but it is not guaranteed that you can change all Attributes. So while it is possible to change the PassThrough-State of a tool, it makes no sense to change its type.

Each Operator Type will have a different set of Attributes depending on its type. You cannot add your own Attributes. Instead, use a mechanism like Image stream metadata or Object Data.

In order to access the Attributes, the GetAttrs() method can be used. As it is provided by the Object superclass, pretty much all objects can have Attributes. So GetAttrs() is a good place to look for functionality or data within an object.

image

==Merge1:GetAttrs()

-- dump all Tool Attributes

==Merge1.Blend:GetAttrs()

-- Inputs also have attributes

==Merge1:GetAttrs(“TOOLB_Locked”)

-- Only show the Locked status

If no argument is given, all Attributes are returned. It is also possible to supply a single tag string to narrow down the search.


The tags consist of a Type prefix, a character for the type, an underline and the Name of the Attribute. So for example most Attributes within a Tool have a TOOL prefix, Inputs INP, Compositions COMP etc.


image


The type character stands for:


S

String

B

Boolean

N

Number (float)

I

Integer

H

Handle

NT

Number Table

IT

Integer Table

ST

String Table

BT

Boolean Table


In our example, TOOLB_Locked stands for a Tool Attribute of type boolean with the name “Locked.”

Attributes can be changed by using SetAttrs({}). The supplied table is required to have the Tag as key and the new value as value. Multiple attributes can be changed at a time, however not all Attributes can be changed at all. The following example renames “Merge1” to “MyMerge” and locks the tool in one call:

Merge1:SetAttrs({TOOLS_Name = “MyMerge”, TOOLB_Locked = true})