PDA

View Full Version : python toggle isolat selection


jeremyknoll
10-21-2010, 11:13 PM
I've written this super simple script to toggle my isolate select on and off, and it does that just fine, but it doesn't update the 'ViewSelectedSet'. Whatever I last manually isolated is what stays in the select set when the code runs. Here's what I got:
isoPnl = mc.getPanel(wf=True)
isoCrnt = mc.isolateSelect(isoPnl, q=True, s=True)

if isoCrnt == 0:
mc.isolateSelect(isoPnl, state=1)
else:
mc.isolateSelect(isoPnl, state=0)
i think there's something easy missing; I'm just not seeing it. anyone see my mistake?

NaughtyNathan
10-22-2010, 12:18 PM
no mistake, it's just that the isolateSelect command is not enough on it's own to do everything necessary. When you choose Isolate Select > View Selected on the view menu it's actually running the MEL procedure: enableIsolateSelect which does a lot of extra stuff.
You can either call this directly from python:
import maya.mel as mel
isoPnl = mc.getPanel(wf=True)
isoCrnt = mc.isolateSelect(isoPnl, q=True, s=True)
mel.eval('enableIsolateSelect %s %d' % (isoPnl,not isoCrnt) )
or simply find and open the enableIsolateSelect procedure, take a look what it is doing in MEL and convert it to python.
:nathaN

EightBit
10-22-2010, 03:00 PM
You might find this (http://forums.cgsociety.org/showthread.php?p=5860319#post5860319)helpful.

jeremyknoll
10-22-2010, 08:55 PM
oh man, i knew 'enableIsolateSelect' needed to be in there but I didn't think at all about the 'eval' command and wasn't running it from the mel module...thanks guys. works fine now.

schlook
10-24-2010, 06:44 AM
I did mine like this:

def toggleIsolate():

import maya.cmds as mc

currentObj = mc.ls(selection=True)
currentPanel = mc.getPanel(wf=True)
currentState = mc.isolateSelect(currentPanel, query=True, state=True)
if currentState == 0:
mc.isolateSelect(currentPanel, state=1)
mc.isolateSelect(currentPanel, addSelected=True)
else:
mc.isolateSelect(currentPanel, state=0)
mc.isolateSelect(currentPanel, removeSelected = True)

CGTalk Moderation
10-24-2010, 06:44 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.