1. import maya.OpenMaya as OpenMaya
  2. import maya.OpenMayaMPx as OpenMayaMPx
  3.  
  4. sl = OpenMaya.MSelectionList()
  5. OpenMaya.MGlobal.getActiveSelectionList(sl)
  6. itersl = OpenMaya.MItSelectionList(sl, OpenMaya.MFn.kDagNode)
  7.  
  8. dagPath = OpenMaya.MDagPath()
  9. dagFn = OpenMaya.MFnDagNode()
  10.  
  11. while (not itersl.isDone()):
  12. itersl.getDagPath(dagPath)
  13. try:
  14. dagPath.extendToShape() # get shaper node
  15. except:
  16. pass
  17. dagObject = dagPath.node()
  18. dagFn.setObject(dagObject)
  19. name = dagFn.name()
  20. print 'Get the Dag Node Name Is :', name
  21.  
  22. itersl.next()
  23.  
  24. # create MFnMeshVertex
  25. object = OpenMaya.MItMeshVertex(dagPath)
  26. while (not object.isDone()):
  27. print object.position().x
  28. 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

  1. // ...
  2.  
  3. // Our callback Id array to
  4. // store the Ids of all our callbacks
  5. // for later removal
  6. MCallbackIdArray myCallbackIds;
  7.  
  8. // This is where the actual adding callback happens
  9. // We register our callback to the "timeChanged" event
  10. MCallbackId callbackId = MEventMessage::addEventCallback("timeChanged", (MMessage::MBasicFunction) MySampleCmd::userCB);
  11.  
  12. // ...
  13.  
  14. if(myCallbackIds.length() != )
  15. // Make sure we remove all the callbacks we added
  16. stat = MEventMessage::removeCallbacks(myCallbackIds);
  1. class MySampleCmd : public MPxCommand {
  2. public:
  3. MySampleCmd();
  4. virtual ~MySampleCmd();
  5.  
  6. // Our callback - implemented as a static method
  7. static void userCB(void* clientData);
  8.  
  9. MStatus doIt( const MArgList& );
  10. MStatus redoIt();
  11. MStatus undoIt();
  12. bool isUndoable() const;
  13. static void* creator();
  14.  
  15. public:
  16.  
  17. // Our callback Id array to
  18. // store the Ids of all our callbacks
  19. // for later removal
  20. MCallbackIdArray myCallbackIds;
  21. };

cmd.h

  1. // Clearing our callback Id array
  2. // for housekeeping
  3. myCallbackIds.clear();
  4. }
  5.  
  6. // Destructor
  7. MySampleCmd::~MySampleCmd() {
  8.  
  9. // Make sure we remove all the callbacks we added
  10. // Failing to do so will result in fatal error
  11. if(myCallbackIds.length() != )
  12.  
  13. // Remove the MEventMessage callback
  14. MEventMessage::removeCallbacks(myCallbackIds);
  15. }
  16.  
  17. MStatus MySampleCmd::redoIt() {
  18.  
  19. // This is where the actual adding callback happens
  20. // We register our callback to the "timeChanged" event
  21. MCallbackId callbackId = MEventMessage::addEventCallback("timeChanged", (MMessage::MBasicFunction) MySampleCmd::userCB);
  22.  
  23. // Append the newly added callback's ID to our list of callback ids
  24. // for future removal
  25. myCallbackIds.append(callbackId);
  26. return MS::kSuccess;
  27. }
  28.  
  29. MStatus MySampleCmd::undoIt() {
  30. MStatus stat;
  31. if(myCallbackIds.length() != )
  32. // Make sure we remove all the callbacks we added
  33. stat = MEventMessage::removeCallbacks(myCallbackIds);
  34. return stat;
  35. }
  36.  
  37. // Our callback function
  38. void SafeSelect::userCB(void* clientData) {
  39. MGlobal::displayInfo( "Callback userCB called!\n" );
  40. return;
  41. }

cmd.cpp

Get Points At Time

  1. MStatus myPlugIn::GetPointsAtTime(
  2. const MDagPath& dagPath,
  3. const MTime& mayaTime,
  4. MPointArray& points )
  5. {
  6. MStatus status = MS::kSuccess;
  7.  
  8. points.clear();
  9.  
  10. MFnMesh fnMesh;
  11.  
  12. // Move Maya to current frame
  13. MGlobal::viewFrame( mayaTime );
  14.  
  15. // You MUST reinitialize the function set after changing time!
  16. fnMesh.setObject( dagPath );
  17.  
  18. // Get vertices at this time
  19. status = fnMesh.getPoints( points );
  20.  
  21. return status;
  22. }
  1. MStatus myPlugIn::doIt( const MArgList& args )
  2. {
  3. MStatus status = MS::kSuccess;
  4.  
  5. MDagPath dagPath;
  6.  
  7. // .. determing dagPath from current selection, or whatever .. //
  8.  
  9. MPointArray points;
  10.  
  11. MTime currentTime, maxTime;
  12.  
  13. // Get start- and end-frame from Maya
  14. currentTime = MAnimControl::minTime();
  15. maxTime = MAnimControl::maxTime();
  16.  
  17. // Iterate through time
  18. while ( currentTime <= maxTime )
  19. {
  20. // Get vertices at this time
  21. status = GetPointsAtTime( dagPath, currentTime, points );
  22.  
  23. // .. do something with the points here .. //
  24.  
  25. // Advance by one frame
  26. currentTime++;
  27. }
  28.  
  29. return status;
  30. }

