Selection

Vecta.Selection

new Vecta.Selection([shapes])

Vecta selection objects are essentially an array of shapes on a drawing where you can perform shape operations.

NameTypeAttributesDescription
shapesVecta.Shape|Vecta.Shape[]optional

A single shape or an array of shapes to be added to the selection

Examples:
var select = new Vecta.Selection(); //Create an empty selection

Methods

.add(shapes) Returns: Vecta.Selection

Add shapes into the selection object.

NameTypeDescription
shapesVecta.Shape|Vecta.Shape[]

A single shape or an array of shapes

Examples:
var select = new Vecta.Selection(), //Create an empty selection
    rect = new Vecta.activePage.drawRect(0, 0, 50, 50); //Draw a rect

select.add(rect); //Add a rectangle shape into the selection

.box() Returns: object

Get the selection object bounding box.

Returns:

{x: number, y: number, width: number, height: number}

Examples:
var rect = new Vecta.activePage.drawRect(0, 0, 50, 50), //Draw a rect
    select = new Vecta.Selection(rect); //Create a new selection object with a single shape

console.log(select.box()); //{x: 0, y: 0, width: 50, height: 50}

.clear() Returns: Vecta.Selection

Clear or remove all shapes from selection object.

Examples:
var rect = new Vecta.activePage.drawRect(0, 0, 50, 50), //Draw a rect
    select = new Vecta.Selection(rect); //Create a new selection object with a single shape

select.clear(); //Remove all shapes from selection object

.difference() Returns: Promise.<Vecta.Shape[]>

Perform difference operation on shapes in the selection object.

Locked shapes will NOT be differenced. Upon completion, differenced shapes will be returned, and the selection object will be modified to contain differenced shapes and locked shapes.

Returns:

Returns a thenable promise containing the shapes that is differenced.

Examples:
var select = new Vecta.Selection([path1, path2]); //Create a new selection object with two paths

select.difference().then(function (shapes) {
    console.log('Number of shapes differenced = ' + shapes.length);
});

.fragment() Returns: Promise.<Vecta.Shape[]>

Perform fragment operation on shapes in the selection object.

Locked shapes will NOT be fragmented. Upon completion, fragmented shapes will be returned, and the selection object will be modified to contain fragmented shapes and locked shapes.

Returns:

Returns a thenable promise containing the shapes that is fragmented.

Examples:
var select = new Vecta.Selection([path1, path2]); //Create a new selection object with two paths

select.fragmented().then(function (shapes) {
    console.log('Number of shapes from fragment operation = ' + shapes.length);
});

.group() Returns: Vecta.Shape

Group shapes from the selection object into a single shape.

If a shape is a child shape of another group or is locked, it will not be grouped into the new shape.

Returns:

Returns the grouped shape if successful or null if not.

Examples:
var rect1 = new Vecta.activePage.drawRect(0, 0, 50, 50), //Draw a rect
    rect2 = new Vecta.activePage.drawRect(50, 50, 50, 50), //Draw another rect
    select = new Vecta.Selection([rect1, rect2]); //Create a new selection object with two shapes

select.group(); //Group the 2 shapes in the selection object

.intersect() Returns: Promise.<Vecta.Shape[]>

Perform intersect operation on shapes in the selection object

Locked shapes will NOT be intersected. Upon completion, intersected shapes will be returned, and the selection object will be modified to contain intersected shapes and locked shapes.

Returns:

Returns a thenable promise containing the shapes that is intersected.

Examples:
var select = new Vecta.Selection([path1, path2]); //Create a new selection object with two paths

select.intersect().then(function (shapes) {
    console.log('Number of shapes intersected = ' + shapes.length);
});

.join() Returns: Promise.<Vecta.Shape[]>

Join shapes in the selection object.

Join operations only applies to unclosed paths, where the begin and end points are located at the same coordinates, otherwise paths will not be joined.

Returns:

Returns a thenable promise containing the shapes that is joined.

Examples:
var select = new Vecta.Selection([path1, path2]); //Create a new selection object with two paths

select.join().then(function (shapes) {
    if (shapes.length === 1) { console.log('All shapes joined into a single shape!'); }
});

.length() Returns: number

Get the number of shapes in the selection object.

Returns:

The number of shapes in the selection object.

Examples:
var select = new Vecta.Selection(); //Create an empty selection

console.log(select.length); //0

.outline() Returns: Promise.<Vecta.Shape[]>

Outline text to path in the selection object.

Only shapes that is unlocked will be outlined. Upon completion, outlined shapes will be returned, and the selection object will be modified to contain outlined shapes and locked shapes.

Returns:

Returns a thenable promise containing the shapes that is outlined to path.

Examples:
var rect = Vecta.activePage.drawRect(0, 0, 50, 50).text('Testing'), //Create rectangle and set text
    select = new Vecta.Selection(rect); //Create a new selection object with rect

select.outline(); //Outline the text

.remove(shape_or_id) Returns: Vecta.Selection

Remove a single shape from the selection object.

NameTypeDescription
shape_or_idVecta.Shape|string

The shape object or id to remove.

.toPath() Returns: Promise.<Vecta.Shape[]>

Convert shapes to path in the selection object.

Locked shapes, paths (already converted) and images will NOT be converted.

Upon completion, converted shapes will be returned, and the selection object will be modified to contain converted shapes and locked shapes.

Returns:

Returns a thenable promise containing the shapes that is converted to path.

Examples:
var select = new Vecta.Selection([rect1, rect2]); //Create a new selection object with two shapes

select.toPath(); //Convert both rectangle to paths

.trim() Returns: Promise.<Vecta.Shape[]>

Trim shapes in the selection object.

Locked shapes will NOT be trimmed. Upon completion, trimmed shapes will be returned, and the selection object will be modified to contain trimmed shapes and locked shapes.

Returns:

Returns a thenable promise containing the shapes that is trimmed.

Examples:
var select = new Vecta.Selection([path1, path2]); //Create a new selection object with two paths

select.trim().then(function (shapes) {
    console.log('Number of shapes from trim operation = ' + shapes.length);
});

.ungroup() Returns: Vecta.Shape[]

Ungroup shapes from the current selection into multiple shapes.

Returns:

Returns the ungrouped shapes.

Examples:
var rect1 = new Vecta.activePage.drawRect(0, 0, 50, 50), //Draw a rect
    rect2 = new Vecta.activePage.drawRect(50, 50, 50, 50), //Draw another rect
    select = new Vecta.Selection([rect1, rect2]), //Create a new selection object with two shapes
    grouped = select.group(); //Group the 2 shapes in the selection object

grouped.ungroup(); //Ungroup the 2 shapes

.union() Returns: Promise.<Vecta.Shape[]>

Perform union operation on shapes in the selection object.

Locked shapes will NOT be unioned. Upon completion, unioned shapes will be returned, and the selection object will be modified to contain unioned shapes and locked shapes.

Returns:

Returns a thenable promise containing the shapes that is unioned.

Examples:
var select = new Vecta.Selection([path1, path2]); //Create a new selection object with two paths

select.union().then(function (shapes) {
    if (shapes.length === 1) { console.log('All shapes unioned into a single one'); }
});