Maya API Test
- import maya.OpenMaya as OpenMaya
- import maya.OpenMayaMPx as OpenMayaMPx
- sl = OpenMaya.MSelectionList()
- OpenMaya.MGlobal.getActiveSelectionList(sl)
- itersl = OpenMaya.MItSelectionList(sl, OpenMaya.MFn.kDagNode)
- dagPath = OpenMaya.MDagPath()
- dagFn = OpenMaya.MFnDagNode()
- while (not itersl.isDone()):
- itersl.getDagPath(dagPath)
- try:
- dagPath.extendToShape() # get shaper node
- except:
- pass
- dagObject = dagPath.node()
- dagFn.setObject(dagObject)
- name = dagFn.name()
- print 'Get the Dag Node Name Is :', name
- itersl.next()
- # create MFnMeshVertex
- object = OpenMaya.MItMeshVertex(dagPath)
- while (not object.isDone()):
- print object.position().x
- object.next()
http://ewertb.soundlinker.com/api/api.php
https://nccastaff.bournemouth.ac.uk/jmacey/RobTheBloke/www/mayaapi.html
https://nccastaff.bournemouth.ac.uk/jmacey/RobTheBloke/www/research/maya/mfnanimcurve.htm
Python PIP升级:
python -m pip install --upgrade pip
Event in Maya Api to capture currentTime / frame change
http://download.autodesk.com/us/maya/2009help/API/class_m_event_message.html#c038e5bbbfc19b2772d1a01220b570c0
- // ...
- // Our callback Id array to
- // store the Ids of all our callbacks
- // for later removal
- MCallbackIdArray myCallbackIds;
- // This is where the actual adding callback happens
- // We register our callback to the "timeChanged" event
- MCallbackId callbackId = MEventMessage::addEventCallback("timeChanged", (MMessage::MBasicFunction) MySampleCmd::userCB);
- // ...
- if(myCallbackIds.length() != )
- // Make sure we remove all the callbacks we added
- stat = MEventMessage::removeCallbacks(myCallbackIds);
- class MySampleCmd : public MPxCommand {
- public:
- MySampleCmd();
- virtual ~MySampleCmd();
- // Our callback - implemented as a static method
- static void userCB(void* clientData);
- MStatus doIt( const MArgList& );
- MStatus redoIt();
- MStatus undoIt();
- bool isUndoable() const;
- static void* creator();
- public:
- // Our callback Id array to
- // store the Ids of all our callbacks
- // for later removal
- MCallbackIdArray myCallbackIds;
- };
cmd.h
- // Clearing our callback Id array
- // for housekeeping
- myCallbackIds.clear();
- }
- // Destructor
- MySampleCmd::~MySampleCmd() {
- // Make sure we remove all the callbacks we added
- // Failing to do so will result in fatal error
- if(myCallbackIds.length() != )
- // Remove the MEventMessage callback
- MEventMessage::removeCallbacks(myCallbackIds);
- }
- MStatus MySampleCmd::redoIt() {
- // This is where the actual adding callback happens
- // We register our callback to the "timeChanged" event
- MCallbackId callbackId = MEventMessage::addEventCallback("timeChanged", (MMessage::MBasicFunction) MySampleCmd::userCB);
- // Append the newly added callback's ID to our list of callback ids
- // for future removal
- myCallbackIds.append(callbackId);
- return MS::kSuccess;
- }
- MStatus MySampleCmd::undoIt() {
- MStatus stat;
- if(myCallbackIds.length() != )
- // Make sure we remove all the callbacks we added
- stat = MEventMessage::removeCallbacks(myCallbackIds);
- return stat;
- }
- // Our callback function
- void SafeSelect::userCB(void* clientData) {
- MGlobal::displayInfo( "Callback userCB called!\n" );
- return;
- }
cmd.cpp
Get Points At Time
- MStatus myPlugIn::GetPointsAtTime(
- const MDagPath& dagPath,
- const MTime& mayaTime,
- MPointArray& points )
- {
- MStatus status = MS::kSuccess;
- points.clear();
- MFnMesh fnMesh;
- // Move Maya to current frame
- MGlobal::viewFrame( mayaTime );
- // You MUST reinitialize the function set after changing time!
- fnMesh.setObject( dagPath );
- // Get vertices at this time
- status = fnMesh.getPoints( points );
- return status;
- }
- MStatus myPlugIn::doIt( const MArgList& args )
- {
- MStatus status = MS::kSuccess;
- MDagPath dagPath;
- // .. determing dagPath from current selection, or whatever .. //
- MPointArray points;
- MTime currentTime, maxTime;
- // Get start- and end-frame from Maya
- currentTime = MAnimControl::minTime();
- maxTime = MAnimControl::maxTime();
- // Iterate through time
- while ( currentTime <= maxTime )
- {
- // Get vertices at this time
- status = GetPointsAtTime( dagPath, currentTime, points );
- // .. do something with the points here .. //
- // Advance by one frame
- currentTime++;
- }
- return status;
- }
Use the Get points at time
M3dView Capture
(1)
- #Import api modules
- import maya.OpenMaya as api
- import maya.OpenMayaUI as apiUI
- #Grab the last active 3d viewport
- view = apiUI.M3dView.active3dView()
- print view
- #read the color buffer from the view, and save the MImage to disk
- image = api.MImage()
- view.readColorBuffer(image, True)
- image.writeToFile('C:/test.jpg', 'jpg')
(2)
- import os
- import maya.OpenMaya as mod_om
- import maya.OpenMayaUI as mod_om_ui
- import maya.cmds as mod_mc
- import maya.mel as mel
- view = mod_om_ui.M3dView.active3dView()
- image_ = mod_om.MImage()
- for frame in range(1,11):
- # Change the frame number
- mod_mc.currentTime(frame)
- for obj in ['headMouthScp_geo', 'pSphere1']:
- # Isolate the object, so that only that particular object is seen
- # Also Tried with turning off/on the visibility
- mod_mc.select(obj)
- mod_mc.isolateSelect('modelPanel4',s=1)
- mod_mc.isolateSelect( 'modelPanel4', addSelected=True )
- #mod_mc.select(obj)
- #mod_mc.isolateSelect( 'modelPanel4', addSelected=True )
- mod_mc.setAttr(obj + '.visibility', 0)
- mod_mc.setAttr(obj + '.visibility', 1)
- # Refresh the scene
- view.refresh()
- mod_mc.refresh()
- # Read Color Buffer
- view.readColorBuffer(image_, True)
- # Write The Color Buffer
- image_.resize(640, 480)
- image_.writeToFile('C:/Temp/Frame_Buffer_%s_%d.bmp' % (obj, frame), 'bmp')
- mod_mc.select(clear=True)
- mod_mc.isolateSelect( 'modelPanel4', state=0 )
(3)cmds context
- import contextlib
- @contextlib.contextmanager
- def solo_renderable(solo_cam):
- # Disable all cameras as renderable
- # and store the original states
- cams = cmds.ls(type='camera')
- states = {}
- for cam in cams:
- states[cam] = mc.getAttr(cam + '.rnd')
- cmds.setAttr(cam + '.rnd', 0)
- # Change the solo cam to renderable
- cmds.setAttr(solo_cam + '.rnd', 1)
- try:
- yield
- finally:
- # Revert to original state
- for cam, state in states.items():
- cmds.setAttr(cam + '.rnd', state)
- with solo_cam('myCamShape'):
- cmds.playblast()
OGL Render in backend:
- import sys
- import os
- import contextlib
- try:
- import maya.cmds as cmds
- import maya.standalone as standalone
- standalone.initialize(name='python')
- except:
- raise ImportError
- def openScene(openPath):
- sceneName = os.path.basename(openPath[:-3])
- print "opening path.................\n"
- cmds.file(openPath, open=True)
- if __name__ == "__main__":
- openScene(r"c:/test2.ma")
- cmds.hwRenderLoad()
- for x in xrange(1,68,1):
- print cmds.ogsRender(width=1280,height=720,cam='camera1',frame = x)
(4)code snipts
<1>
import maya.cmds as cmds
cmds.ls(*cmds.listHistory (mynode), type = 'animCurve' )
<2> iter by type
- import maya.OpenMaya as om
- import maya.OpenMayaMPx as omp
- import maya.OpenMayaAnim as oma
- # just loop the animation curve
- it = om.MItDependencyNodes(om.MFn.kMesh)
- while not it.isDone():
- aobj = it.item()
- print aobj
- #aniCur = oma.MFnAnimCurve(aobj)
- #print aniCur.name()
- it.next()
(5) save two matrixs into a float* array
- // MMatrix stores double values, but I want floating point values on the GPU so convert them here.
- unsigned int numFloat = ;
- float* temp = new float[numFloat];
- unsigned int curr = ;
- for(unsigned int row = ; row<; row++)
- {
- for(unsigned int column = ; column<; column++)
- {
- temp[curr++] = (float)omat(row, column);
- }
- }
- for(unsigned int row = ; row<; row++)
- {
- for(unsigned int column = ; column<; column++)
- {
- temp[curr++] = (float)omatinv(row, column);
- }
- }
in opencl use pointer offset
- __global const float4* matrices, //first matrix is offset matrix, second matrix is offset matrix inverse
- __global const float4* matrixInverse = &(matrices[]);
- __global const float4* matrix = matrices;
(6) command port eval scripts:
MEL:
- commandPort -stp "python" -n ":5055" ;
cmds.commandPort (n=':6328', stp='python')
other Python version:
- import socket
- maya = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- maya.connect(("127.0.0.1", 5055))
- maya.send("""maya.cmds.polySphere( radius=4 )""")
- The above code will create a new sphere in your currently running Maya. You can use any python terminal (doesn't have to be mayapy).
- (If you're running python3, the last command will produce an error until you change it to:
- maya.send(bytes("""maya.cmds.polySphere( radius=4 )""", 'UTF-8'))
Maya API Test的更多相关文章
- Maya Api笔记 - How polygons are handled internally
为加深记忆和理解Maya的Polygon,尝试利用空闲时间翻译Maya Api文档相关章节. How polygons are handled internally - 多边形是如何在内部处理的
- Maya API编程快速入门
一.Maya API编程简介 Autodesk® Maya® is an open product. This means that anyone outside of Autodesk can ch ...
- 一、Maya API简介
#include <maya/MSimple.h> #include <maya/MIOStream.h> DeclareSimpleCommand( hello, " ...
- Building GCC 4.1.2 in CentOS 7 for Maya API development
Following the official guid: http://help.autodesk.com/cloudhelp/2015/ENU/Maya-SDK/files/Setting_up_y ...
- [zz]Maya C++ API Programming Tips
Maya C++ API Programming Tips source : http://wanochoi.com/?page_id=1588 How to handle the multiple ...
- Debugging Maya Plugin(C++) with CodeBlocks in Linux
My system is CentOS7 x64, Maya2015 x64 for Linux. - Make sure that your project is built with flag - ...
- 十二、shapes
1. The control points are attributes on the shape which are usually arrays of points. Control points ...
- 六、通过插件如何创建自己的MEL command
1. MAYA API支持不同类型的plugin (1)Command Plugin——扩充MEL命令 (2)Tool Commands——通过鼠标输出 (3)DG plugin——对场景添加新的操作 ...
- osg 添加 fbx插件 osg中编译fbx
使用osg加载fbx模型,需要自己编译fbx插件,编译流程与插件使用案例如下 代码地址:https://github.com/shelltdf/osgFBX CMake Error: The foll ...
随机推荐
- 关于python的315道题
python基础篇 为什么学习Python? 通过什么途径学习的Python? Python和Java.PHP.C.C#.C++等其他语言的对比? 简述解释型和编译型编程语言? Python解释器种类 ...
- jmeter中判断数据库是否存在相应的记录
jmeter判断数据库中是否存在相应记录可以使用count 配合case,然后再加个断言,后面用 变量JMeterThread.last_sample_ok来判断是否存在相应记录 select cas ...
- sklearn-数据预处理scale
sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003& ...
- Linux记录-告警脚本
#!/bin/bash export JAVA_HOME=/app/jdk/jdk1.8.0_92 export HADOOP_CONF_DIR=/home/hdfs/balancer/hadoop- ...
- JMeter:Dashboard Report自动生成测试报告的巧用和避坑
官网地址查阅:http://jmeter.apache.org/usermanual/generating-dashboard.html 最近在压测过程中使用 Generating Report Da ...
- HDU - 1542 Atlantis(线段树求面积并)
https://cn.vjudge.net/problem/HDU-1542 题意 求矩形的面积并 分析 点为浮点数,需要离散化处理. 给定一个矩形的左下角坐标和右上角坐标分别为:(x1,y1).(x ...
- HTML第一耍 标题 段落 字体等标签
1.HTML标题的使用 <!doctype html> <html> <head> <title>文本标签演示</title> </h ...
- 转---Python——numpy random类
numpy中利用random类获取随机数. numpy.random.random() 生成随机浮点数 默认为生成一个随机的浮点数,范围是在0.0~1.0之间,也可以通过参数size设置返回数据的si ...
- nodejs 下载远程图片
var express = require('express'); var request = require('request');var http = require('http');var ur ...
- Iterator迭代器
java.util.Iterator 迭代器iterator,是一个接口,不能够直接使用,需要使用Iterator接口的实现类对象,而获取实现类的的对象的方式为: Collection接口中有一个方法 ...