Custom commands

smartLog offers the functionality to dynamically inject custom code that can be executed via right click commands for selected logs inside smartLog. After registering your custom commands, they appear in the Custom right click menu in history mode:

_images/custom_commands.jpg

A selection of logs is contained in a list data type. Each log is contained in a dict type. A selection of logs contains the following format:

[
    {
        'comment': 'Some comment',
        'tags': ['prep', 'WIP'],
        'timestamp': 1578084114,
        'user': 'James Miller',
        'time': 3840,
        'path': '/path/to/project/tzw/tzw_010_040_comp-prep_v008_jmi.nk',
        'log_path': '/path/to/logs/1577865467.json',
        'id': '90e60342-3d6a-4c91-80d7-7303b996d9df'
    },
    {
        'comment': '',
        'tags': [],
        'timestamp': 1577865467,
        'user': 'Steve Fisher',
        'time': 9300,
        'path': '/path/to/project/mnt/mnt_300_020_comp_v027_sfi.nk',
        'log_path': '/path/to/logs/1577865498.json',
        'id': '0e811744-b3c8-4259-ae56-d20f5b86710b'
    },
    ...
]

Each dict represents one time log. When writing custom functions, these functions can iterate over this list and execute anything you need. This can be Nuke related functionality but also calling a database, your file system or anything else that you can imagine.

How to create a custom command

Open the following module from your smartLog installation:

<Path to smartLog_vX.X.X>/smartLog/custom/commands.py

This module contains already two custom commands for demonstration purposes.

1) The first custom command sticky_from_timelogs will create StickyNotes in the DAG for each selected log. A StickyNote’s label wil be populated with a selection of data from each log.

2) The second custom command import_script_into_dag will insert the nodes of the working files of the selected logs into the DAG.

At the bottom of the above stated module you need to register the custom commands to smartLog so that they appear in the Custom menu:

osl.register_custom_command("Sticky from TimeLogs", sticky_from_timelogs
osl.register_custom_command("Import Script into DAG", import_script_into_dag)

register_custom_command expects two arguments. The first argument is the label as it will appear in the smartLog’s right click menu. The second argument is the callable to execute. This is a callable, so don’t add round brackets to it.

This is how it looks when the custom commands have been registered:

_images/custom_commands.jpg