How the SmartDraw API Works

SmartDraw's API is the last piece you'll need to understand when creating your own extension. These are the methods that will allow you to integrate your code and communicate with the SmartDraw application.

In the simplest terms, the API allows you to transfer a buffer, object, or string of completed SDON (Smartdraw's mark up language for diagrams) to SmartDraw. It also allows you to store and retrieve user input and preferences for your extension.

Read below for a detailed explanation for each method.

SDAPI.SDON

Controller for interacting with the app's plugin interface via cross-origin iframe communication.

SDAPI.CrossWindowPluginMessage - Object for sending messages back and forth between iframes hosted on different domains.

/**Object for sending messages back and forth between iframes hosted on different domains.*/
SDAPI.CrossWindowPluginMessage = function ()
{
    /**Anything. Any data to transport from one window to another.*/
    this.Payload = null;
    /**Boolean. Whether or not the command issued has been successfully completed by the parent to the iframe.*/
    this.Success = false;
    /**String. An error message sent by the parent iframe informing the child iframe that the operation failed and why.*/
    this.ErrorMessage = null;
};

SDAPI.SDON.GetUserSettings

This function gets the settings string for the current user. Will fall back to the default settings for the extension if the user has no settings set with the extension.

@method GetUserSettings

@param {Function} callback: A callback function that is fired when the data arrives from the parent iframe. Receives a SDAPI.CrossWindowPluginMessage as a parameter where the Payload property is a string of user settings data if the operation succeeded or null if the operation failed.

SDAPI.SDON.GetUserSettings(function (crossWindowMessage)
{
    if (crossWindowMessage.Payload == null || crossWindowMessage.Success === false)
    {
        if (crossWindowMessage.ErrorMessage != null) console.log(crossWindowMessage.ErrorMessage);
    }
    else
    {
        alert("Server returned user settings: " + crossWindowMessage.Payload);
    }
});

SDAPI.SDON.SetUserSettings

Sets the settings for a user with the extension. Any value passed in is turned into a string.

@method SetUserSettings

@param {Anything} settings: The user settings to store for the current user.

@param {Function} callback: A callback function that is fired when the call to set the user's settings completes. Receives a SDAPI.CrossWindowPluginMessage as a parameter where the Payload property is a boolean that is set to true if the operation succeeded or false if it did not succeed.

var currentSettings = "An arbitrary string of user settings data.";
SDAPI.SDON.SetUserSettings(currentSettings, function (crossWindowMessage)
{
    if (crossWindowMessage.Payload === false || crossWindowMessage.Success === false)
    {
        if (crossWindowMessage.ErrorMessage != null) console.log(crossWindowMessage.ErrorMessage);
    }
    else
    {
        alert("Set user settings to " + currentSettings);
    }
});

SDAPI.SDON.SDONDone

Calls to the parent iframe indicating that the work to get a SDON string or Blob has been completed and is passed back to the parent iframe to be stored as a document or injected into the current document.

If the SDON operation fails for any reason, you'll be sent an error message. If the SDON operation is successful, the child iframe will be closed.

@method SDONDone

@param {Anything} vs: An SDON object, string, or blob representing the data to turn into a diagram.

@param {Function} callback: A callback function that is fired when the parent iframe signals that is has received the SDON. Receives a SDAPI.CrossWindowPluginMessage as a parameter where the Payload property is a boolean that is set to true if the operation succeeded or false if it did not succeed.

var sdon =
{
    Version: "20",
    Shape:
    {
        Label: "Hello World"
    }
};
 
SDAPI.SDON.SDONDone(sdon, function (crossWindowMessage)
{
    if (crossWindowMessage.Payload === false || crossWindowMessage.Success === false)
    {
        if (crossWindowMessage.ErrorMessage != null) console.log(crossWindowMessage.ErrorMessage);
    }
 
    //if the call telling SmartDraw to create a diagram from the SDON or inject the SDON into the current diagram succeeds, there will be no callback.
});

SDAPI.SDON.CloseDialog

Calls to the parent iframe and tells it to close the iframe and modal. There is no callback.

@method CloseDialog

SDAPI.SDON.CloseDialog();

Get the Bridging Library

When you're ready to make your own extension: