OMC::AttributeList Class Reference

Detailed Description

Represents a list of attributes for a node, or subattributes of an attribute.

An AttributeList provides the attributes owned by the parent. In most cases, the AttributeList is provided by a Node via OMC::Node::attributes. Some attributes are complex and have subattributes, accessible from OMC::Attribute::subattributes.
The AttributeList allows for list iteration in for loops, indexed access with the list operator[int_idx], and named access with the map operator["name"]


Identify All Attributes Recursively on a Node

from ToonBoom import harmony #Import the Harmony Module
sess = harmony.session() #Get access to the Harmony session, this class.
proj = sess.project #Get the active session's currently loaded project.
scene = proj.scene #Get the top scene in the project.
node_path = "Top/Node"
node = scene.nodes[ node_path ]
if node:
#Start with the base node's list, and recursively look through each attributelist thereafter.
#A recursive function to look at all attributes in any attribute list, the node's attributes, or subattributes.
def detail_all_attributes( attrblist, depth ):
for attrb in attrblist:
print( "%s %s -- %s"%( " "*depth, attrb.full_keyword, attrb.type ) )
if attrb.subattributes: #If this attribute has further subattributes, detail them too.
detail_all_attributes( attrb.subattributes, depth+1 )
#Start detailing the attributes. . .
detail_all_attributes(node.attributes, 0)
else:
print( "Unable to find the node : %s"%node_path )




Direct Access to an Attribute by Keyword

from ToonBoom import harmony #Import the Harmony Module
sess = harmony.session() #Get access to the Harmony session, this class.
proj = sess.project #Get the active session's currently loaded project.
scene = proj.scene #Get the top scene in the project.
peg_path = "Top/Peg"
peg = scene.nodes[ peg_path ]
if peg:
#Knowing that a peg has a PIVOT attribute, access it directly with the map operator:
pivot_attr = peg.attributes[ "PIVOT" ]
if pivot_attr:
#FOUND IT!
frame = 1
pivot_attr.set_value( frame, harmony.Point3d(3.0, 1.0, 0.0), False ) #Set the pivot at the attribute level.
print( "Set the Peg's Pivot at frame : %s"%(frame) )
else:
print( "Failed to find PIVOT attribute." )
#Also, sub attributes can be retrieved in two ways:
pivot_attr_x1 = peg.attributes["PIVOT.X"]
pivot_attr_x2 = peg.attributes["PIVOT"].subattributes["X"]
print( "These are equivalent: %s and %s"%(pivot_attr_x1.full_keyword, pivot_attr_x2.full_keyword) )
else:
print( "Unable to find the node : %s"%peg_path )

Public Member Functions

OMC::Attributeoperator[] (int idx)
 Provides the attribute at the given index. More...
 
OMC::Attributeoperator[] (QString &attribute_name)
 Provides the attribute at the given index. More...
 
bool contains (OMC::Attribute *) const
 Identifies if the list contains the attribute (or subattribute). More...
 
virtual std::vector< OMC::Attribute * > list () const override
 Converts the dynamic list into a static list of attribute objects. More...
 
OMC::Attributecreate_dynamic_attr (const QString &type, const QString &name, const QString &displayName, bool linkable)
 Creates a dynamic attribute on the node. More...
 
virtual void remove_dynamic_attr (const OMC::Attribute *attr)
 Removes a dynamic attribute from the node. More...
 

Member Function Documentation

◆ contains()

bool OMC::AttributeList::contains ( OMC::Attribute ) const

Identifies if the list contains the attribute (or subattribute).

Useful when identifying if an attribute is contained within an attribute list. This is also used with Python's built in in operator.

Check for Attribute in List

from ToonBoom import harmony #Import the Harmony Module
sess = harmony.session() #Get access to the Harmony session, this class.
proj = sess.project #Get the active session's currently loaded project.
scene = proj.scene #Get the top scene in the project.
peg_path = "Top/Peg"
peg = scene.nodes[ peg_path ]
if peg:
#Check for an Attribute that exists:
if "PIVOT" in peg.attributes:
print( "PIVOT EXISTS" )
else:
print( "PIVOT DOESNT EXISTS -- ERROR" )
#This is equivalent:
if peg.attributes.contains("PIVOT"):
print( "PIVOT EXISTS" )
else:
print( "PIVOT DOESNT EXISTS -- ERROR" )
if "DOESNT_EXIST" in peg.attributes:
print( "This really shouldn't exist. . ." )
else:
print( "This is expected.peg" )

