Run function/scriptJob when playback stops

118 views
Skip to first unread message

Wesley Chandler

unread,
May 7, 2018, 11:43:06 AM5/7/18
to Python Programming for Autodesk Maya
Hi guys,

Does anyone know a way to run a function or scriptJob after playback stops?   

I'm running a one-time scriptJob that launches cmds.play(record=True), and after its done recording, I wanted to run a couple other commands after.

Much thanks!

Justin Israel

unread,
May 7, 2018, 3:37:53 PM5/7/18
to python_in...@googlegroups.com
What about a one time "idle" scriptJob event? 

--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/9ed9fc90-ef76-4dbc-8e18-00bbb84ba55b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Wesley Chandler

unread,
May 7, 2018, 5:19:32 PM5/7/18
to Python Programming for Autodesk Maya
Oh thanks Justin, thats a good idea! I'll give it a try.


On Monday, May 7, 2018 at 3:37:53 PM UTC-4, Justin Israel wrote:
What about a one time "idle" scriptJob event? 

On Tue, May 8, 2018, 3:43 AM Wesley Chandler <heyw...@gmail.com> wrote:
Hi guys,

Does anyone know a way to run a function or scriptJob after playback stops?   

I'm running a one-time scriptJob that launches cmds.play(record=True), and after its done recording, I wanted to run a couple other commands after.

Much thanks!

--
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+unsub...@googlegroups.com.

Marcus Ottosson

unread,
May 7, 2018, 6:30:43 PM5/7/18
to python_in...@googlegroups.com

There’s also this.

from maya.api import OpenMaya as om

def onPlayingBack(state, _):
  if state is False:
    print("# Playback stopped!")

id = om.MConditionMessage.addConditionCallback("playingBack", onPlayingBack)
# om.MMessage.removeCallback(id)

It’ll catch all sorts of “playing” events, including your cmds.play(), except the hold-K-and-drag context. Not relevant in this case, but pointing it out anyway for future readers.

What about a one time “idle” scriptJob event?

Not sure about the scriptJob version, but for om.MTimerMessage.addTimerCallback() which is also called during times of idle, it actually gets called during playback as well, as Maya may sleep for some time inbetween each frame. E.g. if a scene natively runs at 10 ms/frame, but playback is locked to 30 ms/frame, then there’s 20 ms of idle inbetween each frame.


On 8 May 2018 at 06:19, Wesley Chandler <heyw...@gmail.com> wrote:
Oh thanks Justin, thats a good idea! I'll give it a try.

On Monday, May 7, 2018 at 3:37:53 PM UTC-4, Justin Israel wrote:
What about a one time "idle" scriptJob event? 

On Tue, May 8, 2018, 3:43 AM Wesley Chandler <heyw...@gmail.com> wrote:
Hi guys,

Does anyone know a way to run a function or scriptJob after playback stops?   

I'm running a one-time scriptJob that launches cmds.play(record=True), and after its done recording, I wanted to run a couple other commands after.

Much thanks!

--
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+unsubscribe@googlegroups.com.

--
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+unsub...@googlegroups.com.

Justin Israel

unread,
May 7, 2018, 7:49:01 PM5/7/18
to python_in...@googlegroups.com


On Tue, May 8, 2018, 10:30 AM Marcus Ottosson <konstr...@gmail.com> wrote:

There’s also this.

from maya.api import OpenMaya as om

def onPlayingBack(state, _):
  if state is False:
    print("# Playback stopped!")

id = om.MConditionMessage.addConditionCallback("playingBack", onPlayingBack)
# om.MMessage.removeCallback(id)

It’ll catch all sorts of “playing” events, including your cmds.play(), except the hold-K-and-drag context. Not relevant in this case, but pointing it out anyway for future readers.


Nice. This way looks better than my idle suggestion. 

What about a one time “idle” scriptJob event?

Not sure about the scriptJob version, but for om.MTimerMessage.addTimerCallback() which is also called during times of idle, it actually gets called during playback as well, as Maya may sleep for some time inbetween each frame. E.g. if a scene natively runs at 10 ms/frame, but playback is locked to 30 ms/frame, then there’s 20 ms of idle inbetween each frame.

On 8 May 2018 at 06:19, Wesley Chandler <heyw...@gmail.com> wrote:
Oh thanks Justin, thats a good idea! I'll give it a try.

On Monday, May 7, 2018 at 3:37:53 PM UTC-4, Justin Israel wrote:
What about a one time "idle" scriptJob event? 

On Tue, May 8, 2018, 3:43 AM Wesley Chandler <heyw...@gmail.com> wrote:
Hi guys,

Does anyone know a way to run a function or scriptJob after playback stops?   

I'm running a one-time scriptJob that launches cmds.play(record=True), and after its done recording, I wanted to run a couple other commands after.

Much thanks!

--
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_m...@googlegroups.com.

--
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_m...@googlegroups.com.

--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOD752S68uCbG-fgeKkzkj_ovH7woX3yfVXjaEVnv83BKw%40mail.gmail.com.

Wesley Chandler

unread,
May 7, 2018, 8:00:10 PM5/7/18
to Python Programming for Autodesk Maya
Thank you guys! This is fantastic!


On Monday, May 7, 2018 at 6:30:43 PM UTC-4, Marcus Ottosson wrote:

There’s also this.

from maya.api import OpenMaya as om

def onPlayingBack(state, _):
  if state is False:
    print("# Playback stopped!")

id = om.MConditionMessage.addConditionCallback("playingBack", onPlayingBack)
# om.MMessage.removeCallback(id)

It’ll catch all sorts of “playing” events, including your cmds.play(), except the hold-K-and-drag context. Not relevant in this case, but pointing it out anyway for future readers.

What about a one time “idle” scriptJob event?

Not sure about the scriptJob version, but for om.MTimerMessage.addTimerCallback() which is also called during times of idle, it actually gets called during playback as well, as Maya may sleep for some time inbetween each frame. E.g. if a scene natively runs at 10 ms/frame, but playback is locked to 30 ms/frame, then there’s 20 ms of idle inbetween each frame.

On 8 May 2018 at 06:19, Wesley Chandler <heyw...@gmail.com> wrote:
Oh thanks Justin, thats a good idea! I'll give it a try.

On Monday, May 7, 2018 at 3:37:53 PM UTC-4, Justin Israel wrote:
What about a one time "idle" scriptJob event? 

On Tue, May 8, 2018, 3:43 AM Wesley Chandler <heyw...@gmail.com> wrote:
Hi guys,

Does anyone know a way to run a function or scriptJob after playback stops?   

I'm running a one-time scriptJob that launches cmds.play(record=True), and after its done recording, I wanted to run a couple other commands after.

Much thanks!

--
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+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/9ed9fc90-ef76-4dbc-8e18-00bbb84ba55b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages