oCmdResult = MCommandResult() MGlobal.executeCommand('currentTime -q', oCmdResult) scriptUtil = MScriptUtil() ptr = scriptUtil.asDoublePtr() oCmdResult.getResult(ptr) frame = scriptUtil.getDouble(ptr)executeCommand의 내용에 따라 그 결과 값을 가져오는 방법은 다르지만 이와 같은 방법으로 MScriptUtil을 사용할수 있다.
2011년 12월 13일 화요일
MScritUtil example - vol.2
2011년 12월 12일 월요일
MScritUtil example - vol.1
image = MImage() image.readFromFile( filename ) scriptUtil = MScriptUtil() widthPtr = scriptUtil.asUintPtr() heightPtr = scriptUtil.asUintPtr() scriptUtil.setUint( widthPrt, 0 ) scriptUtil.setUint( heightPtr, 0 ) image.getSize( widthPtr, heightPtr ) ix = scriptUtil.getUint( widthPtr ) iy = scriptUtil.getUint( heightPtr )
Python API 의 한계인가? vol.1
MPxLocatorNode를 만들때 OpenGL에 관한 내용이다.
C style
GLuint txid; glGenTextures(1, &txid);python style의 경우 opengl 라이브러리를 사용
txid = glGenTextures(1)Maya Python API에서는
glRenderer = MHardwareRenderer.theRenderer() glFT = glRenderer.glFunctionTable() txid = glFT.glGenTextures( 1 )위의 경우 // Error: TypeError: MGLFunctionTable_glGenTextures expected 3 arguments, got 2 // 와 같은 에러를 출력한다. 해서 c-style로 수정하면 // Error: TypeError: in method 'MGLFunctionTable_glGenTextures', argument 3 of type 'MGLuint *' // 와 같은 에러를 출력한다. python을 경우 변수타입을 지정할수 없다. 일반적인 경우 MScriptUtil을 이용하여 변수타입을 정해서 포인터로 받는 형태를 취하는데 MGLuint로 변수타입을 정할수는 없다. 이와 같은 에러의 주 원인은 glFunctionTable를 사용하려 함이다. 이를 사용하지 않고 python opengl라이브러리를 바로 사용한다면 이와 같은 에러는 발생하지 않는다.
2011년 6월 29일 수요일
2011년 6월 20일 월요일
Get Attribute
def nameToNodePlug( attrName, nodeObject ): depNodeFn = OpenMaya.MFnDependencyNode( nodeObject ) attrObject = depNodeFn.attribute( attrName ) plug = OpenMaya.MPlug( MObject, attrName ) return plugnodeObject = MObject type
MDagPath를 MObject type으로 변환하려면 MDagPath.node() Function을 사용.
dagPath = OpenMaya.MDagPath() depFn = OpenMaya.MFnDependencyNode() dagIt = OpenMaya.MItDag(OpenMaya.MItDag.kBreadthFirst, OpenMaya.MFn.kSurface) while not dagIt.isDone(): dagIt.getPath(dagPath) depFn.setObject(dagPath.node()) arrtObject = depFn.attribute('intermediateObject') plug = OpenMaya.MPlug(dagPath.node(), arrtObject) print plug.asInt() dagIt.next()뭐 대충 으런식으로 object shape attribute을 가져온다.
2011년 6월 19일 일요일
Scripted plug-in initialization
When a scripted plug-in is loaded, Maya searches for an initializePlugin() function in its definition. Within this function, all proxy nodes are registered:
# Initialize the script plug-in def initializePlugin(mobject): mplugin = OpenMayaMPx.MFnPlugin(mobject) try: mplugin.registerCommand( kPluginCmdName, cmdCreator ) except: sys.stderr.write( "Failed to register command: %s\n" % kPluginCmdName ) raise
Writing a scripted plug-in
Writing a scripted plug-in requires the definition of some specialized functions within the plug-in. The scripted plug-in must:
Define initializePlugin and uninitializePlugin entry points.
Register and unregister the proxy class within these entry points.
Implement creator and initialize methods (as required) which Maya calls to build the proxy class.
Implement the required functionality of the proxy class. This requires importing the necessary modules.
Writing scripts
The Maya Python API modules contain the classes that are available for Python programming. These classes are separated into different categories and have appropriate naming conventions to signify their association. Classes include:
MFn
Any class with this prefix is a function set used to operate on MObjects of a particular type.
MIt
These classes are iterators and work on MObjects similar to the way a function set does. For example, MItCurveCV is used to operate on an individual NURBS curve CV (there is no MFnNurbsCurveCV), or, iteratively, on all the CVs of a curve.
MPx
Classes with this prefix are all "Proxies", that is, API classes designed for you to derive from and create your own object types.
피드 구독하기:
글 (Atom)