◆ create_dynamic_attr()

OMC::Attribute* OMC::AttributeList::create_dynamic_attr ( const QString &  type,
const QString &  name,
const QString &  displayName,
bool  linkable 
)

Creates a dynamic attribute on the node.

Custom dynamic attributes can be added to nodes by the attribute list owned by the Node. These dynamic attributes behave as normal attributes, but can be added and removed as needed.

Parameters
type- The type of the dynamic attribute.
name- The name of the attribute.
displayName- The display name of the attribute.
linkable- Whether the attribute can be linked to a column.
Returns
Returns the newly-created dynamic Attribute.

Create a new Double Attribute

from ToonBoom import harmony #Import the Harmony Module
sess = harmony.session() #Get access to the Harmony session, this class.
proj = sess.project #Get the active session's currently loaded project.
scene = proj.scene #Get the top scene in the project.
node_path = "Top/Node"
node = scene.nodes[ node_path ]
if node:
attrbs = node.attributes
created_attribute = attrbs.create_dynamic_attr( "DOUBLE", "DYNAMIC_NAME", "DYNAMIC_DISPLAY", True )
if created_attribute:
print( "Created Dynamic Attribute: %s"%(created_attribute.full_keyword) )
created_attribute.set_value(1, 10, False)
else:
print( "Failed to create attribute." )
else:
print( "Node does not exist: %s"%(node_path) )

◆ list()

virtual std::vector<OMC::Attribute*> OMC::AttributeList::list ( ) const
overridevirtual

Converts the dynamic list into a static list of attribute objects.

By default, the AttributeList object is a dynamic list-type. This means that the object does not contain a persistent list, but behaves dynamically when a node is requested from it. Sometimes, a static list is preferred and this method will generate a static list of OMC::Attribute objects. Note, although the list is static, the objects within the list remain dynamic and refer to a node within the project.

◆ operator[]() [1/2]

OMC::Attribute* OMC::AttributeList::operator[] ( int  idx)

Provides the attribute at the given index.

Allows for index access to an Attribute.

Iterate over the Attribute List with Index

from ToonBoom import harmony #Import the Harmony Module
sess = harmony.session() #Get access to the Harmony session, this class.
proj = sess.project #Get the active session's currently loaded project.
scene = proj.scene #Get the top scene in the project.
node_path = "Top/Node"
node = scene.nodes[ node_path ]
attribs = node.attributes
attrib_size = len(attribs)
for idx in range(attrib_size): #Instead of iterating over the object, iterate over the list with an index.
attrb = attribs[idx]
print( "Attribute at Index %s: %s"%(idx, attrb.full_keyword) )

◆ operator[]() [2/2]

OMC::Attribute* OMC::AttributeList::operator[] ( QString &  attribute_name)

Provides the attribute at the given index.

Allows for index access to an Attribute.

Direct Access to an Attribute by Keyword

from ToonBoom import harmony #Import the Harmony Module
sess = harmony.session() #Get access to the Harmony session, this class.
proj = sess.project #Get the active session's currently loaded project.
scene = proj.scene #Get the top scene in the project.
peg_path = "Top/Peg"
peg = scene.nodes[ peg_path ]
if peg:
#Knowing that a peg has a PIVOT attribute, access it directly with the map operator:
pivot_attr = peg.attributes[ "PIVOT" ]
if pivot_attr:
#FOUND IT!
frame = 1
pivot_attr.set_value( frame, harmony.Point3d(3.0, 1.0, 0.0), False ) #Set the pivot at the attribute level.
print( "Set the Peg's Pivot at frame : %s"%(frame) )
else:
print( "Failed to find PIVOT attribute." )
#Also, sub attributes can be retrieved in two ways:
pivot_attr_x1 = peg.attributes["PIVOT.X"]
pivot_attr_x2 = peg.attributes["PIVOT"].subattributes["X"]
print( "These are equivalent: %s and %s"%(pivot_attr_x1.full_keyword, pivot_attr_x2.full_keyword) )
else:
print( "Unable to find the node : %s"%peg_path )

◆ remove_dynamic_attr()

virtual void OMC::AttributeList::remove_dynamic_attr ( const OMC::Attribute attr)
virtual

Removes a dynamic attribute from the node.

Removes the dynamic attribute provided as an argument, if it exists in this list. Throws an error if there is an issue otherwise.

Parameters
attr- The name of the attribute.
Inheritance diagram for OMC::AttributeList:
Collaboration diagram for OMC::AttributeList: