Discussion:
[Maya-Python] Custom Repeat Last Command
Marcus Ottosson
2018-07-31 19:26:46 UTC
Permalink
Hi all,

When you call something from a menu, it is added to a Recent Command List
accessible via the Edit menu. Likewise, when you execute a line in the
script editor, the full contents of what you ran is added to said list.

The last entry in that list is repeated on pressing G, or going Edit ->
Repeat 


However, when running something outside of a menu or Script Editor, this
doesn’t happen.

from Qt import QtWidgets
def onclick():
cmds.polyCube()

button = QtWidgets.QPushButton("Press Me")
button.show()
button.clicked.connect(onclick)

Here, a new cube is created on pressing the button, but on hitting G what
you get instead is a new button; as it is repeating the script itself
rather than what happened on pressing the button.

How can I make the contents of onclick trigger on hitting G or pressing
Edit -> Repeat 
?

I’ve tried cmds.evalDeferred("cmds.polyCube()") which I figured would do
the job for me, but doesn’t. Like wise with maya.utils.executeDeferred.
Then I figured I need a custom command plug-in, but then realised polyCube
is also a command and Maya doesn’t care either way.

My next/last resort is creating a new but hidden Maya menu, adding a
command to it and triggering that so as to force Maya into adding it to the
list, and then deleting it. But would love to avoid that.

Any ideas?
--
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 python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCrODZ-1ZM_J-K2uFHYB3VpkBynFzyVkgvgDpcKmewt%2BQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Carlos Rico
2018-07-31 19:55:51 UTC
Permalink
In MEL you can use:

Synopsis: repeatLast [flags]
Flags:
-e -edit
-q -query
-ac -addCommand String
-acl -addCommandLabel String
-cl -commandList Int
-cnl -commandNameList Int
-hl -historyLimit Int
-i -item Int
-nhi -numberOfHistoryItems

Command Type: Command

It is also available in python but it seems tha
t
only accepts MEL code, give it a try.

from maya import cmds
def create_sphere(*args):
cmds.sphere()
cmds.repeatLast(ac='python("from maya import cmds;cmds.sphere()")')

cmds.window(t="repeatLast", w=300)
cmds.columnLayout()
cmds.button(l='create_sphere', c=create_sphere)
cmds.showWindow()

Hope it helps. Cheers
Carlos Rico Adega

<http://www.vimeo.com/16765581> LinkedIn
<https://www.linkedin.com/in/carlos-rico-adega-3250586/>
Post by Marcus Ottosson
Hi all,
When you call something from a menu, it is added to a Recent Command List
accessible via the Edit menu. Likewise, when you execute a line in the
script editor, the full contents of what you ran is added to said list.
The last entry in that list is repeated on pressing G, or going Edit ->
Repeat 

However, when running something outside of a menu or Script Editor, this
doesn’t happen.
from Qt import QtWidgets
cmds.polyCube()
button = QtWidgets.QPushButton("Press Me")
button.show()
button.clicked.connect(onclick)
Here, a new cube is created on pressing the button, but on hitting G what
you get instead is a new button; as it is repeating the script itself
rather than what happened on pressing the button.
How can I make the contents of onclick trigger on hitting G or pressing
Edit -> Repeat 
?
I’ve tried cmds.evalDeferred("cmds.polyCube()") which I figured would do
the job for me, but doesn’t. Like wise with maya.utils.executeDeferred.
Then I figured I need a custom command plug-in, but then realised polyCube
is also a command and Maya doesn’t care either way.
My next/last resort is creating a new but hidden Maya menu, adding a
command to it and triggering that so as to force Maya into adding it to the
list, and then deleting it. But would love to avoid that.
Any ideas?
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCrODZ-1ZM_J-K2uFHYB3VpkBynFzyVkgvgDpcKmewt%2BQ%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCrODZ-1ZM_J-K2uFHYB3VpkBynFzyVkgvgDpcKmewt%2BQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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 python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFzJ14U01qHfn7m4tq%3DcBqSxbjxNcZH01sfwc4tedcwTwVr48A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Marcus Ottosson
2018-07-31 20:30:59 UTC
Permalink
Thanks Carlos!

Once I found out about cmds.repeatLast I discovered this old gem.

- https://groups.google.com/forum/#!topic/python_inside_maya/xfuCYBO6aLg

Problem solved!
Post by Carlos Rico
Synopsis: repeatLast [flags]
-e -edit
-q -query
-ac -addCommand String
-acl -addCommandLabel String
-cl -commandList Int
-cnl -commandNameList Int
-hl -historyLimit Int
-i -item Int
-nhi -numberOfHistoryItems
Command Type: Command
It is also available in python but it seems tha
t
only accepts MEL code, give it a try.
from maya import cmds
cmds.sphere()
cmds.repeatLast(ac='python("from maya import cmds;cmds.sphere()")')
cmds.window(t="repeatLast", w=300)
cmds.columnLayout()
cmds.button(l='create_sphere', c=create_sphere)
cmds.showWindow()
Hope it helps. Cheers
Carlos Rico Adega
<http://www.vimeo.com/16765581> LinkedIn
<https://www.linkedin.com/in/carlos-rico-adega-3250586/>
Post by Marcus Ottosson
Hi all,
When you call something from a menu, it is added to a Recent Command List
accessible via the Edit menu. Likewise, when you execute a line in the
script editor, the full contents of what you ran is added to said list.
The last entry in that list is repeated on pressing G, or going Edit ->
Repeat 

However, when running something outside of a menu or Script Editor, this
doesn’t happen.
from Qt import QtWidgets
cmds.polyCube()
button = QtWidgets.QPushButton("Press Me")
button.show()
button.clicked.connect(onclick)
Here, a new cube is created on pressing the button, but on hitting G what
you get instead is a new button; as it is repeating the script itself
rather than what happened on pressing the button.
How can I make the contents of onclick trigger on hitting G or pressing
Edit -> Repeat 
?
I’ve tried cmds.evalDeferred("cmds.polyCube()") which I figured would do
the job for me, but doesn’t. Like wise with maya.utils.executeDeferred.
Then I figured I need a custom command plug-in, but then realised
polyCube is also a command and Maya doesn’t care either way.
My next/last resort is creating a new but hidden Maya menu, adding a
command to it and triggering that so as to force Maya into adding it to the
list, and then deleting it. But would love to avoid that.
Any ideas?
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCrODZ-1ZM_J-K2uFHYB3VpkBynFzyVkgvgDpcKmewt%2BQ%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCrODZ-1ZM_J-K2uFHYB3VpkBynFzyVkgvgDpcKmewt%2BQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAFzJ14U01qHfn7m4tq%3DcBqSxbjxNcZH01sfwc4tedcwTwVr48A%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAFzJ14U01qHfn7m4tq%3DcBqSxbjxNcZH01sfwc4tedcwTwVr48A%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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 python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOA6A-4nyfp6pS8wRzJDX2LQMw_gExsLMzgiHKdX_twoTw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...