Saver: Server basics

From The Foundry MODO SDK wiki
Jump to: navigation, search

A Saver is a plug-in server that can write internal nexus objects in a specific file format. Typically the objects are of image and scene types.

Overview

When the modo user selects "Save As..." from the menu, they are presented with a dialog containing a set of formats for the type of object they are saving: image savers for images and scene savers for scenes. Based on the format they choose, a server matching that format will be created to write the object to the file. The internal name of the server is used to reference the format in save commands.

Headers

Tags

  • LXsSAV_OUTCLASS -- the GUID or alias for the object type that this saver can write (e.g. LXa_IMAGE). Only this type of object will be passed to the saver.
  • LXsSAV_DOSTYPE -- the three-character file extension to be used by default (e.g. JPG).
  • LXsSAV_OVERWRITE -- set to "1" this indicates that the server needs to get the real, final path for the destination file. If not set the saver may be told to save the file to a temporary location before it's copied over the real file.

Sample Methods

The plug-in server class derives from CLxImpl_Saver, and exports the ILxSaver interface.

Saver::Verify()

The Verify() method is called before saving to allow the server to generate info or warnings. For example there may be data in the source object that can't be saved in this format. The message can be set to show that, to give users a chance to change formats to avoid losing data.

        LxResult
sav_Verify (
        ILxUnknownID            source,
        ILxUnknownID            message)     LXx_OVERRIDE
{
        CLxUser_Message         msg (message);

        if (source_data_is_ok (source))
                return LXe_OK;

        msg.SetCode (LXe_WARNING);
        msg.SetMsg ("mymessagetable", "myerrormessagekey");
        return LXe_OK;
}
Saver::Save()

The Save() method does the main work of the server, reading the contents of the source object and writing that data to the destination file.

        LxResult
sav_Save (
        ILxUnknownID            source,
        const char             *filename,
        ILxUnknownID            monitor)     LXx_OVERRIDE
{
        CLxUser_Monitor         mon (monitor);

        if (!open_file_write (filename))
                return LXe_IO_ERROR;

        < write data to file >

        close_file ();
        return LXe_OK;
}

Helper Classes

The CLxSceneSaver class can be used to write scene savers. See Scene (lxu-scene.hpp).