A Size is a class describing the dimensions of a graphic. It has two elements, the width (in points) and the height (in points) of the object. A Size is also the second component of a Rect, which describes both the location (Point) and dimensions (Size) of a graphic.
Creating a Size Instance
An instance of the Size class is created by preceding the class name with the new item constructor, and following the class name with the width (in points), and height (in points) of the object, enclosed in a pair of parens (). The result is a new instance of the Size class:
new Size(widthValue: Number, heightValue: Number) → (Size) • Returns a new Size instance using the specified dimensions.
New Size Instancevar newSize = new Size(150.0, 75.0)
An instance of the Size class has two properties: the width and height of the graphic.
height (Number) • The vertical measure of the size object.
width (Number) • The horizontal measure of the size object.
Using Size in Scripts
The values of the properties of a Size can be read by scripts. The values can also be changed, but to effect a change in the dimensions of a graphic, the geometry (Rect) of which the Size is a component, must be altered and then applied to a graphic.
Changing the Size of a Graphicvar cnvs = document.windows.selection.canvas// The following will not change the dimensions of the graphiccnvs.graphics.geometry.size = new Size(200.0, 200.0)// To change the size of the graphic, get the graphic’s geometryvar geo = cnvs.graphics.geometry// change the size of the geometrygeo.size = new Size(200.0, 200.0)// apply the changed geometry to the graphiccnvs.graphics.geometry = geo// dimensions of the graphic change!
And here’s an example where all the graphics in a canvas are resized to match the size of the one that is selected:
var canvas = document.windows.selection.canvas
var g1 = canvas.newShape()
var g2 = canvas.newShape()
var g3 = canvas.newShape()
var g4 = canvas.newShape()
g1.geometry = new Rect(180.00, 162.00, 153.00, 153.00)
g1.shadowColor = null
g1.fillColor = Color.RGB(1.0, 0.0, 0.0)
g2.textUnitRect = new Rect(0.10, 0.15, 0.80, 0.70)
g2.shape = "Circle"
g2.geometry = new Rect(261.00, 90.00, 135.00, 135.00)
g2.shadowColor = null
g2.fillColor = Color.RGB(0.0, 1.0, 0.0)
g3.textUnitRect = new Rect(0.33, 0.33, 0.34, 0.34)
g3.shape = "AdjustableStar"
g3.flippedVertically = true
g3.geometry = new Rect(306.00, 153.00, 198.00, 198.00)
g3.shadowColor = null
g3.fillColor = Color.RGB(1.0, 1.0, 0.0)
g3.flippedHorizontally = true
g4.textUnitRect = new Rect(0.14, 0.12, 0.75, 0.75)
g4.shape = "Diamond"
g4.geometry = new Rect(189.00, 252.00, 90.00, 90.00)
g4.shadowColor = null
g4.fillColor = Color.RGB(0.0, 1.0, 1.0)