Using userData in export hooks

Hey!

I want to trigger some action after the export of a clip has ended. The information I need is the absolute file path of the exported clip and the preset that was used. Unfortunately I can’t get this info from just one hook.
post_export() gives me the preset path in info[“presetPath”].
post_export_asset gives the destination and the resolved path, so I can construct an absolute path from that.

In order to get these two informations in one I thought I could populate the userData in pre_export with the presetPath, since - according to the manual - the userData is always passed downstream:
https://help.autodesk.com/view/FLAME/2022/ENU/?guid=Flame_API_Python_Hooks_Reference_Python_Hooks_Tips_html

Here’s what I did:

def pre_export(info, userData, *args, **kwargs):
	if not userData:
		userData = {}
	userData["presetPath"] = info["presetPath"]
	return userData


def post_export_asset(info, userData, *args, **kwargs):
	print(userData)

Unfortunately the userData printed from post_export_asset is None. Isn’t returning something from the hook the supposed method for passing the userData? I couldn’t find anything in the docs or examples concerning this.

@fredwarren How would I pass the data correctly?

Thanks in advance!
Claus

I found a solution. In case anybody else comes across this:

userData was always None, because I didn’t set it initially in my PyExporter. I would have expected, that it could also be filled at any point during the hooks. So always insert some userData here:

exporter.export(
    sources=selection,
    preset_path=preset,
    output_directory=output_dir,
    hooks_user_data={
        "some_key": "some_value",
    }
)

A little example in the documentation would have been nice for understanding this concept. :slight_smile:

I just couldn’t get the custom hooks as a parameter working:

exporter.export(
    sources=selection,
    preset_path=preset,
    output_directory=output_dir,
    hooks=[some_custom_hook]
)

def some_custom_hook(info, userData):
    print("CUSTOM HOOK CALLED")

This hook is never called. What am I doing wrong here?