treeView query in python?

treeView query in python?

Anonymous
Not applicable
1,137 Views
6 Replies
Message 1 of 7

treeView query in python?

Anonymous
Not applicable
hi
suppose Hi have a treeView control like this

string $window = `window`;
string $layout = `formLayout`;

string $control = `treeView -parent $layout -numberOfButtons 3 -abr false`;

formLayout -e
-attachForm $control "top" 2
-attachForm $control "left" 2
-attachForm $control "bottom" 2
-attachForm $control "right" 2
$layout;

showWindow $window;

treeView -edit -addItem "layer 1" "" $control;
treeView -edit -addItem "layer 2" "layer 1" $control;
treeView -edit -addItem "layer 3" "layer 2" $control;


and I want to query the the itemIndex or the itemParent of the 'layer 2'

I can do :

treeView  -itemIndex "layer 2" -q $control; // result 0
treeView -itemParent "layer 2" -q $control; // result layer 1
treeView -itemExists "layer 2" -q $control; // result 1


but if I want to use Python?
this is the same window in python

import maya.cmds as cmds

from maya import cmds
window = cmds.window()
layout = cmds.formLayout()

control = cmds.treeView( parent = layout, numberOfButtons = 3, abr = False )

cmds.formLayout(layout,e=True, attachForm=(control,'top', 2))
cmds.formLayout(layout,e=True, attachForm=(control,'left', 2))
cmds.formLayout(layout,e=True, attachForm=(control,'bottom', 2))
cmds.formLayout(layout,e=True, attachForm=(control,'right', 2))

cmds.showWindow( window )

cmds.treeView( control, e=True, addItem = ("layer 1", ""))
cmds.treeView( control, e=True, addItem = ("layer 2", "layer 1"))
cmds.treeView( control, e=True, addItem = ("layer 3", "layer 2"))


about the query if I write

cmds.treeView( control, q =1, itemIndex = 'layer 2' ) 


I got

# TypeError: Flag 'itemIndex' must be passed a boolean argument when query flag is set #


than I write

cmds.treeView( control, q =1, itemIndex = 1) 


but this ime he's looking for the item name

# RuntimeError: Item '' was not found in the treeview #


how is the sintax for this query in python?
thanks in advance
0 Likes
1,138 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
Try:

cmds.treeView (control, itemIndex=("layer 2"), q=True) 
cmds.treeView (control, itemParent=("layer 3"),q=True)
cmds.treeView (control, itemExists=("layer 3"),q=True)
0 Likes
Message 3 of 7

Anonymous
Not applicable
thanks for the answer
unfortunately I got the same error

# TypeError: Flag 'itemExists' must be passed a boolean argument when query flag is set #

:(
0 Likes
Message 4 of 7

Anonymous
Not applicable
Hi, I've been tearing my hair out over this problem too, did you/anyone find a solution? Is it just not possible with Python?
0 Likes
Message 5 of 7

Anonymous
Not applicable
This is working for me in 2011 x64 on windows.
0 Likes
Message 6 of 7

Anonymous
Not applicable
Try:

cmds.treeView (control, itemIndex=("layer 2"), q=True) 
cmds.treeView (control, itemParent=("layer 3"),q=True)
cmds.treeView (control, itemExists=("layer 3"),q=True)


It also works for me in 2011, but not in 2009. I dont have 2010.
I think this is actually a bug that they fixed in either 2010 or 2011.
0 Likes
Message 7 of 7

Anonymous
Not applicable
Has anyone figured out how to remove one item from the treeView. It has a removeAll but thats not helpful. Thanks!
0 Likes