[Maya-Python] meshInfo script newbie api question

2009-10-23 Thread johnvdz

hi all,

i'm doing a basic mesh info script following loosely the David Gould c++ 
script(which i have no idea about). I want to write out a basic text 
file with python for use later. i just want the numbers of polys and 
verts and then the poly-vert associations.

this is pritty much my first api script and really just for kicks and to 
try learn some python Api. of cource i have hit the wall with trying to 
iterate over the polycount of an object. as i know you cant do it in a 
python method. i was trying to assign a variable to a 
OpenMaya.MIntArray() and then iterate over that but i'm either doing it 
wrong or its just not possible. could anyone let me know what i'm doing 
wrong or what direction i should take

my script so far is.

i just select the shape node of the mesh object
***
#import sys
import maya.OpenMaya as OpenMaya
#import maya.OpenMayaMPx as OpenMayaMPx

def meshInfo(shapeNode):
#print hello
mObj = OpenMaya.MObject()
selectionList = OpenMaya.MSelectionList()#get list of objects 
#print selectionList
dagPath = OpenMaya.MDagPath()
OpenMaya.MGlobal.getActiveSelectionList(selectionList)#get the list 
of selected info
 
#selectionList.add( shapeNode )
selectionList.getDependNode( 0, mObj )#get the depandants shape
print mObj.apiType()
if( mObj.apiType() == OpenMaya.MFn.kMesh ):
print 'its a mesh'
newDagPath = OpenMaya.MDagPath()
dagPath.getAPathTo( mObj, newDagPath )
try:
meshFn = OpenMaya.MFnMesh( mObj )
print 'yep'
except:
sys.stderr.write(!!! ERROR :: can not create meshFn)
try:
polyIter = OpenMaya.MItMeshPolygon( newDagPath )
print 'yep2'
except:
sys.stderr.write(!!! ERROR :: can not create polyIter)
try:
polyVertIter = OpenMaya.MItMeshFaceVertex( newDagPath ) 
#iterate over the face verts
print 'yep3'
except:
sys.stderr.write(!!! ERROR :: can not create polyVertIter)
numPolys = OpenMaya.MIntArray()
print 'numpolys'
meshFn.numPolygons(numPolys)
print polyIter.count()
for i in numPolys: ##just trying to iterate over some value and 
trying not to revert to mel or mayapy
print i,
#get poly number and vertex points
#eventually print to file
#v1:(1.0, 0 ,1)
#v2:(etc)
#p1:(v1,v4,v19) etc
else:
print 'not kMesh'



any help would be great

john

--~--~-~--~~~---~--~~
http://groups.google.com/group/python_inside_maya
-~--~~~~--~~--~--~---



[Maya-Python] Re: grabbing skin cluster. API

2009-10-23 Thread Brandon Harris


Reawakening the topic. I can grab ahold of the skinCluster by
traversing the plugs downstream and grabbing the skincluster. What I
am finding though is that in some cases I can grab a skin cluster that
may not be directly plugged into the shape (ie a blendshape with a
skinCluster) This doesn't happen if the selected object has a
skinCluster, but if it doesn't, but the blendshape does it will grab
the blendshapes skinCluster.


itDG = openMaya.MItDependencyGraph(shape.node
(),openMaya.MItDependencyGraph.kDownstream,openMaya.MItDependencyGraph.kPlugLevel)
while not itDG.isDone():
oCurrentItem = itDG.currentItem()
#the iterator returns an MObject that we then check to see
if it is a skinCluster. If it is, Save it.
if oCurrentItem.hasFn(openMaya.MFn.kSkinClusterFilter):
skinCluster = openAni.MFnSkinCluster(oCurrentItem)
print (skinCluster.name() +  will be returned)
break
itDG.next()


I suppose it's not a deal breaker, but I would like to ensure that the
tool won't break. Does anyone know of a way to compare plugs? Maybe
see if the skinCluster that is returns is actually connecting to the
shape?

--~--~-~--~~~---~--~~
http://groups.google.com/group/python_inside_maya
-~--~~~~--~~--~--~---



[Maya-Python] meshInfo script newbie api question

2009-10-23 Thread johnvdz

hi all,

i'm doing a basic mesh info script following loosely the David Gould c++ 
script(which i have no idea about). I want to write out a basic text 
file with python for use later. i just want the numbers of polys and 
verts and then the poly-vert associations.

this is pritty much my first api script and really just for kicks and to 
try learn some python Api. of cource i have hit the wall with trying to 
iterate over the polycount of an object. as i know you cant do it in a 
python method. i was trying to assign a variable to a 
OpenMaya.MIntArray() and then iterate over that but i'm either doing it 
wrong or its just not possible. could anyone let me know what i'm doing 
wrong or what direction i should take

my script so far is.

i just select the shape node of the mesh object
***
#import sys
import maya.OpenMaya as OpenMaya
#import maya.OpenMayaMPx as OpenMayaMPx

