问题
I've created my own Graph Editor and Outliner, my problem is that I want to be able to keep the previously selected object selected in my Outliner so that it continues to display on the Graph Editor, but I'm also still able to select the attributes of that object and have the Graph Editor update.
The effect I'm trying to get is what you get from the Auto Load Selected Objects feature in Autodesk Maya's Graph Editor.
I've tried a few things with the selectionConnections, but I haven't quite got my head around it. I can keep the Outliner and Graph Editor from changing by using the lock = 1 code, but the Graph Editor no longer updates with the attributes of the selected object.
Here's what I have so far:
import maya.cmds as mc
mc.window( w = 500 )
mc.paneLayout( configuration = 'vertical2', swp = 1, ps = [ 2, 70, 0 ] )
mc.frameLayout( w = 150, h = 100, lv = 0 )
mc.outlinerEditor( mainListConnection = 'modelList',
selectionConnection = 'modelList',
showShapes = 1,
showReferenceNodes = 0,
showReferenceMembers = 0,
showAttributes = 1,
showSelected = 0,
highlightActive = 1,
showAnimCurvesOnly = 0,
autoExpand = 1,
showConnected = 1,
showDagOnly = 0,
ignoreDagHierarchy = 1,
expandConnections = 0,
showCompounds = 0,
showNumericAttrsOnly = 0,
autoSelectNewObjects = 0,
doNotSelectNewObjects = 1,
transmitFilters = 0,
showSetMembers = 1,
setFilter = 'defaultSetFilter',
lck = 1 )
mc.setParent( '..' )
mc.frameLayout( w = 1, h = 100, lv = 0 )
mc.animCurveEditor( mlc = 'modelList', dak = 1, di = 0, dat = 'off' )
mc.setParent( '..' )
mc.showWindow()
The issue is that when I deselect the object the Outliner highlight turns off the object and the Graph Editor goes blank. I want this to ignore new selections and keep the current object selected, but still able to individually select the attributes.
I hope this makes sense.
回答1:
@Adam, the technique you have proposed works but interferes with the active selection also, which is not ideal. Ideally, your window and what's selected after your window is open must be decoupled. The way you can do that is by:
- Making a
selectionConnection. See the docs.
EDIT: This selection connection need not be locked. To do this:
sel_conn_name = "graphSelConn"
if cmds.selectionConnection(sel_conn_name, q=True, exists=True):
cmds.deleteUI(sel_conn_name)
cmds.selectionConnection(sel_conn_name, lock=False)
Note: selectionConnections are physical UI objects, whose names need to be unique to be re-created, just like windows. Hence we do the exists check as seen above.
EDIT:
This will be the selection connection that your outlinerEditor would be using.
We make another selection connection that the animCurveEditor would be using:
sel_conn_curves_name = "graphSelConnCurves"
if mc.selectionConnection(sel_conn_curves_name, q=True, exists=True):
mc.deleteUI(sel_conn_curves_name)
mc.selectionConnection(sel_conn_curves_name)
Why do we use 2 selection connections and what are the mainListConnection flags for?
The mainListConnection would be the selectionConnection that will be used as the primary/initial source for this editor.
The selectionConnection flag will hold the selectionConnection object that will receive/hold the objects that are selected on this editor.
So in our case, the outlinerEditor will have 'modelList' as its mainListConnection because it needs to start off showing objects that were selected/active. The animCurveEditor would need the objects selected on the outlinerEditor as its primary source, so we use the outlinerEditor's selectionConnection holder.
Feeding the
selectionConnectionto your respectiveoutlinerEditorandanimCurveEditor. This can be done by passing oursel_conn_nameto theselectionConnectionflags of both theoutlinerEditorandanimCurveEditor.EDIT: Locking the selection connection ONLY for the
outlinerEditor, so it won't be affected by changes to the active list. You do this by settinglockMainConnection=Truefor it. Check the docs. You then feed theoutlinerEditor'sselectionConnection, which issel_conn_nameto themainListConnectionofanimCurveEditor. You give theanimCurveEditorit's ownselectionConnectionto work with, in this casesel_conn_curves_name. It is important to unlock main connection of theanimCurveEditoras we want it to reflect selected attributes. We do this by settinglockMainConnection=False.
Here is the modified script for you:
import maya.cmds as mc
mc.window(w=500)
mc.paneLayout(configuration='vertical2', swp=1, ps=[2, 70, 0])
mc.frameLayout(w=150, h=100, lv=0)
sel_conn_name = "graphSelConn"
if mc.selectionConnection(sel_conn_name, q=True, exists=True):
mc.deleteUI(sel_conn_name)
mc.selectionConnection(sel_conn_name)
sel_conn_curves_name = "graphSelConnCurves"
if mc.selectionConnection(sel_conn_curves_name, q=True, exists=True):
mc.deleteUI(sel_conn_curves_name)
mc.selectionConnection(sel_conn_curves_name)
mc.outlinerEditor(mainListConnection='modelList',
selectionConnection=sel_conn_name,
lockMainConnection=True,
showShapes=1,
showReferenceNodes=0,
showReferenceMembers=0,
showAttributes=1,
showSelected=0,
highlightActive=1,
showAnimCurvesOnly=0,
autoExpand=1,
showConnected=1,
showDagOnly=0,
ignoreDagHierarchy=1,
expandConnections=0,
showCompounds=0,
showNumericAttrsOnly=0,
autoSelectNewObjects=0,
doNotSelectNewObjects=1,
transmitFilters=0,
showSetMembers=1,
setFilter='defaultSetFilter'
)
mc.setParent('..')
mc.frameLayout(w=1, h=100, lv=0)
mc.animCurveEditor(mlc=sel_conn_name,
slc=sel_conn_curves_name,
lockMainConnection=False,
dak=0,
di=0,
dat='off')
mc.setParent('..')
mc.showWindow()
Hope that was useful.
回答2:
Update
Ok, I think I've got an answer for this:
import maya.cmds as mc
Xsl = (mc.ls (sl=1, sn=1))[0]
def toastFUNC (arg=0):
mc.animCurveEditor (curveEditor, e=1, lck=1)
mc.window(w=500)
mc.paneLayout( configuration='vertical2', swp=1, ps=[2, 70, 0] )
mc.frameLayout(w=150, h=100, lv=0)
mc.outlinerEditor(mlc='modelList', slc='modelList', showReferenceNodes=0, showReferenceMembers=0, showAttributes=1, showSelected=0, highlightActive=1, showAnimCurvesOnly=0, autoExpand=1,
showConnected=1, showDagOnly=0, ignoreDagHierarchy=1, expandConnections=0, showCompounds=0, showNumericAttrsOnly=0,
autoSelectNewObjects=0, doNotSelectNewObjects=1, transmitFilters=0, showSetMembers=1, setFilter='defaultSetFilter', lck=1, sec=toastFUNC)
mc.setParent('..')
mc.frameLayout(w=1, h=100, lv=0)
curveEditor = mc.animCurveEditor(mlc='modelList', slc='modelList', dak=1, di=0, dat='off', lck=1)
mc.setParent('..')
mc.showWindow()
If anyone has any tips for using the selectionConnection I'd still love to hear some :)
来源:https://stackoverflow.com/questions/27107009/keeping-object-selected-in-the-outliner-after-deselecting-it-in-3d-view