transform(pItem, type, [value])

Transforms a given page item. The type of transformation is determinded with the second parameter. The third parameter is the transformation value, either a number or an array of x and y values. The transformation’s reference point (top left, bottom center etc.) can be set beforehand by using the referencePoint() function. If the third parameter is ommited, the function can be used to measure the value of the page item. There are 10 different transformation types:

  • "translate": Translates the page item by the given [x, y] values. Returns the coordinates of the page item’s anchor point as anray.
  • "rotate": Rotates the page item to the given degree value. Returns the page item’s rotation value in degrees.
  • "scale": Scales the page item to the given [x, y] scale factor values. Alternatively, a single scale factor value can be usto scale the page item uniformely. Returns the scale factor values of the page item’s current scale as an array.
  • "shear": Shears the page item to the given degree value. Returns the page item’s shear value in degrees.
  • "size": Sets the page item’s size to the given [x, y] dimensions. Returns the size of the page item as an array.
  • "width": Sets the page item’s width to the given value. Returns the width of the page item.
  • "height": Sets the page item’s height to the given value. Returns the height of the page item.
  • "position": Sets the position of the page item’s anchor point to the given [x, y] coordinates. Returns the coordinates of the page item’s anchor point as an array.
  • "x": Sets the x-position of the page item’s anchor point to the given value. Returns the x-coordinate of the page item’s anr point.
  • "y": Sets the y-position of the page item’s anchor point to the given value. Returns the y-coordinate of the page item’s anchor point.

Type: function

Parameter(s):

  • pItem {PageItem}:

    The page item to transform.

  • type {String}:

    The type of transformation.

  • value {} Optional:

    The value(s) of the transformation.

Returns:

  • {Number | Array}:

    The current value(s) of the specified transformation.

Example(s):

Rotating a rectangle to a 25 degrees angle

var r = rect(20, 40, 200, 100);
transform(r, "rotate", 25);

Measure the width of a rectangle

var r = rect(20, 40, random(100, 300), 100);
var w = transform(r, "width");
println(w); // prints the rectangle's random width between 100 and 300

Position a rectangle's lower right corner at a certain position

var r = rect(20, 40, random(100, 300), random(50, 150));
referencePoint(BOTTOM_RIGHT);
transform(r, "position", [40, 40]);