def meshInfo(shapeNode):
   #print hello
   mObj = OpenMaya.MObject()
   selectionList = OpenMaya.MSelectionList()#get list of objects
#print selectionList
   dagPath = OpenMaya.MDagPath()
   OpenMaya.MGlobal.getActiveSelectionList(selectionList)#get the list 
of selected info
   #selectionList.add( shapeNode )
   selectionList.getDependNode( 0, mObj )#get the depandants shape
   print mObj.apiType()
   if( mObj.apiType() == OpenMaya.MFn.kMesh ):
   print 'its a mesh'
   newDagPath = OpenMaya.MDagPath()
   dagPath.getAPathTo( mObj, newDagPath )
   try:
   meshFn = OpenMaya.MFnMesh( mObj )
   print 'yep'
   except:
   sys.stderr.write(!!! ERROR :: can not create meshFn)
   try:
   polyIter = OpenMaya.MItMeshPolygon( newDagPath )
   print 'yep2'
   except:
   sys.stderr.write(!!! ERROR :: can not create polyIter)
   try:
   polyVertIter = OpenMaya.MItMeshFaceVertex( newDagPath ) 
#iterate over the face verts
   print 'yep3'
   except:
   sys.stderr.write(!!! ERROR :: can not create polyVertIter)
   numPolys = OpenMaya.MIntArray()
   print 'numpolys'
   meshFn.numPolygons(numPolys)
   print polyIter.count()
   for i in numPolys: ##just trying to iterate over some value and 
trying not to revert to mel or mayapy
   print i,
   #get poly number and vertex points
   #eventually print to file
   #v1:(1.0, 0 ,1)
   #v2:(etc)
   #p1:(v1,v4,v19) etc
   else:
   print 'not kMesh'



any help would be great

john

--~--~-~--~~~---~--~~
http://groups.google.com/group/python_inside_maya
-~--~~~~--~~--~--~---



[Maya-Python] Re: PyQt in Maya examples

2009-10-23 Thread Sylvain Berger
Where can I find your version of pumpThread?

Thanks

On Tue, Sep 29, 2009 at 5:24 AM, David Moulder da...@thirstydevil.co.ukwrote:

 Ok,  Here's and basic example with PyQT and a QListWidget...
 Please note.  This use's a modified pumpThread module.  The default one
 from the maya dev kit has given us lots of problems.
 Thanks to some very clever people on this list we now have a working
 pumpThread module that is heavily tested here at work.

 from PyQt4 import QtCore, QtGui
 import pymel as pm
 import pumpThread

 class ExampleUI(QtGui.QDialog):
 def __init__(self, parent=None):
 super(ExampleUI, self).__init__(parent)
 # Set some basic properties on the UI
 self.setWindowTitle('ExampleUI')
 self.setObjectName(ExampleUI)
 self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

 # Add a Layout and set it to the UI
 self.mainLayout = QtGui.QVBoxLayout(self)
 self.setLayout(self.mainLayout)

 # Add a Button and set some properties.  Also add it to a layout.
 self.RefreshButton = QtGui.QPushButton()
 self.RefreshButton.setText(Refresh)
 self.mainLayout.addWidget(self.RefreshButton)

 # Add a list and set it to the layout
 self.SelectionList = QtGui.QListWidget()
 self.SelectionList.setMinimumSize(250,250)
 self.mainLayout.addWidget(self.SelectionList)

 # Connect the Refresh Button to a function to populate the list
 using SIGNAL's
 self.connect(self.RefreshButton, QtCore.SIGNAL(clicked()),
 self._RefreshButtonFunc)

 def _RefreshButtonFunc(self):
 '''
 Fill the list based on a maya selection
 '''
 oSel = pm.selected()
 if oSel:
 self.SelectionList.clear()
 [self.SelectionList.addItem(s.name()) for s in oSel]
 else:
 self.SelectionList.clear()

 @staticmethod
 def Display():
 '''
 calls the window.  Typical PumpThread call
 Use's a modified pumpThread that properly set's up the thread.
 '''
 # We need a global to stop python gc the UI
 global mainWindow

 # We need pumpThread to make the UI responsive
 pumpThread.initializePumpThread()
 app = pumpThread.get_app()
 if app:
 # We can set the app to use a nice style
 app.setStyle('Plastique')
 mainWindow = ExampleUI()
 mainWindow.show()

 ExampleUI.Display()

 I'll post our final pumpThread later today.

 -Dave



 On Tue, Sep 29, 2009 at 6:42 AM, floyd1510 vshingr...@gmail.com wrote:


 Hello all,

 I have got PyQt up and running in Maya 2009. I was wondering if
 someone could guide me to a few examples, like adding a list of
 objects from maya into the QT listview or adding items dynamically to
 a combo box etc.

 I appreciate the help.

 Cheers,
 Vikram.




 



-- 
A pit would not be complete without a Freeman coming out of it.
The Vortigaunt

--~--~-~--~~~---~--~~
http://groups.google.com/group/python_inside_maya
-~--~~~~--~~--~--~---