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!

On Tue, 31 Jul 2018 at 20:56, Carlos Rico <[email protected]> wrote:

> 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/>
> [email protected]
>
> O mar., 31/07/2018 ás 21:26, Marcus Ottosson (<[email protected]>)
> escribiu:
>
>> 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 [email protected].
>> 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 [email protected].
> 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 [email protected].
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.

Reply via email to