I wanted to see how to shorten some of these expressions if possible as I'm still learning...It´s a script that'll toggle meshes between High Quality Display and Low Quality Display. Some of my bigger concerns are three:
1-To set something to HQ, I believe the only flag needed is -polygonObject, even though in the Script Editor when you press the default shortcut it also changes -divisionU, -divisionV, -pointsWire and -pointsShaded. I didn't really find a use for these...
2-Some objects for some reason will sometimes say their polygonObject (PO) flag value is 0 and others 1 (whyyyy), thus I had to include this in the script with an
or.
3-I wanted the script to set objects back to PO=1 ONLY if all objects were in High Quality first. So I made a
for expression first that would check this before assigning values, and created two boolean variables to act as switches. Can this be shortened, somehow?
<div>isLow = False
isHigh = False
sel = cmds.ls(sl=True)
#Check in the selection if there are HQ and LQ displays mixed
for obj in sel:
cmds.select(obj, r=True) #Replace selection to be examined
getPOValue = cmds.displaySmoothness( q=1, po=1 ) #Get flag value from the selection
if getPOValue == [3L]:
isHigh = True
if getPOValue == [1L] or getPOValue == [0L]:
isLow = True
#Assign PO Values
for obj in sel:
cmds.select(obj, r=True)
getPOValue = cmds.displaySmoothness( q=1, po=1 )
if getPOValue == [1L] or getPOValue == [0L]:
cmds.displaySmoothness( po=3 )
else:
#Only set everything to LQ if everything is HQ first
if isHigh == True and isLow == False:
cmds.displaySmoothness( po=1 )
cmds.select(sel, r=True) #Return to the initial selection<br></div>
Anyway, thanks to anyone who takes the time to read this
!
Replies
2) I'm not sure about polygonobject = 0, I thought maybe it was some legacy thing or used in subdiv surfaces, but a fresh primitive or import return 0 until I press 1. I'd go with the assumption that on a polygon object that 0 and 1 are the same thing. Checking for getPOValue <= [1L] will simplify looking for both 0 and 1.
3) I'm no grand scripter, but that seems like the best way to go, it's a fairly quick way to sort through the two possible sets of numbers in a list and do something with them in turn. I could think of less elegant ways to do that with the sort command.
Also, displaySmoothness seems to take an object list as parameter, and return lists as well, maybe you can use that to avoid loops? (I'm asking because the docs don't show an example of it. Someone with Maya would need to test it).
If it does accept and return object lists, then you could do something like this:
PS: Gotta love the Maya docs, "displaySmoothness is undoable (...). At present, this command is NOT un-doable." Wat
@RN
And that's the exact behaviour I'm doing here, no?
Also it's the first time I see a for expression using that kind of syntax, I'll have to read a bit to understand that haha...Thanks for showing me more ways, doable or not, of doing this. And yeah, Autodesk docs in general can be frustrating...
Let me know if there's something you didn't understand. The strangest thing might be the enumerate function, which returns a tuple (a read-only array) that is being unpacked into the 'index, v' variables (aka multiple assignment, the values in the tuple are being orderly assigned to the variables in that comma list).