The SmartDraw Bridging Library

The bridging library contains the methods that will allow you to integrate your code and communicate with the SmartDraw application.

In the simplest terms, the briding library allows you to transfer a buffer, object, or string of completed VSON (a 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.VS

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.VS.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.VS.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.VS.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.VS.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.VS.VSDone

/**Calls to the parent iframe indicating that the work to get a VS string 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 VS operation failed for any reason, a message is sent back with an error message. If the VS operation is successful, the child iframe is closed.

@method VSDone

@param {String} vs: A VSON string to turn into a diagram.

@param {Function} callback: A callback function that is fired when the parent iframe signals that is has received the VS. 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 vs =
{
    Version: "20",
    Shape:
    {
        Label: "Hello World"
    }
};
 
SDAPI.VS.VSDone(vs, 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 VSON or inject the VSON into the current diagram succeeds, there will be no callback.
});

SDAPI.VS.CloseDialog

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

@method CloseDialog

SDAPI.VS.CloseDialog();

Get the Bridging Library

You can always build an extension inside SmartDraw using the built-in Javascript Extension editor. However, if you want to build your own server app, you'll want to get these pieces: