Keeping Object Selected In The Outliner After Deselecting It In 3D View
Solution 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
selectionConnection
to your respectiveoutlinerEditor
andanimCurveEditor
. This can be done by passing oursel_conn_name
to theselectionConnection
flags of both theoutlinerEditor
andanimCurveEditor
.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=True
for it. Check the docs. You then feed theoutlinerEditor's
selectionConnection
, which issel_conn_name
to themainListConnection
ofanimCurveEditor
. You give theanimCurveEditor
it's ownselectionConnection
to work with, in this casesel_conn_curves_name
. It is important to unlock main connection of theanimCurveEditor
as 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.
Solution 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 :)
Post a Comment for "Keeping Object Selected In The Outliner After Deselecting It In 3D View"