Document

Vecta.Document

new Vecta.Document()

Vecta document object.

In the Vecta application, the created Vecta.Document will always return the currently loaded drawing called the active document.

See also:

Methods

.created() Returns: string

Get the document created date.

Returns:

Returns the drawing's created date in Mm dd, YY

.creator() Returns: string

Get the document creator.

Returns:

Returns the creator's name if available.

.edited() Returns: string

Get document last edited date.

Returns:

Returns the drawing's last edited date in Mm dd, YY

.id() Returns: string

Get the document id.

Returns:

Returns the document ID.

.insertPage([id], [opts]) Returns: Promise

Creates a new page in the document

NameTypeAttributesDescription
idstringoptional

The Page ID to set. If not provided, a new Page ID will be generated.

optsobjectoptional

Override the default for page setup

Returns:

Returns a promsie that will resolve the created page

Examples:
Vecta.activeDoc.insertPage().then(function (page) {
   console.log(page); // Vecta.Page ...
});

.json([data]) Returns: object

Get or set custom json data for document.

NameTypeAttributesDescription
dataobjectoptional

Custom json to set. If not provided, returns the custom json.

Returns:

Returns custom json

Examples:
Vecta.activeDoc.json({a: 1, b: 2});
console.log(Vecta.activeDoc.json()); // {a: 1, b: 2}

.layers([id]) Returns: Vecta.Layer|Vecta.Layer[]

Get all layers or a single layer in the document.

NameTypeAttributesDescription
idstringoptional

The layer ID to get or undefined if get all.

Returns:

Returns Vecta.Layer or and array of Vecta.Layer.

Examples:
var layers = Vecta.activeDoc.layers();
See also:

.loadPage(id, [opts]) Returns: Promise

Load an existing page in document by providing an ID

NameTypeAttributesDescription
idstring

ID of page

optsobjectoptional

options to load page

NameTypeAttributesDescription
activebooleanoptional

Whether to set as active page. Defaults to true

syncbooleanoptional

Whether to sync page. Defaults to true

page_onlybooleanoptional

Whether to load page only. Defaults to false

shapesstring[]optional

If provided, only load shapes with given id

Returns:

Returns a promise that will resolve the loaded page

.pages() Returns: array

Returns a list of page id in the document.

Returns:

An array of page id in the document

.stencils() Returns: Vecta.Stencil[]

Get a list of stencils currently opened in the document.

Returns:

Returns an array of stencil object.

Examples:
console.log(Vecta.activeDoc.stencils());
See also:

.styles(attr) Returns: string|number|null

Get the document default styling.

NameTypeDescription
attrstring

The attribute to get. Can be any of the following:

stroke, stroke-width, stroke-opacity, stroke-dasharray, stroke-linecap, stroke-linejoin, fill, fill-opacity, font-family, font-size, font-weight, font-style, font-fill, font-fill-opacity, text-decoration, text-anchor, text-align

Returns:

Returns the default style.

Examples:
console.log(Vecta.activeDoc.styles('fill')); //#ffffff

.title([title]) Returns: string

Get or set the document's title.

NameTypeAttributesDescription
titlestringoptional

The new document title

Returns:

Returns document title

Examples:
console.log(Vecta.activeDoc.title()); //Untitled Drawing
console.log(Vecta.activeDoc.title('Hello world!')); //sets Hello world! as the document title.
Electra Cloud