[py/mel] polyEditUVShell

Hi,

I’ve got a couple of objects with many faces unitized within Maya from the UV editor. The problem is the orientation or direction of the unitized faces, as they aren’t rotated either horizontal or vertical to how I want them.

I would like them all facing one same way, however I have found no option to do so.

New to python, trying to give this a go:

import maya.cmds as mc;
#import .mel libraries for python usage

if mc.polyEditUVShell (angle = 180.0):
	mc.polyEditUVShell( pivotU= 0.5, pivotV= 0.5, angle= 90.0 );

The problem is:

  1. It flips what was horizontal as vertical, and what was vertical as horizontal
  2. I can’t use angle >= xxx.x nor != xxx.x (Maya then reads angle as undefined, etc)

The other problem is, I assume maya currently has no idea what angle or rotation any of the faces are currently at. I know how to query them

import maya.cmds as mc;
#import .mel libraries for python usage

uvPos = mc.polyEditUV( query=True );
print (uvPos);

But then how do I format that to a variable, if that’s required (or I’m thinking a little to complex), to then have maya understand the rotations of current shells and force all shells to one rotation/direction?

Appreciated,
Kai.

Hi Kai,

You are right in stating that Maya has no idea which way up the faces are.

The first thing to do is decide on a definition of up like, “The top is the (vertex/edge) that has the greatest Y value in world space”.
Then you can map that definition across to the UV’s.

Using this mapping you can work out how to rotate the face in UV space.

Keir

Hi Keir,

Thank you for replying.


import maya.cmds as mc

# Create a list to store vertex positions
vertexPositions = []

# Get the selected mesh
selectedMesh = mc.ls(selection=True, dag=True, type='mesh')[0]
if selectedMesh:

    # Get the number of vertices
    numberOfVertices = mc.polyEvaluate(selectedMesh, vertex=True)

    # Get the world space position for the selected meshes vertices
    for vertex in range(numberOfVertices):
        vertexPosition = mc.xform('{mesh}.vtx[{vertex}]'.format(mesh=selectedMesh, vertex=vertex), \
            query=True, worldSpace=True, translation=True)
        vertexPositions.append(vertexPosition)

print(vertexPosition)

vertPos = vertexPosition[19:37]

mc.polyEditUVShell( pivotU= 0.5, pivotV= 0.5, angle= vertPos );

I’m attempting to query the objects greatest Y/up value, then cut off X/Z from the query, and use Y as the position UVs should rotate towards.

Although I can’t seem to get it to work, Maya says:

Error: TypeError: Invalid arguments for flag ‘angle’. Expected float, got [ ]

Which I don’t understand. Could I get hint in the right direction?

Once again, appreciated.
Kai.

I don’t really know what you’re trying to do but…

You take a list of indexes (19 to 37) from the vertexPosition list or string, so the result is that vertPos is a list of something, or as python says a [].

The angle flag requires a float so you have to calculate the float representing to number of degrees you want to rotate the shell before using it. So you need to do some algebra here.

Besides that… I have many issues with this code…

vertexPosition is a list with 3 floats, that you know only has 3 entries as you create it, so why are you trying to get indexes 19 to 37 out of it?

Another thing, it’s really confusing to have variables named almost the same. You have both vertexPosition and vertexPositions… and you for some reason start using vertexPosition outside the for loop where you created it. So you’re using it outside it’s local space which is also very confusing as it’s not even allowed in many languages (but I know python is not as strict with rules as say… MEL).

Hi,

Sorry for the confusion - I was quickly going through some python coursework I received a couple months ago that I haven’t completely got around to, and modified an example provided. The naming convention with “vertexPosition” and “vertexPositions” is pretty bad, I agree.

The floats I assumed were returning an XYZ position, and that I require Y (as the object is a pretty tall object, such as a elongated Y-up cylinder) - so I was trying to use the indices of the returned value as the Y up value for UV shells to point to, or so?

I know you’re all pretty busy, but would it take long to maybe throw the correct theory my way with a little explanation and maybe a command or two that I can refer to documentation for?

Thanks.

Hi Kai

I think you are getting your self confused.

Plan out exactly how you are going to achieve your goal. Don’t worry about the code, just get a clear idea of how it will work.


# Get a single face
# Create a map of the vertex index to the positions (in world space)
# Create a map of the vertex index to the uv positions (in UV space)
# Calculate the two highest vertex positions of the face
# What angle should I rotate the UVs to get the highest (in world space) vertex index to be the highest in (in UV space)

Once you have the basic outline start filling in the code under the comments.

Start simple and work your way up to complex. Create a test scene with a single face plane and get it working with that first.

Also I second everything Wolfsong said.

Keir