FileReference

FileReference

Represents a file, for example an image

Constructor

new FileReference()

Source:
Properties:
Name Type Description
file string | undefined The path to the saved file in the sketch

Extends

Members

parent

Source:
Inherited From:
Returns the parent element

Methods

clone(parent) → {Node}

Source:
Inherited From:
Creates a deep clone of this node
Parameters:
Name Type Description
parent Node | undefined The new parent of the clone. If it's not defined use the current parent.
Returns:
Type
Node

detach() → {Node}

Source:
Inherited From:
Removes the node from its parent
Returns:
Type
Node

export(dir, nameopt)

Source:
Exports the file to other location
Example
//Export all images to a directory
sketch.pages.forEach(page => {
    page.getAll('MSJSONFileReference').forEach(ref => {
        ref.export('/path/to/export');
    })
})
Parameters:
Name Type Attributes Description
dir string The directory path of the exported file.
name string <optional>
New name for the exported file.

get(type, conditionopt) → {Node|undefined}

Source:
Inherited From:
Search and returns the first descendant node that match the type and condition.
Parameters:
Name Type Attributes Description
type String The Node type
condition function | String <optional>
The node name or a callback to be executed on each node that must return true or false. If it's not provided, only the type argument is be used.
Returns:
Type
Node | undefined

getAll(type, conditionopt) → {Array.<Node>}

Source:
Inherited From:
Search and returns all descendant nodes matching with the type and condition.
Example
//Get the first page
const page = sketch.pages[0];

//Get all colors found in this page
const colors = page.getAll('color');

//Get all colors with specific values
const blueColors = page.getAll('color', (color) => {
 return color.blue > 0.5 && color.red < 0.33
});
Parameters:
Name Type Attributes Description
type String The Node type
condition function | String <optional>
The node name or a callback to be executed on each node that must return true or false. If it's not provided, only the type argument is be used.
Returns:
Type
Array.<Node>

getParent(typeopt, conditionopt) → {Node|Sketch|undefined}

Source:
Inherited From:
Find a node ascendent matching with the type and condition
Parameters:
Name Type Attributes Description
type String <optional>
The node type
condition function | String <optional>
The node name or a callback to be executed on each parent and must return true or false. If it's not provided, only the type argument is be used.
Returns:
Type
Node | Sketch | undefined

getSketch() → {Sketch|undefined}

Source:
Inherited From:
Get the sketch element associated with this node
Returns:
Type
Sketch | undefined

push(key, node) → {Node}

Source:
Inherited From:
Push a new children in this node
Parameters:
Name Type Description
key string The node key
node Node | Object The node/s to insert
Returns:
The new node inserted
Type
Node

replaceWith(node) → {Node}

Source:
Inherited From:
Replace this node with other
Parameters:
Name Type Description
node Node The node to use
Returns:
The new node
Type
Node

set(key, node)

Source:
Inherited From:
Add/replace new childrens in this node
Parameters:
Name Type Description
key string The node key
node Node | Object | Array The node/s to insert

toJson() → {Object}

Source:
Inherited From:
Returns a json with the node data
Returns:
Type
Object