Ok, when I change the trigger from pressCommand to releaseCommand it works
for me.
The reason I think, is because when you press you put Maya in a suspended
mode. Awaiting a release. During the release it would resume normal duties
like updating the GUI and viewport. But, because you create a reference
while being pressed, you prevent Maya from detecting a release. As though
you were erasing its memory of anything being pressed. That could explain
why you would have to forcefully refresh Maya after exiting the context.
Full example.
import types
from maya import cmds
def func_test():
nodes = cmds.file("scenes/temp.ma", reference=True, returnNewNodes=True)
cmds.select(nodes)
class PickerContext(object):
CONTEXT_NAME = "PickerContext"
def __init__(self, func, **kwargs):
self.__undo_mode = kwargs.get("undoMode", "step")
self.__projection = kwargs.get("projection", "viewPlane")
self.__space = kwargs.get("space", "screen")
self.__cursor = kwargs.get("cursor", "crossHair")
self.__selected_nodes = list()
if not isinstance(func, (types.FunctionType, types.ClassType,
types.MethodType)):
raise BaseException("Invalid argument given !!!\n\tGive a
function or class with matrix for argument...")
self.func = func
def build(self):
if cmds.draggerContext(self.CONTEXT_NAME, exists=True):
cmds.setToolTo("selectSuperContext")
cmds.selectMode(object=True)
cmds.deleteUI("PickerContext")
cmds.draggerContext(
self.CONTEXT_NAME,
releaseCommand=self.on_press,
name=self.CONTEXT_NAME,
)
def launch(self):
self.build()
cmds.setToolTo(self.CONTEXT_NAME)
def on_press(self):
self.func()
# Create a reference
cmds.file(new=True, force=True)
cmds.polyCube()
cmds.file(rename="temp.ma")
cmds.file(save=True, force=True)
cmds.file(new=True, force=True)
# Pick
cmds.sphere(radius=0.5)
picker_ctx = PickerContext(func_test)
picker_ctx.launch()
On 28 February 2017 at 09:05, Rémi Deletrain <[email protected]>
wrote:
> Je n'ai rien trouvé jusqu'à présent pour faire un refresh de l'outliner.
> J'ai essayé de forcer les sélections dans le code pour remettre à jour
> (car après avoir quitter le DraggerContext il n'y a que ça qui fait le
> refresh) mais ça ne change rien non plus..
>
> ============================================================
> ============================================================
> =========================
>
> I have not found anything to make a refresh of the outliner.
> I tried to force the selections in the code to update (because after
> leaving the DraggerContext there is only that which makes the refresh) but
> it does not change either ...
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/python_inside_maya/3659c450-477b-4ca5-aa7e-
> 11cf9e4b5fbf%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/3659c450-477b-4ca5-aa7e-11cf9e4b5fbf%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>
--
*Marcus Ottosson*
[email protected]
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCj-AanB6isLNc4U-RBgydYTn0FJf4D%3DS%2Bk7ZtnHTDPBA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.