.. _render_integrations:

Render integrations
===================
smartCache offers functionality to submit the rendering of your smartCache
nodes to a third party render engine, e.g. Deadline, Tractor, Royal Render,
etc. But you can also use this functionality to trigger your own render logic
and execute whatever code you need to execute.

.. note::

    Note that smartCache offers the needed framework for render integrations.
    You will need to provide th logic to submit the caches to your render
    engine yourself. The reason is that this process is highly independent to
    everyone's needs.

This is how it works
--------------------
Navigate to this folder:

``[PATH TO smartCache_vX.X.X]/cpXX/smartCache/render_integration``

Where ``[PATH TO smartCache_vX.X.X]`` is the absolute path of your smartCache
installation and ``cpXX`` is the Python version you use. If unsure execute this
line to get information about it inside Nuke's ScriptEditor:

``import sys; print("cp{0}{1}".format(sys.version_info[0], sys.version_info[1]))``

The ``render_integration`` package contains a ``deadline.py`` module. This
module serves as an example how this works.

This ``deadline.py`` module contains a class ``DeadlineRenderIntegration`` that
inherits from ``smartCache.render_integration.base.RenderIntegrationBase``.
Every render integration should inherit from that class. This is an abstract
base class that provides the required interface. When implementing a concrete
render integration class you will need to implement the following methods:

- **label:** The label to use for the render button in the render dialog, see
  the following screenshot.
- **process:** The logic to execute to render the cache or submit the cache for
  rendering. When executing this method, smartCache automatically passes the
  information about the write nodes (embedded in the selected smartCache nodes)
  as well as the entered frame range to it. So you don't need to find out that
  information yourself anymore.

.. image:: img/render_integrations/render_integrations.png

.. note::

    Please note again that the deadline.py is not complete! You need to
    implement the ``process`` method to your needs to submit the smartCache
    rendering to your farm.

Once you have implemented your custom render integration class you need
to add it to:

``smartCache.render_integration.__init__.RENDER_INTEGRATIONS``

It will then show up in the smartCache render dialog's graphical user
interface automatically for your.

During development we encourage you to reload the module so that you see
code changes immediately::

    from importlib import reload  # Only needed for python-3

    from smartCache.render_integration import deadline
    reload(deadline)
    from smartCache import render_integration
    reload(render_integration)