This is an old documentation. Go to the latest Customer's Canvas docs

getItemRectangles Method

Callable

  • getItemRectangles(ids: string [] ) : Promise < RotatedRectangleF [] >
  • Gets the bounding rectangles for design elements with regard to their rotation.

    In the following example, toRectangleF() returns the bounds without taking into account the item rotation, i.e. the vertically or horizontally oriented rectangle, whereas rotatedRect contains the rotation angle and bounds.

    example
    const ids = (await editor.getSelectedItems()).map(item => item.id);
    if (ids.length > 0) {
    
        var product = await editor.getProduct();
        var rectangles = await product.getItemRectangles(ids);
        var message = "";
        for (let i = 0; i < rectangles.length; i++) {
            const rotatedRect = rectangles[i];
            const rect = rotatedRect.toRectangleF();
            message += "Item with " + ids[i] +
                " has: width: " + rect.width.toFixed(2) +
                ", height: " + rect.height.toFixed(2) +
                ", location: (" + rect.left.toFixed(2) + ", " + rect.top.toFixed(2) + ")" +
                ", angle: " + rotatedRect.angle.toFixed(2) + "\n";
        }
    
        console.log(message);
    }
    

    Parameters

    • ids: string []

      An array of item identifiers.

    Returns Promise < RotatedRectangleF [] >

    An array of item bounds, in points.