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.

NoteYou can use maya.utils.executeDeferred() to delay code execution until after the Maya scene is initialized. For more information, see maya.utils.
  1. 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
  2. In the userSetup.py file, type the commands you want Maya to run on start up; for example, import maya.cmds as mc.
    NoteMake sure you save the file with the right extension (.py).

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改变成什么!

 

下面是测试代码:

  1. #!/usr/bin/env python
  2. #coding:UTF-8
  3. from xml.dom import minidom
  4.  
  5. xmlStr = '<?xml version="1.0" encoding="UTF-8"?><test><oldTagName/></test>'
  6. xmlDoc = minidom.parseString(xmlStr)
  7. firstNode = xmlDoc.firstChild
  8.  
  9. originalNode = firstNode.firstChild
  10. originalNode.setAttribute('name','originalNode')
  11. print 'This is original Node.'
  12. print originalNode.toxml()
  13. print '-------------------------------------------'
  14.  
  15. originalNode.tagName = 'original_Changed'
  16. print 'I give the originalNode a new tagName.'
  17. print originalNode.toxml()
  18. print '-------------------------------------------'
  19.  
  20. cloneNode = originalNode.cloneNode(0)
  21. cloneNode.setAttribute('name','cloneNode')
  22. print 'This is clone Node from original Node, The tagName is the same as the old tagName of original Node!!!.'
  23. print cloneNode.toxml()
  24. print '-------------------------------------------'
  25.  
  26. cloneNode.tagName = 'isChanged'
  27. print 'I give cloneNode a new tagName.'
  28. print cloneNode.toxml()
  29. print '-------------------------------------------'
  30.  
  31. cloneCloneNode = cloneNode.cloneNode(0)
  32. cloneCloneNode.setAttribute('name','cloneCloneNode')
  33. print 'This is clone Node from colne Node, The tagName is the same as the old tagName of original Node!!!.'
  34. print cloneCloneNode.toxml()
  35. print '-------------------------------------------'
  36.  
  37. cloneCloneNode.tagName = 'isChanged_too'
  38. print 'I give the cloneCloneNode a new tagName.'
  39. print cloneCloneNode.toxml()
  40. print '-------------------------------------------'
  41.  
  42. originalNode.tagName = 'flow_Changed'
  43. print 'I give the originalNode a new tagName.'
  44. print originalNode.toxml()
  45. print '-------------------------------------------'
  46.  
  47. CCCNode = cloneCloneNode.cloneNode(0)
  48. cloneNode.setAttribute('name','CCCNode')
  49. print 'This is clone Node from cloneCloneNode, The tagName is the same as the old tagName of original Node!!!.'
  50. print CCCNode.toxml()
  51. print '-------------------------------------------'
  52.  
  53. NewCloneNode = originalNode.cloneNode(0)
  54. NewCloneNode.setAttribute('name','NewCloneNode')
  55. print 'This is noe clone Node from originalNode, The tagName is the same as the old tagName of original Node!!!.'
  56. print NewCloneNode.toxml()
  57. print '-------------------------------------------'
  58.  
  59. print 'so, The tagName of the clone clone Node == The the old tagName  of original Node!!!!!!!!!!'
  60. 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

http://numpy.scipy.org/

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

http://www.pygame.org/

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:

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 

用例

  1. import win32clipboard as w
  2. import win32con
  3.  
  4. def getText():
  5.     w.OpenClipboard()
  6.     d = w.GetClipboardData(win32con.CF_TEXT)
  7.     w.CloseClipboard()
  8.     return d
  9.  
  10. def setText(aString):
  11.     w.OpenClipboard()
  12.     w.EmptyClipboard()
  13.     w.SetClipboardData(win32con.CF_TEXT, aString)
  14.     w.CloseClipboard()