Skip to main content

一个现代的maya python库

Project description

CPMel

一个现代的maya python库

ta有以下设计目标

  1. 相对较快地初始化速度
  2. 易于与maya-api1、maya-api2交互
  3. 易于扩展
  4. 够用的性能

目录

快速开始

安装

注意下方的python是你的Python, 正常情况下可以直接通过python调用, 而Maya的python一般是"C:\Program Files\Autodesk\<Maya版本>\bin\mayapy.exe"

python -m pip install cpmel

在windows下maya的安装例子

注意:

  1. 请将Maya路径替换为自己的。
  2. 请使用cmd
"C:\Program Files\Autodesk\Maya2018\bin\mayapy.exe" -m pip install cpmel

测试

执行以下程序应当可以获得选择列表,如果正确那么恭喜你安装完成!

# -*-coding:utf-8 -*-
from __future__ import unicode_literals, print_function, division
import cpmel.cmds as cc

sel = cc.ls(sl=True)

使用教程

命令调用

获得选择列表

# -*-coding:utf-8 -*-
from __future__ import unicode_literals, print_function, division
import cpmel.cmds as cc

sel = cc.ls(sl=True)

创建关节

# -*-coding:utf-8 -*-
from __future__ import unicode_literals, print_function, division
import cpmel.cmds as cc

cc.select(cl=True)
jin = cc.joint()

创建UI

# -*-coding:utf-8 -*-
from __future__ import unicode_literals, print_function, division
import cpmel.cmds as cc

window_name = 'your_window_name'
if cc.window(window_name, ex=True):
    cc.deleteUI(window_name)
cc.window(window_name)
with cc.flowLayout():
    cc.button()
    cc.button()
    cc.button()
cc.showWindow()

与api交互

获得节点的函数集对象

# -*-coding:utf-8 -*-
from __future__ import unicode_literals, print_function, division
import cpmel.cmds as cc

node = cc.createNode('transform')
# api1版本的函数集对象
node.api1_m_fn()
# api2版本的函数集对象
node.api2_m_fn()

获得属性的MPlug对象

# -*-coding:utf-8 -*-
from __future__ import unicode_literals, print_function, division
import cpmel.cmds as cc

node = cc.createNode('transform')
attr = node.tx
# api1版本的
attr.api1_m_plug()
# api2版本的
attr.api2_m_plug()

一些其他的

# -*-coding:utf-8 -*-
from __future__ import unicode_literals, print_function, division
import cpmel.cmds as cc

node = cc.createNode('transform')

# api1版本
node.api1_m_fn_dependency_node()
node.api1_node_object()
node.api1_m_dag_path()
# api2版本
node.api2_m_fn_dependency_node()
node.api2_node_object()
node.api2_m_dag_path()

常用的对象方法

名称相关操作

# -*-coding:utf-8 -*-
from __future__ import unicode_literals, print_function, division
import cpmel.cmds as cc

node = cc.createNode('transform')
# 获得最短名称
node.name()
# 仅获得节点名称
node.node_name()
# 获得完整路径
node.full_path_name()

dag相关操作

# -*-coding:utf-8 -*-
from __future__ import unicode_literals, print_function, division
import cpmel.cmds as cc

node_a = cc.createNode('transform')
node_b = cc.createNode('transform')
node_c = cc.createNode('transform')

# 设置父对象
node_a.parent = node_b
# or node_a.set_parent(node_b)
# 获得父对象
print('获得父对象', node_a.parent)
# or node_a.get_parent()
# 添加子对象
node_c.add_child(node_b)
# 获得子对象
print('获得子对象', node_c.childs)
# or node_c.get_childs()

附加特性

属性相关操作

# -*-coding:utf-8 -*-
from __future__ import unicode_literals, print_function, division
import cpmel.cmds as cc

node = cc.createNode('transform')
# 获得属性
# 方法1
tx_attr = node.tx
# 方法2 ps: 在节点属性名称与对象属性冲突时可以使用这个
tx_attr = node.attr('tx')

# 读写属性
# 方法1
# 写
node['tx'] = 1.0
# 读
tx_val = node['tx']
# 方法2
# 写
node.tx.set_value(1.0)
# 读
tx_val = node.tx.get_value()

# 连接属性
# 方法1
node.tx >> node.ty
# 方法2
node.tx.connect(node.ty)
# 断开属性连接
node.tx.disconnect(node.ty)

版权说明

该项目签署了Apache-2.0 授权许可,详情请参阅 LICENSE

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cpmel-3.7.0.tar.gz (86.4 kB view details)

Uploaded Source

Built Distribution

cpmel-3.7.0-py2.py3-none-any.whl (89.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file cpmel-3.7.0.tar.gz.

File metadata

  • Download URL: cpmel-3.7.0.tar.gz
  • Upload date:
  • Size: 86.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for cpmel-3.7.0.tar.gz
Algorithm Hash digest
SHA256 55af03c06a112dfac0484d966f837da401d6b621f0635cf36f46058708bb9893
MD5 ff5a32d8465d9b49108f004cf2820990
BLAKE2b-256 6b3cf8c8534293ad37074bffbcf5d1c5413e6fbb16cd9765f33222a5c64bc49c

See more details on using hashes here.

File details

Details for the file cpmel-3.7.0-py2.py3-none-any.whl.

File metadata

  • Download URL: cpmel-3.7.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 89.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for cpmel-3.7.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 350c6362da9c1d08f2d31991583f2e20095a2dc134eba6d3ff76af57362f15bf
MD5 afd3c834849a1fcf0681278d127d7783
BLAKE2b-256 7840d1fdc722cec915dfcac56f5d97f10449a2f0356c8e3ec925a1c4c85d38ae

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page