Returns a Vecta.Selection object that contains the currently selected shapes in the Vecta application.
When you select shapes using the Vecta user interface, the selected shapes will be contained in the Vecta.selection instance.
The difference between Vecta.selection and the Vecta.Selection class is that the Vecta application contains a single Vecta.selection instance, while the Vecta.Selection class are user creatable and contains shapes that are selected programmatically.
See also:
Methods
.add(shapes) Returns: Vecta.selection
Add shapes into the selection object.
Name | Type | Description |
---|---|---|
shapes | Vecta.Shape|Vecta.Shape[] | A single shape or an array of shapes |
Examples:
Vecta.selection.add(shapes).refresh(); //Add multiple shapes, and refresh
.box() Returns: object
Get the selection object bounding box.
Returns:
{x: number, y: number, width: number, height: number}
Examples:
var shape = Vecta.activePage.shape('xxx'); //Get the shape with id === xxx
shape.move(0, 0).size(100, 100); //Set left top and size to 0, 0, 100, 100
Vecta.selection.add([shape]); //Add shape to selection object
console.log(Vecta.selection.box()); //{x: 0, y: 0, width: 100, height: 100}
.clear() Returns: Vecta.selection
Clear or remove all shapes from current selection.
Examples:
Vecta.selection.clear(); //Remove all shapes from selection instance
.connPoint() Returns: Vecta.Connect
Get connection point from the selection object.
Returns:
Returns the selected connection point.
Examples:
Vecta.selection.connPoint(); //Returns the selected connection point.
.difference() Returns: Promise.<Vecta.Shape[]>
Difference shapes in the selection object.
Returns:
Returns a thenable promise containing the shapes that is differenced.
Examples:
Vecta.selection.difference().then(function (shapes) {
console.log('Number of shapes differenced = ' + shapes.length);
});
.flipHoriz() Returns: Vecta.selection
Flip shapes horizontally
Examples:
Vecta.selection.flipHoriz();
.flipVerti() Returns: Vecta.selection
Flip shapes vertically
Examples:
Vecta.selection.flipVerti();
.fragment() Returns: Promise.<Vecta.Shape[]>
Fragment shapes in the selection object.
Returns:
Returns a thenable promise containing the shapes that is fragmented.
Examples:
Vecta.selection.fragment().then(function (shapes) {
console.log(shapes.length + ' shapes fragmented!');
});
.group() Returns: Vecta.Shape
Group shapes from the selection object into a single shape.
If a shape is a child shape of another group, it will not be grouped into the new shape.
If a shape 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
var rect2 = new Vecta.activePage.drawRect(50, 50, 50, 50); //Draw another rect
Vecta.selection.add([rect1, rect2]).group(); //Add 2 shapes into selection object and group them
.intersect() Returns: Promise.<Vecta.Shape[]>
Intersect shapes in the selection object.
Returns:
Returns a thenable promise containing the shapes that is intersected.
Examples:
Vecta.selection.intersect().then(function (shapes) {
console.log('Number of shapes intersected = ' + shapes.length);
});
.join() Returns: Promise.<Vecta.Shape[]>
Join shapes in the selection object. 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:
Vecta.selection.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.
Examples:
if (Vecta.selection.length() > 1) {
Vecta.selection.group(); //group all shapes in selection object if number of shapes is more than 1
}
.outline() Returns: Promise.<Vecta.Shape[]>
Outline text in the selection object to paths.
Returns:
Returns a thenable promise containing the shapes that is converted.
Examples:
Vecta.selection.outline().then(function (shapes) {
console.log('Number of outlined text = ' + shapes.length);
});
.refresh() Returns: Vecta.selection
Refresh selection handles in UI.
Examples:
//add some shapes into selection and refresh handles
Vecta.selection.add(shapes).refresh();
.remove(shape_or_id) Returns: Vecta.selection
Remove a single shape from the selection object.
Name | Type | Description |
---|---|---|
shape_or_id | Vecta.Shape|string | The shape object or id to remove. |
.shapes() Returns: Vecta.Shape[]
Get all shapes from the selection object.
Returns:
Returns an array of shapes.
Examples:
Vecta.selection.shapes(); //Returns all shapes in the selection
Vecta.selection.shapes()[0]; //Return the first shape in the selection
.toPath() Returns: Promise.<Vecta.Shape[]>
Convert shapes in the selection object to paths.
Returns:
Returns a thenable promise containing the shapes that is converted.
Examples:
Vecta.selection.toPath().then(function (shapes) {
console.log('Number of shapes converted = ' + shapes.length);
});
.trim() Returns: Promise.<Vecta.Shape[]>
Trim shapes in the selection object.
Returns:
Returns a thenable promise containing the shapes that is trimmed.
Examples:
Vecta.selection.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
var rect2 = new Vecta.activePage.drawRect(50, 50, 50, 50); //Draw another rect
Vecta.selection.add([rect1, rect2]).ungroup(); //Ungroup the shape in selection object
.union() Returns: Promise.<Vecta.Shape[]>
Union shapes in the selection object.
Returns:
Returns a thenable promise containing the shapes that is unioned.
Examples:
Vecta.selection.union().then(function (shapes) {
if (shapes.length === 1) { console.log('All shapes unioned into a single one'); }
});