Hi Justin,
I know this thread is old but hopefully you con help me out. I am new to
scripting in Maya. I have a script going that gives me a selection of all
faces across multiple objects that I want to apply vertex color to.
I have a python method working but it is very slow. I am attempting to use
the api since I hear it is faster. I used the code you pasted below and was
finally able to get component selection into a list. When I use the
resulting list of vertex indices from your code with a color array I have
made with setVertexColors, I get an overloaded function error. the point I
ran into the problem was in getting the appropriate object that the face
selection was tied to. My workaround was to use a for loop and
setVertexColor(colorVertexList[I], vList[I]). It works but is pretty much
the same speed as before, i'm sure since I am marching each index one at a
time. How would I set vertex color on the verts in vList calling
setVertexColors properly? Any advice is much appreciated.
Here is what I have, using your method for getting the vertex idexes:
import maya.OpenMaya as api
import maya.cmds as c
import maya.mel as mm
shadingGroup = cmds.listConnections('Dirt', type='shadingEngine')
componentsWithMaterial = cmds.sets(shadingGroup, q=True)
cmds.select(componentsWithMaterial)
first_face = componentsWithMaterial[0].split(":")[0]
if ']' in first_face:
selectedFace = str(first_face)
else:
selectedFace = str(first_face) + ']'
cmds.select(selectedFace)
facetSG = cmds.hyperShade(smn=True)
shader = cmds.ls(selection=True)
cmds.select(shader)
cmds.hyperShade(objects='')
objectAllFaces = cmds.ls(selection=True)
objectAllVerts = cmds.ls(cmds.polyListComponentConversion(objectAllFaces,
ff=True, tv=True))
for n in objectAllVerts:
cmds.select(n)
sel = api.MSelectionList()
api.MGlobal.getActiveSelectionList(sel)
compIter = api.MItSelectionList(sel, api.MFn.kMeshVertComponent)
component = api.MObject()
meshDagPath = api.MDagPath()
meshObj = om.MObject( )
sel.getDependNode(0,meshObj)
meshFn = om.MFnMesh(meshObj)
vList = []
colorVertexList = api.MColorArray ( )
while not compIter.isDone():
compIter.getDagPath(meshDagPath, component)
if not component.isNull():
vertIter = api.MItMeshVertex(meshDagPath, component)
while not vertIter.isDone():
vList.append(vertIter.index())
vertIter.next()
compIter.next()
for i in range(len(vList)):
colorVertexList.append(1.0,0.0,0.0,1.0)
for i in range(len(vList)):
meshFn.setVertexColor(colorVertexList[i], vList[i])
On Sunday, November 27, 2011 at 1:05:02 PM UTC-7, Justin Israel wrote:
> Thanks. I am quite lovely aren't I? LOL
>
> Here is a rough example that I thought of, using python commands and
> assuming a start and end selection
> https://gist.github.com/1398060
>
> I don't really check the original selection to see if its only two
> vertices or faces, but this should give you an idea. Hopefully I didn't
> over-think your problem.
> I used a regex to get the int vert/face number instead of using the maya
> api since that approach seems like too much code just to get the index from
> the selection:
>
> import maya.OpenMaya as api
>
> sel = api.MSelectionList()
> api.MGlobal.getActiveSelectionList(sel)
> compIter = api.MItSelectionList(sel, api.MFn.kMeshVertComponent)
>
>
> component = api.MObject()
> meshDagPath = api.MDagPath()
>
>
> vList = []
>
> while not compIter.isDone():
> compIter.getDagPath(meshDagPath, component)
> if not component.isNull():
> vertIter = api.MItMeshVertex(meshDagPath, component)
> while not vertIter.isDone():
> vList.append(vertIter.index())
> vertIter.next()
> compIter.next()
>
>
> I may be a little slow from the holiday weekend and overlooked some easier
> way to do it. But thats as much as I can do with a bunch of turkey in my
> stomach :-)
>
> -- justin
>
>
> On Nov 27, 2011, at 4:57 AM, Reza Shahsavary wrote:
>
> thx Justin
> ur Lovely
> but 2 questions if u don't mind!
> 1.what should i do if want to select my component mesh without typing
> surface name i.g :p.sphere..i`d like to do that with selection mesh
> 2.i just need to select my components in one direction(horizontal or
> vertical)
> thx
> P.M:i just uploaded a photo from maya.i need to selection like
> that.actually its selected by hand :)
>
>
> --
> view archives: http://groups.google.com/group/python_inside_maya
> change your subscription settings:
> http://groups.google.com/group/python_inside_maya/subscribe
> <my selection.jpg>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/5744b71d-0ab0-4134-9bd2-c16e60da6738%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.