Use the Get points at time

M3dView Capture

(1)

  1. #Import api modules
  2. import maya.OpenMaya as api
  3. import maya.OpenMayaUI as apiUI
  4.  
  5. #Grab the last active 3d viewport
  6. view = apiUI.M3dView.active3dView()
  7. print view
  8.  
  9. #read the color buffer from the view, and save the MImage to disk
  10. image = api.MImage()
  11. view.readColorBuffer(image, True)
  12. image.writeToFile('C:/test.jpg', 'jpg')

(2)

  1. import os
  2.  
  3. import maya.OpenMaya as mod_om
  4. import maya.OpenMayaUI as mod_om_ui
  5. import maya.cmds as mod_mc
  6. import maya.mel as mel
  7.  
  8. view = mod_om_ui.M3dView.active3dView()
  9. image_ = mod_om.MImage()
  10.  
  11. for frame in range(1,11):
  12. # Change the frame number
  13. mod_mc.currentTime(frame)
  14. for obj in ['headMouthScp_geo', 'pSphere1']:
  15.  
  16. # Isolate the object, so that only that particular object is seen
  17. # Also Tried with turning off/on the visibility
  18. mod_mc.select(obj)
  19. mod_mc.isolateSelect('modelPanel4',s=1)
  20. mod_mc.isolateSelect( 'modelPanel4', addSelected=True )
  21. #mod_mc.select(obj)
  22. #mod_mc.isolateSelect( 'modelPanel4', addSelected=True )
  23. mod_mc.setAttr(obj + '.visibility', 0)
  24. mod_mc.setAttr(obj + '.visibility', 1)
  25.  
  26. # Refresh the scene
  27. view.refresh()
  28. mod_mc.refresh()
  29.  
  30. # Read Color Buffer
  31. view.readColorBuffer(image_, True)
  32.  
  33. # Write The Color Buffer
  34. image_.resize(640, 480)
  35. image_.writeToFile('C:/Temp/Frame_Buffer_%s_%d.bmp' % (obj, frame), 'bmp')
  36.  
  37. mod_mc.select(clear=True)
  38. mod_mc.isolateSelect( 'modelPanel4', state=0 )

(3)cmds context

  1. import contextlib
  2.  
  3. @contextlib.contextmanager
  4. def solo_renderable(solo_cam):
  5.  
  6. # Disable all cameras as renderable
  7. # and store the original states
  8. cams = cmds.ls(type='camera')
  9. states = {}
  10. for cam in cams:
  11. states[cam] = mc.getAttr(cam + '.rnd')
  12. cmds.setAttr(cam + '.rnd', 0)
  13.  
  14. # Change the solo cam to renderable
  15. cmds.setAttr(solo_cam + '.rnd', 1)
  16.  
  17. try:
  18. yield
  19. finally:
  20. # Revert to original state
  21. for cam, state in states.items():
  22. cmds.setAttr(cam + '.rnd', state)
  23.  
  24. with solo_cam('myCamShape'):
  25. cmds.playblast()

OGL Render in backend:

  1. import sys
  2. import os
  3. import contextlib
  4.  
  5. try:
  6. import maya.cmds as cmds
  7. import maya.standalone as standalone
  8.  
  9. standalone.initialize(name='python')
  10. except:
  11. raise ImportError
  12.  
  13. def openScene(openPath):
  14. sceneName = os.path.basename(openPath[:-3])
  15. print "opening path.................\n"
  16. cmds.file(openPath, open=True)
  17.  
  18. if __name__ == "__main__":
  19. openScene(r"c:/test2.ma")
  20. cmds.hwRenderLoad()
  21.  
  22. for x in xrange(1,68,1):
  23. 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

  1. import maya.OpenMaya as om
  2. import maya.OpenMayaMPx as omp
  3. import maya.OpenMayaAnim as oma
  4.  
  5. # just loop the animation curve
  6. it = om.MItDependencyNodes(om.MFn.kMesh)
  7.  
  8. while not it.isDone():
  9. aobj = it.item()
  10. print aobj
  11. #aniCur = oma.MFnAnimCurve(aobj)
  12. #print aniCur.name()
  13.  
  14. it.next()

