PDA

View Full Version : hide selection not updating from Python


EightBit
12-17-2009, 09:40 PM
Hi all:
I'm writing .py code to speed up isolateSelect. Almost everything is working. BUT, when I invert the selected faces and then toggle isolate select w/Python, Maya doesn't hide the newly selected faces - it continues to hide the original selection.

I can toggle the hiding of selected faces w/this:
def pixl_isolateSelected():
curPanel = cmds.getPanel (up=1); #Get cam under pointer
cmds.isolateSelect ( curPanel, state = not(cmds.isolateSelect (curPanel, q=1, state = 1)))

I can invert the selection w/this:
def pixl_invertIsolated():
mm.eval('InvertSelection')

However, once the selection is inverted, Maya will continue to hide/show the faces in the original selection (ie not the updated selection of faces) - but only when invoked from Python.
If I use the menu or a mel script, the correct faces are hidden (membership of "modelPanelXXViewSelectedSet" is updated).
Here's the mel which works correctly:
global proc pixl_isolateSelected()
{
string $curPanel = `getPanel -up`; //Get cam under pointer
enableIsolateSelect $curPanel (!`isolateSelect -q -state $curPanel`);
}

Can anyone see where the problem is?
Thanks.

Jickien
12-30-2009, 05:00 PM
Hi EightBit:

for your cord pasted here are not complete, it's a little bit inconvenient to test,so forgive me to give up to test them in my Maya.so after reading,i suppose there may be have such problems in your code:

your first selection works, because this selection is made by manual, the selection results will be returned also; then you use mm.eval('InvertSelection') invert the current selection.here is the crux :

# try below
newSel=mm.eval('InvertSelection')
print newSel
# return None to you,right?

because eval will return nothing,so you selection results inside Maya won't update.

why the Mel version works?i see you use a Mel Build-in function : enableIsolateSelect , this function will automatic query current panel's selection then update the selection results inside Maya before do isolateSelect job,that's the difference.

rewrite your def pixl_invertIsolated() as follow to see if it's works:


def pixl_invertIsolated():
mm.eval('InvertSelection')
cmds.ls(sl=True)
#tell maya query and return your current selection

EightBit
01-08-2010, 04:42 AM
Sun:
Thanks for the reply. I see that the result of 'ls' doesn't change after inverting. But the HUD shows that the selection is inverted. In the viewport, it looks like all the faces are selected.
I think the fact that the results of 'ls' not changing after inverting is a sign of a bug. I asked about this on the Autodesk Subscription forum and they couldn't figure it out, so they think it is a bug also.

I don't see a workaround in Python, do you?

I'm want to use Python wherever possible, but for this proc I'm using Mel...

Thanks again.

kojala
01-08-2010, 08:23 AM
you should use python selection invert function, works with all types of components
but takes the component type only from the first component and is much more simpler
than the mel one. And is faster cos its not actually selecting anything


import maya.cmds as m

def inv():
comps = m.ls(sl=1, fl=1)
items = comps[0].split('.')

obj = items[0]
comp_type = items[1].split('[')[0]
all = m.ls(obj+'.'+comp_type+'
', fl=1)
return list(set(all).difference(comps))

EightBit
01-11-2010, 11:32 PM
Thanks a lot Kojala:
I'm new to Python and hadn't used set method. That is helpful.

However, in revisiting the script, I've discovered that the problem isn't the inversion (at least its not the only problem). I find that if I select some faces, and then I invoke isolateSelect from Python, the faces are not isolated - everything in the viewport is hidden. If I invoke it from the menu, it works, and then it works in Python, but only until the selection is changed. So I don't know if this is a bug or high user density. It appears that invoking isolateSelect from Python doesn't take into account a changed selection. I've also tried the 'u', 'addSelected' and 'ls' methods.
# Attempt to use python for isloateSelect functions
def pixl_isolateSelected():
import maya.cmds as cmds
curPanel = cmds.getPanel (up=1); #Get cam under pointer
# cmds.isolateSelect ( curPanel, ls = 1) #Fails
# cmds.isolateSelect ( curPanel, addSelected = 1) #Fails
# cmds.isolateSelect ( curPanel, u = 1) #Fails

cmds.isolateSelect ( curPanel, state = not(cmds.isolateSelect (curPanel, q=1, state = 1)))
# Works but selection is not updatedThanks again.

kojala
01-13-2010, 03:28 PM
So if I understand correcly, you toggle your python isolateSelect from a hotkey and your script looks for what is selected then it puts those to isolated selection? and when you hit your hotkey again your isolateSelection is turned off?

EightBit
01-13-2010, 10:25 PM
So if I understand correcly, you toggle your python isolateSelect from a hotkey and your script looks for what is selected then it puts those to isolated selection? and when you hit your hotkey again your isolateSelection is turned off?Yes.

What I'd like to do is create a suite of tools for 3 isolate select functions (from my Lightwave days):
1) Toggle isolateSelect for the viewport under the mouse - if it is off, it would hide the unselected components (same function as Show/IsolateSelect/View Selection)
2) Invert the faces which are isolated at a given time (for a given shell)
3) Hide additional faces while working.

However, it appears that if I have a selection of components, if isolateSelect is invoked using Python, it doesn't take the selection into account (whereas it works fine w/Mel). Interestingly, the manual includes an example in which some components are explicitly selected and isolated using Python, but I can't get it to work w/manually selected components.
Thanks.

kojala
01-18-2010, 06:37 AM
sorry for my late answer, but I got this working:


#querying the selected faces, flattening so we get all faces uniquely
faces = cmds.ls(sl=1, fl=1)
#turning on the isolate selected mode
cmds.isolateSelect('modelPanel4', state=1)
#adding the faces one by one cos addDagObject accepts only one at a time
for face in faces:
cmds.isolateSelect('modelPanel4', addDagObject=face)

CGTalk Moderation
01-18-2010, 06:37 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.