Initializing the Maya Environment in and for Python
Initializing the Maya Environment in and for Python
Maya runs any Python commands in the userSetup.py file whenever it starts up. You can use this file to set up your working environment or execute commonly used Python commands such as importing the maya.cmds module.
The userSetup.py script is executed during the initialization and setup phase of Maya; therefore, only commands which set up your working environment and have no dependencies on Maya functionality can be successfully run in this script.
- Create a file named userSetup.py in the following folder:
- Windows: <drive>:\Documents and Settings\<username>\My Documents\maya\<Version>\scripts
- Mac OS X: ~/Library/Preferences/Autodesk/maya/<version>/scripts
- Linux: ~/maya/<version>/scripts
- In the userSetup.py file, type the commands you want Maya to run on start up; for example, import maya.cmds as mc.
python tkFileDialog 的一些细节
askopenfilename(parent,filetypes,initialdir,initialfile,title)
asksaveasfilename(parent,filetypes,initialdir,initialfile,title)
parent 父窗口
filetypes 文件类型,如 [("footage xml", ".xml"),("All Files",".*")]
initialdir 初始路径
initialfile 初始文件
title 窗口标题
Python2.5 中 由cloneNode(xml.dom.minidom)产生的xml Node元素的tagName问题
Python2.5 中
由cloneNode(xml.dom.minidom)产生的xml Node元素的tagName
与 最开始的原始节点建立时的tagName相同,
不管你中间的克隆节点的tagName改变成什么,
也不管原始节点的tagName改变成什么!
下面是测试代码:
-
#!/usr/bin/env python
-
#coding:UTF-8
-
from xml.dom import minidom
-
-
xmlStr = '<?xml version="1.0" encoding="UTF-8"?><test><oldTagName/></test>'
-
xmlDoc = minidom.parseString(xmlStr)
-
firstNode = xmlDoc.firstChild
-
-
originalNode = firstNode.firstChild
-
originalNode.setAttribute('name','originalNode')
-
print 'This is original Node.'
-
print originalNode.toxml()
-
print '-------------------------------------------'
-
-
originalNode.tagName = 'original_Changed'
-
print 'I give the originalNode a new tagName.'
-
print originalNode.toxml()
-
print '-------------------------------------------'
-
-
cloneNode = originalNode.cloneNode(0)
-
cloneNode.setAttribute('name','cloneNode')
-
print 'This is clone Node from original Node, The tagName is the same as the old tagName of original Node!!!.'
-
print cloneNode.toxml()
-
print '-------------------------------------------'
-
-
cloneNode.tagName = 'isChanged'
-
print 'I give cloneNode a new tagName.'
-
print cloneNode.toxml()
-
print '-------------------------------------------'
-
-
cloneCloneNode = cloneNode.cloneNode(0)
-
cloneCloneNode.setAttribute('name','cloneCloneNode')
-
print 'This is clone Node from colne Node, The tagName is the same as the old tagName of original Node!!!.'
-
print cloneCloneNode.toxml()
-
print '-------------------------------------------'
-
-
cloneCloneNode.tagName = 'isChanged_too'
-
print 'I give the cloneCloneNode a new tagName.'
-
print cloneCloneNode.toxml()
-
print '-------------------------------------------'
-
-
originalNode.tagName = 'flow_Changed'
-
print 'I give the originalNode a new tagName.'
-
print originalNode.toxml()
-
print '-------------------------------------------'
-
-
CCCNode = cloneCloneNode.cloneNode(0)
-
cloneNode.setAttribute('name','CCCNode')
-
print 'This is clone Node from cloneCloneNode, The tagName is the same as the old tagName of original Node!!!.'
-
print CCCNode.toxml()
-
print '-------------------------------------------'
-
-
NewCloneNode = originalNode.cloneNode(0)
-
NewCloneNode.setAttribute('name','NewCloneNode')
-
print 'This is noe clone Node from originalNode, The tagName is the same as the old tagName of original Node!!!.'
-
print NewCloneNode.toxml()
-
print '-------------------------------------------'
-
-
print 'so, The tagName of the clone clone Node == The the old tagName of original Node!!!!!!!!!!'
-
print 'The attributes of the clone clone Node == The attributes of the clone Node'
结果:
This is original Node.
<oldTagName name="originalNode"/>
-------------------------------------------
I give the originalNode a new tagName.
<original_Changed name="originalNode"/>
-------------------------------------------
This is clone Node from original Node, The tagName is the same as the old tagName of original Node!!!.
<oldTagName name="cloneNode"/>
-------------------------------------------
I give cloneNode a new tagName.
<isChanged name="cloneNode"/>
-------------------------------------------
This is clone Node from colne Node, The tagName is the same as the old tagName of original Node!!!.
<oldTagName name="cloneCloneNode"/>
-------------------------------------------
I give the cloneCloneNode a new tagName.
<isChanged_too name="cloneCloneNode"/>
-------------------------------------------
I give the originalNode a new tagName.
<flow_Changed name="originalNode"/>
-------------------------------------------
This is clone Node from cloneCloneNode, The tagName is the same as the old tagName of original Node!!!.
<oldTagName name="cloneCloneNode"/>
-------------------------------------------
This is noe clone Node from originalNode, The tagName is the same as the old tagName of original Node!!!.
<oldTagName name="NewCloneNode"/>
-------------------------------------------
so, The tagName of the clone clone Node == The the old tagName of original Node!!!!!!!!!!
The attributes of the clone clone Node == The attributes of the clone Node
NumPy
NumPy is the fundamental package needed for scientific computing with Python. It contains:
- a powerful N-dimensional array object
- sophisticated broadcasting functions
- basic linear algebra functions
- basic Fourier transforms
- sophisticated random number capabilities
- tools for integrating Fortran code.
- tools for integrating C/C++ code.
Pygame
Pygame is a set of Python modules designed for writing games. Pygame adds functionality on top of the excellent SDL library. This allows you to create fully featured games and multimedia programs in the python language.
Pygame is highly portable and runs on nearly every platform and operating system. Pygame itself has been downloaded millions of times, and has had millions of visits to its website.
Pygame is free. Released under the LGPL licence, you can create open source, free, freeware, shareware, and commercial games with it. See the licence for full details.
Python Computer Graphics Kit
http://cgkit.sourceforge.net/gallery.html
Introduction
The Python Computer Graphics Kit is an Open Source software package containing a collection of Python modules, plugins and utilities that are meant to be useful for any domain where you have to deal with 3D data of any kind, be it for visualization, creating photorealistic images, Virtual Reality or even games.Currently, the entire kit consists of the following parts:
- The Python package cgkit that extends Python with 3D-related functionality.
- The Maya plugin sourcepy that integrates the Python interpreter into Maya, and the accompanying Python package maya that makes Maya functionality available in Python.
- A collection of small stand-alone utilities written in Python, MEL or MaxScript.
Python Win32 Extensions
http://sourceforge.net/projects/pywin32/
windows剪切板
-
Module win32clipboard
A module which supports the Windows Clipboard API.
Methods
- ChangeClipboardChain
- Removes a specified window from the chain of clipboard viewers.
- CloseClipboard
- Closes the clipboard.
- CountClipboardFormats
- Retrieves the number of different data formats currently on the clipboard.
- EmptyClipboard
- Empties the clipboard and frees handles to data in the clipboard.
- EnumClipboardFormats
- Lets you enumerate the data formats that are currently available on the clipboard.
- GetClipboardData
- Retrieves data from the clipboard in a specified format.
- GetClipboardDataHandle
- Retrieves data from the clipboard in a specified format, returning the underlying integer handle.
- GetClipboardFormatName
- Retrieves from the clipboard the name of the specified registered format.
- GetClipboardOwner
- Retrieves the window handle of the current owner of the clipboard.
- GetClipboardSequenceNumber
- Returns the clipboard sequence number for the current window station.
- GetClipboardViewer
- Retrieves the handle of the first window in the clipboard viewer chain.
- GetGlobalMemory
- Returns the contents of the specified global memory object.
- GetOpenClipboardWindow
- Retrieves the handle of the window that currently has the clipboard open.
- GetPriorityClipboardFormat
- Returns the first available clipboard format in the specified list.
- IsClipboardFormatAvailable
- Determines whether the clipboard contains data in the specified format.
- OpenClipboard
- Opens the clipboard for examination.
- RegisterClipboardFormat
- Registers a new clipboard format.
- SetClipboardData
- Places data on the clipboard in a specified clipboard format.
- SetClipboardText
- Places text on the clipboard .
- SetClipboardViewer
- Adds the specified window to the chain of clipboard viewers
- ChangeClipboardChain
用例
-
import win32clipboard as w
-
import win32con
-
-
def getText():
-
w.OpenClipboard()
-
d = w.GetClipboardData(win32con.CF_TEXT)
-
w.CloseClipboard()
-
return d
-
-
def setText(aString):
-
w.OpenClipboard()
-
w.EmptyClipboard()
-
w.SetClipboardData(win32con.CF_TEXT, aString)
-
w.CloseClipboard()