application

The application module exposes useful information about XD's state, along with APIs for exporting content.

Example

// Generate PNG rendition of the selected node
let application = require("application");
let fs = require("uxp").storage.localFileSystem;
let file = await fs.getFileForSaving();
let shape = selection.items[0];
let renditions = [{
     node: shape,
     outputFile: file,
     type: application.RenditionType.PNG,
     scale: 2
}];
application.createRenditions(renditions).then(function (results) {
    // ...do something with outputFiles on disk...
});

Example

let application = require("application");
console.log("Version:", application.version);        // e.g. "13.0.21.3"
console.log("XD locale:", application.appLanguage);  // e.g. "en"
console.log("OS locale:", application.systemLocale); // e.g. "en_US"

application.createRenditions(renditions)

Generate renditions of nodes in the document in a batch. Overwrites any existing files without warning.

A single createRenditions() call can generate any number of renditions, including multiple renditions of the same node (with different output settings) or renditions of multiple different nodes. Only one createRenditions() call can be executing at any given time, so wait for the Promise it returns before calling it again.

Kind: static method of application
Returns: Promise<Array<RenditionResult>, string> - Promise which is fulfilled with an array of RenditionResults (pointing to the same outputFiles that were originally passed in, or rejected with an error string if one or more renditions failed for any reason.

Param Type Description
renditions Array<RenditionSettings> List of renditions to generate

Typedef RenditionSettings

All rendition settings fields are required (for a given rendition type) unless otherwise specified.

Property Type Description
node !SceneNode Root of scenegraph subtree to render. This may be any node in the scenegraph, regardless of the current edit context.
outputFile !uxp.storage.File File to save the rendition to (overwritten without warning if it already exists)
type string File type: RenditionType.PNG, JPG, PDF, or SVG
scale number (PNG & JPG renditions) DPI multipler in the range [0.1, 100], e.g. 2.0 for @2x DPI.
quality number (JPG renditions) Compression quality in the range [1, 100].
background ?Color (PNG & JPEG renditions) Alpha component ignored for JPG. Optional: defaults to transparent for PNG, solid white for JPG.
minify boolean (SVG renditions) If true, SVG code is minified.
embedImages boolean (SVG renditions) If true, bitmap images are stored as base64 data inside the SVG file. If false, bitmap images are saved as separate files linked from the SVG code.

Typedef RenditionResult

Property Type Description
outputFile !uxp.storage.File File the rendition was written to (equal to outputFile in RenditionSettings)

application.version : string

Adobe XD version number in the form "major.minor.patch.build"

Kind: static property of application
Read only: true


application.appLanguage : string

Current language the application UI is using. This may not equal the user's OS locale setting: it is the closest locale supported by XD - use this when you want your plugin's UI to be consistent with XD's UI. Specifies language only, with no region info (e.g. "fr", not "fr_FR").

Kind: static property of application
Read only: true


application.systemLocale : string

User's OS-wide locale setting. May not match the XD UI, since XD does not support all world languages. Includes both language and region (e.g. "fr_CA" or "en_US").

Kind: static property of application
Read only: true

results matching ""

    No results matching ""