ynput / ayon-3dsmax

3dsMax addon for AYON
Apache License 2.0
1 stars 1 forks source link

Use AYON event system for 3dsMax Callback #5

Open moonyuet opened 1 year ago

moonyuet commented 1 year ago

Is there an existing issue for this?

Current Behavior:

Why isn't 3dsmax using the OpenPype event system like the other hosts? Let's create an issue to track that and fix that in a separate PR. Each host should try and emit the events in a DCC agnostic way so that global OpenPype tooling could hook into it, like scene saves, etc.

_Originally posted by @BigRoy in https://github.com/ynput/OpenPype/pull/5499#discussion_r1315901738_

Expected Behavior:

  1. Using AYON event system for the callbacks in 3dsmax.
  2. Can take references from the Maya hosts.

Version

3.16.5

What platform you are running AYON on?

Windows

Steps To Reproduce:

n/a

Are there any labels you wish to add?

Relevant log output:

No response

Additional context:

No response

[cuID:OP-6769]

BigRoy commented 11 months ago

For more details on Max's event system see these documentation pages:

As such it looks like that on host install we should be able to do this in OpenPype:

pseudocode

from functools import partial
from openpype.lib import (
    register_event_callback,
    emit_event
)

import pymxs
rt = pymxs.runtime

def emit_event_notification_param(event):
    notification = rt.callbacks.notificationParam()
    emit_event(event, {"notificationParam": notification})

def register_callbacks():

    id = rt.Name("openpype_callbacks")

    # init
    rt.callbacks.addScript(
        rt.Name('postSystemStartup'),
        partial(emit_event_notification_param, "init"),
        id=id
    )

    # open
    # todo: we might want filePreOpenProcess and filePostOpenProcess?
    rt.callbacks.addScript(
        rt.Name('filePreOpen'),
        partial(emit_event_notification_param, "before.open"),
        id=id
    )
    rt.callbacks.addScript(
        rt.Name('filePostOpen'),
        partial(emit_event_notification_param, "open"),
        id=id
    )

    # save
    # todo: we might want filePreSaveProcess and filePostSaveProcess?
    rt.callbacks.addScript(
        rt.Name('filePreSave'),
        partial(emit_event_notification_param, "save"),
        id=id
    )
    rt.callbacks.addScript(
        rt.Name('filePostSave'),
        partial(emit_event_notification_param, "after.save"),
        id=id
    )

    # new
    # todo: not entirely sure whether systemPostNew means "new file"
    rt.callbacks.addScript(
        rt.Name('systemPostNew'),
        partial(emit_event_notification_param, "new"),
        id=id
    )

Then that would roughly mimic what Maya does by emitting OpenPype events:

Which is implemented in Maya here and then install also install callbacks to those here.


Removing all callbacks should then be as easy as:

rt.callbacks.removeScripts(id=rt.name("openpype_callbacks"))

I have never worked in 3DsMax so take this with a grain of salt.