(5) save two matrixs into a float* array

  1. // MMatrix stores double values, but I want floating point values on the GPU so convert them here.
  2. unsigned int numFloat = ;
  3. float* temp = new float[numFloat];
  4. unsigned int curr = ;
  5. for(unsigned int row = ; row<; row++)
  6. {
  7. for(unsigned int column = ; column<; column++)
  8. {
  9. temp[curr++] = (float)omat(row, column);
  10. }
  11. }
  12. for(unsigned int row = ; row<; row++)
  13. {
  14. for(unsigned int column = ; column<; column++)
  15. {
  16. temp[curr++] = (float)omatinv(row, column);
  17. }
  18. }

in opencl use pointer offset

  1. __global const float4* matrices, //first matrix is offset matrix, second matrix is offset matrix inverse
  2. __global const float4* matrixInverse = &(matrices[]);
  3. __global const float4* matrix = matrices;

(6) command port eval scripts:

MEL:

  1. commandPort -stp "python" -n ":5055" ;
  1. cmds.commandPort (n=':6328', stp='python')

other Python version:

  1. import socket
  2. maya = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  3. maya.connect(("127.0.0.1", 5055))
  4. maya.send("""maya.cmds.polySphere( radius=4 )""")
  5. 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).
  6.  
  7. (If you're running python3, the last command will produce an error until you change it to:
  8.  
  9. maya.send(bytes("""maya.cmds.polySphere( radius=4 )""", 'UTF-8'))

Maya API Test的更多相关文章

  1. Maya Api笔记 - How polygons are handled internally

    为加深记忆和理解Maya的Polygon,尝试利用空闲时间翻译Maya Api文档相关章节. How polygons are handled internally - 多边形是如何在内部处理的

  2. Maya API编程快速入门

    一.Maya API编程简介 Autodesk® Maya® is an open product. This means that anyone outside of Autodesk can ch ...

  3. 一、Maya API简介

    #include <maya/MSimple.h> #include <maya/MIOStream.h> DeclareSimpleCommand( hello, " ...

  4. 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 ...

  5. [zz]Maya C++ API Programming Tips

    Maya C++ API Programming Tips source : http://wanochoi.com/?page_id=1588 How to handle the multiple ...

  6. 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 - ...

  7. 十二、shapes

    1. The control points are attributes on the shape which are usually arrays of points. Control points ...

  8. 六、通过插件如何创建自己的MEL command

    1. MAYA API支持不同类型的plugin (1)Command Plugin——扩充MEL命令 (2)Tool Commands——通过鼠标输出 (3)DG plugin——对场景添加新的操作 ...

  9. osg 添加 fbx插件 osg中编译fbx

    使用osg加载fbx模型,需要自己编译fbx插件,编译流程与插件使用案例如下 代码地址:https://github.com/shelltdf/osgFBX CMake Error: The foll ...

随机推荐

  1. 关于python的315道题

    python基础篇 为什么学习Python? 通过什么途径学习的Python? Python和Java.PHP.C.C#.C++等其他语言的对比? 简述解释型和编译型编程语言? Python解释器种类 ...

  2. jmeter中判断数据库是否存在相应的记录

    jmeter判断数据库中是否存在相应记录可以使用count 配合case,然后再加个断言,后面用 变量JMeterThread.last_sample_ok来判断是否存在相应记录 select cas ...

  3. sklearn-数据预处理scale

    sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003& ...

  4. Linux记录-告警脚本

    #!/bin/bash export JAVA_HOME=/app/jdk/jdk1.8.0_92 export HADOOP_CONF_DIR=/home/hdfs/balancer/hadoop- ...

  5. JMeter:Dashboard Report自动生成测试报告的巧用和避坑

    官网地址查阅:http://jmeter.apache.org/usermanual/generating-dashboard.html 最近在压测过程中使用 Generating Report Da ...

  6. HDU - 1542 Atlantis(线段树求面积并)

    https://cn.vjudge.net/problem/HDU-1542 题意 求矩形的面积并 分析 点为浮点数,需要离散化处理. 给定一个矩形的左下角坐标和右上角坐标分别为:(x1,y1).(x ...

  7. HTML第一耍 标题 段落 字体等标签

    1.HTML标题的使用 <!doctype html> <html> <head> <title>文本标签演示</title> </h ...

  8. 转---Python——numpy random类

    numpy中利用random类获取随机数. numpy.random.random() 生成随机浮点数 默认为生成一个随机的浮点数,范围是在0.0~1.0之间,也可以通过参数size设置返回数据的si ...

  9. nodejs 下载远程图片

    var express = require('express'); var request = require('request');var http = require('http');var ur ...

  10. Iterator迭代器

    java.util.Iterator 迭代器iterator,是一个接口,不能够直接使用,需要使用Iterator接口的实现类对象,而获取实现类的的对象的方式为: Collection接口中有一个方法 ...