Reputation: 47
Pretty much exactly as the title states, I've got a simple python script in Maya that isn't functioning.
import maya.cmds as cmds
import maya.mel as mel
def createCylinder():
# Check if cylinder "trunkCylinder" exists. Delete it
if cmds.objExists("trunkCylinder"):
cmds.delete("trunkCylinder")
# Create a new cylinder called "trunkCylinder"
cmds.polyCylinder(axis=(0,1,0), height=1, name="trunkCylinder" )
# Clear the selection, then select the cap and invert the selection.
cmds.select(clear=True)
cmds.select("trunkCylinder.f[21]", replace=True)
invertedSel = mel.eval("invertSelection;")
print str(invertedSel)
# ^^ Prints: None ^^
# End result is nothing is selected
createCylinder()
I expected Maya to print a list of all faces on trunkCylinder except f[21] and to inverse the selection in the viewport. Instead, it returns None and deselects f[21]. Does anyone see a mistake in my code, or am I using invertSelection incorrectly?
Fortunately I can just select f[0:20] as a workaround, or even get a list of the faces and compare it to my list of faces, removing anything that is on both lists. However I can already envision situations where getting invertSelection to work would save me a lot of time. Any help here would be appreciated.
Upvotes: 1
Views: 2734
Reputation: 58493
The following Python script is definitely works. You should try it)). Asterisk is used for selection of all the other faces in array, along with toggle
flag, that inverted a selection for you.
import maya.cmds as cmds
def createCylinder():
if cmds.objExists("trunkCylinder"):
cmds.delete("trunkCylinder")
cmds.polyCylinder(axis=(0,1,0), height=1, name="trunkCylinder")
cmds.select(clear=True)
cmds.select("trunkCylinder.f[21]")
cmds.select("trunkCylinder.f[*]", tgl=True)
createCylinder()
Upvotes: 2