Size

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

An instance of the **Size** class is created by preceding the class name with the **new** command, 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, heightValue)**(Size) • Returns a new Size with the specified dimensions.

Creating a Size Object | ||

01 | newSize = new Size(150.0,75.0) |

Instance Properties

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 Graphic | ||

01 | var canvas = document.windows[0].selection.canvas | |

02 | canvas.graphics[0].geometry.size = new Size(200.0,200.0) | |

03 | // will not change the dimensions of the graphic | |

04 | // get the graphic’s geometry | |

05 | geo = canvas.graphics[0].geometry | |

06 | // change the size of the geometry | |

07 | geo.size = new Size(200.0,200.0) | |

08 | // apply the changed geometry | |

09 | canvas.graphics[0].geometry = geo | |

10 | // 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:

sel = document.windows[0].selection
cnvs = sel.canvas
if(cnvs.graphics.length > 1){
if(sel.graphics.length == 1){
targetSize = sel.graphics[0].geometry.size
for(i = 0; i < cnvs.graphics.length; i++){
geo = cnvs.graphics[i].geometry
geo.size = targetSize
cnvs.graphics[i].geometry = geo
}
}
}

omnigraffle:///omnijs-run?script=sel%20%3D%20document%2Ewindows%5B0%5D%2Eselection%0Acnvs%20%3D%20sel%2Ecanvas%0Aif%28cnvs%2Egraphics%2Elength%20%3E%201%29%7B%0A%09if%28sel%2Egraphics%2Elength%20%3D%3D%201%29%7B%0A%09%09targetSize%20%3D%20sel%2Egraphics%5B0%5D%2Egeometry%2Esize%0A%09%09for%28i%20%3D%200%3B%20i%20%3C%20cnvs%2Egraphics%2Elength%3B%20i%2B%2B%29%7B%0A%09%09%09geo%20%3D%20cnvs%2Egraphics%5Bi%5D%2Egeometry%0A%09%09%09geo%2Esize%20%3D%20targetSize%0A%09%09%09cnvs%2Egraphics%5Bi%5D%2Egeometry%20%3D%20geo%0A%09%09%7D%0A%20%20%20%20%7D%0A%7D

var canvas = document.windows[0].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)
document.windows[0].selection.view.select([g4])

omnigraffle:///omnijs-run?script=var%20canvas%20%3D%20document%2Ewindows%5B0%5D%2Eselection%2Ecanvas%0Avar%20g1%20%3D%20canvas%2EnewShape%28%29%0Avar%20g2%20%3D%20canvas%2EnewShape%28%29%0Avar%20g3%20%3D%20canvas%2EnewShape%28%29%0Avar%20g4%20%3D%20canvas%2EnewShape%28%29%0Ag1%2Egeometry%20%3D%20new%20Rect%28180%2E00%2C%20162%2E00%2C%20153%2E00%2C%20153%2E00%29%0Ag1%2EshadowColor%20%3D%20null%0Ag1%2EfillColor%20%3D%20Color%2ERGB%281%2E0%2C%200%2E0%2C%200%2E0%29%0Ag2%2EtextUnitRect%20%3D%20new%20Rect%280%2E10%2C%200%2E15%2C%200%2E80%2C%200%2E70%29%0Ag2%2Eshape%20%3D%20%22Circle%22%0Ag2%2Egeometry%20%3D%20new%20Rect%28261%2E00%2C%2090%2E00%2C%20135%2E00%2C%20135%2E00%29%0Ag2%2EshadowColor%20%3D%20null%0Ag2%2EfillColor%20%3D%20Color%2ERGB%280%2E0%2C%201%2E0%2C%200%2E0%29%0Ag3%2EtextUnitRect%20%3D%20new%20Rect%280%2E33%2C%200%2E33%2C%200%2E34%2C%200%2E34%29%0Ag3%2Eshape%20%3D%20%22AdjustableStar%22%0Ag3%2EflippedVertically%20%3D%20true%0Ag3%2Egeometry%20%3D%20new%20Rect%28306%2E00%2C%20153%2E00%2C%20198%2E00%2C%20198%2E00%29%0Ag3%2EshadowColor%20%3D%20null%0Ag3%2EfillColor%20%3D%20Color%2ERGB%281%2E0%2C%201%2E0%2C%200%2E0%29%0Ag3%2EflippedHorizontally%20%3D%20true%0Ag4%2EtextUnitRect%20%3D%20new%20Rect%280%2E14%2C%200%2E12%2C%200%2E75%2C%200%2E75%29%0Ag4%2Eshape%20%3D%20%22Diamond%22%0Ag4%2Egeometry%20%3D%20new%20Rect%28189%2E00%2C%20252%2E00%2C%2090%2E00%2C%2090%2E00%29%0Ag4%2EshadowColor%20%3D%20null%0Ag4%2EfillColor%20%3D%20Color%2ERGB%280%2E0%2C%201%2E0%2C%201%2E0%29%0Adocument%2Ewindows%5B0%5D%2Eselection%2Eview%2Eselect%28%5Bg4%5D%29

Adjust Size of all Canvas Graphics to Match Selected Graphic | ||

01 | sel = document.windows[0].selection | |

02 | cnvs = sel.canvas | |

03 | if(cnvs.graphics.length > 1){ | |

04 | if(sel.graphics.length == 1){ | |

05 | targetSize = sel.graphics[0].geometry.size | |

06 | for(i = 0; i < cnvs.graphics.length; i++){ | |

07 | geo = cnvs.graphics[i].geometry | |

08 | geo.size = targetSize | |

09 | cnvs.graphics[i].geometry = geo | |

10 | } | |

11 | } | |

12 | } |

UNDER CONSTRUCTION

This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.