Maya Python Studying
Thursday, April 18, 2013
My own "Hello, World!" Maya plug-in
Yestarday, I used Maya devkit example to learn Maya plug-ins. Today, I will create my own alternative Hello World plug-in!
import maya.OpenMaya as om
import maya.OpenMayaMPx as ommpx
class AR_HelloWorldCmd(ommpx.MPxCommand):
"""
A command that prints a string to the console.
"""
## the name of the command
kPluginCmdName = 'ar_helloWorld'
def __init__(self):
"""
Initialize the instance.
"""
ommpx.MPxCommand.__init__(self)
def doIt(self, args):
"""
Print string to the console.
"""
print('Hello, world!')
@classmethod
def cmdCreator(cls):
"""
Return pointer to proxy object.It has to always call this method when creating MPx objects in scripted plug-ins.
"""
return ommpx.asMPxPtr(cls())
def initializePlugin(obj):
"""
Initialize the plug-in.
"""
plugin = ommpx.MFnPlugin(
obj,
'Meng',
'1.0',
'Any'
)
try:
plugin.registerCommand(
AR_HelloWorldCmd.kPluginCmdName,
AR_HelloWorldCmd.cmdCreator
)
except:
raise Exception(
'Failed to register command: %s'%
AR_HelloWorldCmd.kPluginCmdName
)
def uninitializePlugin(obj):
"""
Uninitialize the plug-in.
"""
plugin = ommpx.MFnPlugin(obj)
try:
plugin.deregisterCommand(AR_HelloWorldCmd.kPluginCmdName)
except:
raise Exception(
'Failed to unregister command: %s'%
AR_HelloWorldCmd.kPluginCmdName
)
It is critical to note again that you must unload and then reload a plug-in to see changes that you are making in an external text editor become active in Maya.
Wednesday, April 17, 2013
Maya Plug-In
The simplest way to start developing commands by using plug-ins is to look at the simplest possible example. The Maya devkit folder contains sevel example commands.
So I add helloworld plug-in by using Plug-in Manager:
Then print “Hello World!” should be as simple as type:
import maya.cmds as cmds;
cmds.spHelloWorld()
Then print “Hello World!” should be as simple as type:
import maya.cmds as cmds;
cmds.spHelloWorld()
Sunday, April 14, 2013
Formal Categorization of Problem solving Strategies
The following is a more Formal
Categorization of Problem solving Strategies:
• Abstraction: solving the
problem in a model of the system before applying it to the real system
• Analogy: using a
solution that solves an analogous problem
• Brainstorming:
(especially among groups of people) suggesting a large number of solutions or
ideas and combining and developing them until an optimum is found
• Divide and conquer:
breaking down a large, complex problem into smaller, solvable problems
• Hypothesis testing:
assuming a possible explanation to the problem and trying to prove (or, in some
contexts, disprove) the assumption
• Lateral thinking:
approaching solutions indirectly and creatively
• Means-ends analysis:
choosing an action at each step to move closer to the goal
• Method of focal objects:
synthesizing seemingly non-matching characteristics of different objects into
something new
• Morphological analysis:
assessing the output and interactions of an entire system
• Proof: try to prove that
the problem cannot be solved. The point where the proof fails will be the
starting point for solving it
• Reduction: transforming
the problem into another problem for which solutions exist
• Research: employing
existing ideas or adapting existing solutions to similar problems
• Root cause analysis:
identifying the cause of a problem
• Trial-and-error: testing
possible solutions until the right one is found
Thursday, April 11, 2013
General Problem Solving Strategies
General Problem Solving Strategies:
1. Read and try to understand asserts
diagnostics or symptoms if available.
2. Form clear hypothesis about cause of
problem.
3. Compare and contrast a working case with
a non-working case.
4. Trace flow if possible.
5. Isolate working and non-working parts. (Divide and
conquer) This is different from 3 above
in that 3 describes comparing a working whole vs. a non-working whole. Here, we are separating parts of a
non-working whole into working and non-working parts.
6. Time Box Trouble Shooting Efforts and
ask for help
7. Form new hypothesis if necessary --walk
away and return after a break.
Saturday, April 6, 2013
Reading Material
Since I'm a little ahead of my schedule, so,
I decided to read more materials related to technical artist instead of keep
reading Maya Python. Here are some materials I read.
1.
A great book to read on controlling
flow in complex systems. This book helps me to naturally involve objective
analysis, economics and an understanding of flow in my problem solving process.
2.
Several links describing
Technical Art: Since reality is composed of multiple perspectives, it’s
important to encounter multiple points of view.
No single description is definitive.
Sunday, March 31, 2013
Chapter 9 Conclution
Chapter 9 is all about understanding Maya API. Since the API documentation is written by C++, so I have to at least understand some basic knowledge about C++.
Maya's C++ API contains many classes and function sets that are accessible through various Python modules. These modules use SWIG to automatically convert Python parameters into data for C++, as well as a lack of perfect correspondence between C++ and Python, programmers working with the Python API must have some basic understanding of C++ to read the documentation, understand some limitations they will face, and better grasp classes like MScriptUtil.
Though it is somewhat different from ordinary Python scripting in Maya, the Maya Python API provides an accessible way to rapidly develop powerful tools for Maya.
PS: Maya API Reference: http://docs.autodesk.com/MAYAUL/2013/ENU/Maya-API-Documentation/index.html
Saturday, March 23, 2013
Cannot install Qt SDK
Chapter 8 is all about Qt. So first, I have to install it. But I encountered some problems because the book only told us how to install it for Maya 2011 and Maya 2012. I followed the instruction but it cannot work.
Then, I searched for a long time and found out that many people have same problem with me. Finally, I found the reason: PyQt 4.9.1 built against Qt4.7.1.
Unfortunately, I didn't find a solution to solve this problem. But I can keep on learning without studying Chapter 8. So, next week, I will move on to Chapter 9: Understanding C++ and the API Documentation. From this week's learning, I knew Qt is a WYSIWYG (what you see is what you get) tool. So, it must be very powerful and easy to use. I would like to learn it later on if I have chance.
Then, I searched for a long time and found out that many people have same problem with me. Finally, I found the reason: PyQt 4.9.1 built against Qt4.7.1.
Unfortunately, I didn't find a solution to solve this problem. But I can keep on learning without studying Chapter 8. So, next week, I will move on to Chapter 9: Understanding C++ and the API Documentation. From this week's learning, I knew Qt is a WYSIWYG (what you see is what you get) tool. So, it must be very powerful and easy to use. I would like to learn it later on if I have chance.
Subscribe to:
Posts (Atom)