Is it possible to watch a while loop run in the UV editor?

Is it possible to watch a while loop run in the UV editor?

malcolm_341
Collaborator Collaborator
799 Views
11 Replies
Message 1 of 12

Is it possible to watch a while loop run in the UV editor?

malcolm_341
Collaborator
Collaborator

I wrote a simple while loop that moves the selected UVs one tile until it reaches a specified number, but when I run it the UV editor doesn't visually update until the while loop is complete. Is there a way to visually update the UV editor so I can see each time the UVs move one tile, I tried using pause -seconds 1 in my script and textureWindow -edit -refresh polyTexturePlacementPanel1; but neither of those commands worked, it just did all the work and then showed me the final result none of the steps along the way.

0 Likes
Accepted solutions (1)
800 Views
11 Replies
Replies (11)
Message 2 of 12

absoluteKelvin
Collaborator
Collaborator

you trying to do some uv animation ? 😄

https://www.artstation.com/kelvintam
Message 3 of 12

malcolm_341
Collaborator
Collaborator

Ha ha, kind of. I'm trying to create some automated testing for part of my script so I can watch it try all the permutations to make sure I got all the code right. I ended up just running the loop by hand by continuously pressing the numeric enter key 1,200 times. That worked, but it would've been cooler to watch it do the work automatically to test for errors.

0 Likes
Message 4 of 12

e_honda
Enthusiast
Enthusiast

Hi,

 

You can use the textureWindow command with a refresh flag.

https://help.autodesk.com/cloudhelp/2017/ENU/Maya-Tech-Docs/CommandsPython/textureWindow.html#flagre...

 

 

win_name = cmds.getPanel(scriptType='polyTexturePlacementPanel')[0]
cmds.textureWindow(win_name, edit=True, refresh=True)

 

 

 

I know that you already tested that command, so here is a simple example that works for me:

 

 

from maya import cmds
from maya.api import OpenMaya


mesh = cmds.polyCube(constructionHistory=False)[0]
sl = OpenMaya.MSelectionList()
mfnmesh = om2.MFnMesh()
sl.add(mesh)
dag = sl.getDagPath(0)
mfnmesh.setObject(dag)
active_uvset = cmds.polyUVSet(mesh, query=True, currentUVSet=True)[0]
us, vs = mfnmesh.getUVs(uvSet=active_uvset)
# this TextureViewWindow command is optional. just to make sure that the window is shown.
cmds.TextureViewWindow()
win_name = cmds.getPanel(scriptType='polyTexturePlacementPanel')[0]
# beware that xrange only works in Python2
for x in xrange(1000):
    us[0] += 0.001
    mfnmesh.setUVs(us, vs, uvSet=active_uvset)
    cmds.textureWindow(win_name, edit=True, refresh=True)

 

 

 

Hope it helps.

0 Likes
Message 5 of 12

malcolm_341
Collaborator
Collaborator

@e_hondathat's python, are you sure it's not because you're using python that you see the refresh update. Refresh still doesn't work for me.

0 Likes
Message 6 of 12

malcolm_341
Collaborator
Collaborator

Here's some simple code... That does not work, no visual update. What's the trick?

 

for ($i = 0; $i < 10; ++$i)
{
    polyEditUV -u 1 -v 0 -r 1;
    pause -seconds 1;
    textureWindow -edit -refresh polyTexturePlacementPanel1;
}
0 Likes
Message 7 of 12

e_honda
Enthusiast
Enthusiast

Hi,

 

I tested your MEL code and it doesn't worked, indeed.

Also, I tested some combinations of MEL and Python to see what happens:

  • MEL -> does not worked
  • Python -> worked
  • Python calling MEL(UVEdit+Window Update) -> does not worked
  • Python calling MEL(UVEdit) and Window Update using Python -> worked
  • MEL calling python(UVEdit+Window Update) -> does not worked
  • MEL calling python(UVEdit) and Window Update using MEL -> does not worked

In other words, it seems that the MEL version of the textureWindow with refresh flag does not works as it should.

It is really weird because, in theory, Python and MEL commands should trigger the same functionality of Maya.

Maybe somebody who knows more about those implementations could say something?

Message 8 of 12

malcolm_341
Collaborator
Collaborator

Well that's annoying. Thanks for testing all those combinations.

0 Likes
Message 9 of 12

Kahylan
Advisor
Advisor

Hi!

 

Since you just want to see it step by step for testing, you could export a snapshot after each iteration.

 

$object = "pCube1";
$uvs = `ls -sl -fl`;
for ($i = 0; $i < 10; ++$i)
{    
    string $stringI = $i;
    select $uvs;
    uvSnapshot -o -ff png -xr 1024 -yr 1024 -aa -r 255 -g 255 -b 255 -n ("/Users/kahylan/Documents/UV" + $stringI + ".png") -uMin 0 -uMax 10 -vMin 0 -vMax 1;
    polyEditUV -u 1 -v 0 -r 1;
    select $object;

}
uvSnapshot -o -ff png -xr 1024 -yr 1024 -aa -r 255 -g 255 -b 255 -n ("/Users/kahylan/Documents/UV" + $stringI + ".png") -uMin 0 -uMax 10 -vMin 0 -vMax 1;

 

Its a bit of a hacky work around and you'll have to delete the imagefiles after each time, but that's probably still faster than running your code 1000x.

0 Likes
Message 10 of 12

malcolm_341
Collaborator
Collaborator

I gave it a try and your code still doesn't show the update, it just takes all the snapshots and moves the UVs with no visual update until it's finished.

 

0 Likes
Message 11 of 12

mspeer
Consultant
Consultant
Accepted solution

Hi!

 

Use evalDeferred, then it works.

Example:

 

 

for ($i = 0; $i < 360; ++$i)
{    
    textureWindow -edit -refresh polyTexturePlacementPanel1;
    evalDeferred("polyEditUV -a 1");
}

 

 

It also works without refresh:

for ($i = 0; $i < 360; ++$i)
{    
    evalDeferred("polyEditUV -a 1");
}
Message 12 of 12

malcolm_341
Collaborator
Collaborator

Yes, it works! Thanks, here it is working.

 

for ($i = 0; $i < 10; ++$i)
{
    evalDeferred("polyEditUV -u 0 -v 1 -r 1");
    evalDeferred("pause -seconds 1");
}
0 Likes