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. 洛谷P2770 双路DP // 网络流

    https://www.luogu.org/problemnew/show/P2770 第一眼看过去,觉得这不是一个经典的双路DP模型吗,将一条过去一条回来互不相交的路径看作是起点出发了两条路径一起走 ...

  2. POJ1821 单调队列//ST表 优化dp

    http://poj.org/problem?id=1821 当我们在考虑内层循环j以及决策k的时候,我们可以把外层变量i看作定值,以此来优化dp状态转移方程. 题意 有n个工人准备铺m个连续的墙,每 ...

  3. Java Web之JSP

    什么是JSP? JSP就是一个可以写Java代码的HTML页面 JSP是什么? JSP是Servlet,JSP的本质就是Servlet Tomcat的web.xml文件下有这样几段代码: 看到下面的通 ...

  4. laravel 5.4 fopen(): Filename cannot be empty

    1.出错的报错信息(我在用laravel5.4文件上传时候出错的) laravel 5.4 fopen(): Filename cannot be empty 2.解决的方法 在php.ini中修改临 ...

  5. Linux 内核中的数据结构:基数树(radix tree)

    转自:https://www.cnblogs.com/wuchanming/p/3824990.html   基数(radix)树 Linux基数树(radix tree)是将指针与long整数键值相 ...

  6. jQuery使用(八):运动方法

    show().hide().toggle() 参数:null或(duration,easing,callblack) fadeIn().fadeout().fadeToggle().fadeTo() ...

  7. 【1】【leetcode-79】 单词搜索

    (典型dfs,知道思想写错) 给定一个二维网格和一个单词,找出该单词是否存在于网格中. 单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格.同一个单 ...

  8. 29. SpringBoot Redis 非注解

    1. 引入依赖 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spr ...

  9. Rootkit介绍

    Rootkit 是一种特殊类型的 malware(恶意软件). Rootkit 之所以特殊是因为您不知道它们在做什么事情.Rootkit 基本上是无法检测到的,而且几乎不能删除它们. 虽然检测工具在不 ...

  10. webpack学习笔记——打包js

    1.新建一个入口js文件,如entry.js,代码如下: document.write("It works.") 2.然后编译 entry.js 并打包到 bundle.js(会自 ...