Skip to content
/ attribs Public

An experimental Python library for creating Maya Attributes

License

Notifications You must be signed in to change notification settings

tahv/attribs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

attribs

An experimental Python library for creating Maya Attributes.

Installation

Install attribs with pip:

pip install maya-attribs

Quickstart

Use attribs.add_attribute to create an new attributes on an OpenMaya.MFnDependencyNode. This function also returns the newly created OpenMaya.MPlug.

from maya import cmds
from maya.api import OpenMaya
import attribs

def create_node(node_type: str) -> OpenMaya.MObject:
    name = cmds.createNode(node_type)
    return OpenMaya.MSelectionList().add(name).getDependNode(0)

node = OpenMaya.MFnDependencyNode(create_node("transform"))
modifier = OpenMaya.MDGModifier()

attribute = attribs.Bool("foo", default=False)

plug = attribs.add_attribute(node, attribute, modifier=modifier)

Set attribute flags either as keyword argument or later as properties.

from maya import cmds
from maya.api import OpenMaya
import attribs

def create_node(node_type: str) -> OpenMaya.MObject:
    name = cmds.createNode(node_type)
    return OpenMaya.MSelectionList().add(name).getDependNode(0)

node = OpenMaya.MFnDependencyNode(create_node("transform"))
modifier = OpenMaya.MDGModifier()

attribute = attribs.Double3(
    "MyDouble", 
    default=(1.0, 2.0, 3.0), 
    channel_box=True,
)
attribute.keyable = True

plug = attribs.add_attribute(node, attribute, modifier=modifier)

Compounds are also supported.

from maya import cmds
from maya.api import OpenMaya
import attribs

def create_node(node_type: str) -> OpenMaya.MObject:
    name = cmds.createNode(node_type)
    return OpenMaya.MSelectionList().add(name).getDependNode(0)

node = OpenMaya.MFnDependencyNode(create_node("transform"))
modifier = OpenMaya.MDGModifier()

attribute = attribs.Compound("foo")
attribute.append(attribs.Bool("bar"))
attribute.append(attribs.String("baz"))

plug = attribs.add_attribute(node, attribute, modifier=modifier)

About

An experimental Python library for creating Maya Attributes

Topics

Resources

License

Stars

Watchers

Forks

Languages