I used to use Alex Gorbatchev Syntax Highlighter to make python code looks nice. But due to bug in copy function (empty strings are replaced with "ANDnbsp" and so becomes corrupted), i had to switch to another static converter. If anybody know how to fix syntax highlighter please let me know.
Currently i use http://hilite.me
Tuesday, December 25, 2012
Sunday, December 23, 2012
Maya PyQt UI template
Use the following code to show PyQt *.ui in Autodesk maya. It will load all stuff located in ui file and create window attached to maya-window. Copy this code to maya script editor, replace string uifile = 'c:/test.ui' with real path to your ui-file (use forward slash even on windows). Now execute this code, and you will get your UI-window in maya.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import maya.OpenMayaUI as apiUI from PyQt4 import QtCore, uic import sip uifile = 'c:/test.ui' form, base = uic.loadUiType(uifile) def getMayaWindow(): """ Get the main Maya window as a QtGui.QMainWindow instance @return: QtGui.QMainWindow instance of the top level Maya windows """ ptr = apiUI.MQtUtil.mainWindow() if ptr is not None: return sip.wrapinstance(long(ptr), QtCore.QObject) class testQtWindow(form, base): def __init__(self, parent = getMayaWindow()): super(testQtWindow,self).__init__(parent) self.setupUi(self) def main(): global win try: win.close() except: pass win = testQtWindow() win.show() if __name__=="__main__": main() |
Friday, December 21, 2012
PyQt application template
This is template for PyQt application. It's good point to start studying PyQt.
- create ui-file in QtDesigner
- save it to disk
- replace 'c:/test.ui' with real path to created ui
- execute py-file. Make sure to run it with pythonw, not with python. In this case, command window will not pop up (on windows system).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | from PyQt4 import QtGui, uic import sys # replace 'c:/test.ui' with real path to ui-file created in QtDesigner uifile = 'c:/test.ui' form, base = uic.loadUiType(uifile) class testQtWindow(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = form() self.ui.setupUi(self) def main(): app = QtGui.QApplication(sys.argv) myapp = testQtWindow() myapp.show() sys.exit(app.exec_()) if __name__=="__main__": main() |
Wednesday, December 19, 2012
Split face between selected vertices in MAYA
This MEL-script splits face between selected vertices. Both vertices should belong to one face. New adge will be constructed between selected verts.
Usage:- copy script to you scripts directory
- source it in MAYA (or reboot maya)
- select to vertices on mesh
- run command isplitByVertex or place it on shelf
Download script
Monday, December 17, 2012
Switch wireframe on shaded.
One more small script. Now to use shelf button to switch wireframe on shaded mode. Instead of Shading->Wireframe on shaded menu.
Usage:
- make new shelf button with script text (python command)
- press "5" to turn shaded view in current MAYA viewport
- press created shelf button
It turns on and off wireframe on objects in current viewport.
Usage:
- make new shelf button with script text (python command)
- press "5" to turn shaded view in current MAYA viewport
- press created shelf button
It turns on and off wireframe on objects in current viewport.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | ''' @author: Serge Scherbakov Date: 25.07.2012 ''' import maya.cmds as cmds def wireframeSwitcher(): viewport = cmds.getPanel( withFocus = True) if 'modelPanel' in viewport: currentState = cmds.modelEditor( viewport, q = True, wireframeOnShaded = True) if currentState: cmds.modelEditor( viewport, edit = True, wireframeOnShaded = False) else: cmds.modelEditor( viewport, edit = True, wireframeOnShaded = True) wireframeSwitcher() |
Align pivots in Maya
This script allows you to copy object pivot translation and rotation from one object to another one.
How to use:
- copy code to the script editor "Python tab"
- select source object
- select target object
- execute script
Works on multiple selection. Align all object pivots with last selected.
- copy code to the script editor "Python tab"
- select source object
- select target object
- execute script
Works on multiple selection. Align all object pivots with last selected.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | ''' Align pivots by Serge Scherbakov. Usage: 1. Select source object(s) 2. Add to selection target object 3. Run script by 'import copyPivot\n copyPivot.copyPivot() ''' import maya.cmds as cmds import maya.mel as mel def copyPivot (): sourceObj = cmds.ls(sl = True)[len(cmds.ls(sl = True))-1] targetObj = cmds.ls(sl = True)[0:(len(cmds.ls(sl = True))-1)] parentList = [] for obj in targetObj: if cmds.listRelatives( obj, parent = True): parentList.append(cmds.listRelatives( obj, parent = True)[0]) else: parentList.append('') if len(cmds.ls(sl = True))<2: cmds.error('select 2 or more objects.') pivotTranslate = cmds.xform (sourceObj, q = True, ws = True, rotatePivot = True) cmds.parent(targetObj, sourceObj) cmds.makeIdentity(targetObj, a = True, t = True, r = True, s = True) cmds.xform (targetObj, ws = True, pivots = pivotTranslate) for ind in range(len(targetObj)): if parentList[ind] != '' : cmds.parent(targetObj[ind], parentList[ind]) else: cmds.parent(targetObj[ind], world = True) copyPivot() |
Extract poly component index in 1 string.
To extract index of maya polycomponent (face, edge or vertex) you can use the following expression. Python power is awesome.
edgeIndex = str(edge).split('[')[1].split(']')[0]
Subscribe to:
Posts (Atom)