Groups

A Group is a set of graphics represented as a single graphic. Groups can also contain other groups. They are a useful way of enabling manual positioning and editing of a set of graphics.

cnvs = document.windows[0].selection.canvas groups = new Array() cnvs.graphics.forEach(function(graphic){ if(graphic instanceof Group){groups.push(graphic)} })
var groups = new Array() canvases.forEach(function(cnvs){ cnvs.graphics.forEach(function(graphic){ if(graphic instanceof Group){groups.push(graphic)} }) })

Creating a Group

A new instance of the Group class is created by passing an array of graphic references, to the Group allocation method: new Group()

var canvas = document.windows[0].selection.canvas var g1 = canvas.newShape() var g2 = canvas.newShape() var g3 = canvas.newShape() var g4 = canvas.newShape() var g5 = canvas.newShape() g1.textUnitRect = new Rect(0.33, 0.33, 0.34, 0.34) g1.shape = "AdjustableStar" g1.geometry = new Rect(83.00, 81.00, 104.50, 104.50) g1.shadowColor = null g1.fillColor = Color.RGB(0.25, 0.25, 1.0) g2.textUnitRect = new Rect(0.10, 0.15, 0.80, 0.70) g2.shape = "Circle" g2.geometry = new Rect(187.50, 129.00, 111.00, 111.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.geometry = new Rect(298.50, 81.00, 104.50, 104.50) g3.shadowColor = null g3.fillColor = Color.RGB(1.0, 1.0, 0.0) g4.textUnitRect = new Rect(0.33, 0.33, 0.34, 0.34) g4.shape = "AdjustableStar" g4.geometry = new Rect(83.00, 204.50, 104.50, 104.50) g4.shadowColor = null g4.fillColor = Color.RGB(1.0, 0.5, 0.5) g5.textUnitRect = new Rect(0.33, 0.33, 0.34, 0.34) g5.shape = "AdjustableStar" g5.geometry = new Rect(298.50, 204.50, 104.50, 104.50) g5.shadowColor = null g5.fillColor = Color.RGB(0.0, 1.0, 1.0) group = new Group([g1,g2,g3,g4,g5]) document.windows[0].selection.view.select([group])
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%0Avar%20g5%20%3D%20canvas%2EnewShape%28%29%0Ag1%2EtextUnitRect%20%3D%20new%20Rect%280%2E33%2C%200%2E33%2C%200%2E34%2C%200%2E34%29%0Ag1%2Eshape%20%3D%20%22AdjustableStar%22%0Ag1%2Egeometry%20%3D%20new%20Rect%2883%2E00%2C%2081%2E00%2C%20104%2E50%2C%20104%2E50%29%0Ag1%2EshadowColor%20%3D%20null%0Ag1%2EfillColor%20%3D%20Color%2ERGB%280%2E25%2C%200%2E25%2C%201%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%28187%2E50%2C%20129%2E00%2C%20111%2E00%2C%20111%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%2Egeometry%20%3D%20new%20Rect%28298%2E50%2C%2081%2E00%2C%20104%2E50%2C%20104%2E50%29%0Ag3%2EshadowColor%20%3D%20null%0Ag3%2EfillColor%20%3D%20Color%2ERGB%281%2E0%2C%201%2E0%2C%200%2E0%29%0Ag4%2EtextUnitRect%20%3D%20new%20Rect%280%2E33%2C%200%2E33%2C%200%2E34%2C%200%2E34%29%0Ag4%2Eshape%20%3D%20%22AdjustableStar%22%0Ag4%2Egeometry%20%3D%20new%20Rect%2883%2E00%2C%20204%2E50%2C%20104%2E50%2C%20104%2E50%29%0Ag4%2EshadowColor%20%3D%20null%0Ag4%2EfillColor%20%3D%20Color%2ERGB%281%2E0%2C%200%2E5%2C%200%2E5%29%0Ag5%2EtextUnitRect%20%3D%20new%20Rect%280%2E33%2C%200%2E33%2C%200%2E34%2C%200%2E34%29%0Ag5%2Eshape%20%3D%20%22AdjustableStar%22%0Ag5%2Egeometry%20%3D%20new%20Rect%28298%2E50%2C%20204%2E50%2C%20104%2E50%2C%20104%2E50%29%0Ag5%2EshadowColor%20%3D%20null%0Ag5%2EfillColor%20%3D%20Color%2ERGB%280%2E0%2C%201%2E0%2C%201%2E0%29%0Agroup%20%3D%20new%20Group%28%5Bg1%2Cg2%2Cg3%2Cg4%2Cg5%5D%29%0Adocument%2Ewindows%5B0%5D%2Eselection%2Eview%2Eselect%28%5Bgroup%5D%29
group-00

Group Properties

Even though the properties of the individual elements of group can still be edited, a group as an entity has its own properties as well.

An array of references to a group’s elements can be ascertained by using the graphics property of the group. This array can then be used to manipulate the individual group elements without changing their status as belonging to the host group. Here’s a script example demonstrating how to change the value of each element of a group:

if (document.windows[0].selection.graphics.length != 1){ title = "SELECTION ERROR" message = "Please select a single group." new Alert(title, message).show(function(result){}) } else { obj = document.windows[0].selection.graphics[0] if(obj instanceof Group){ obj.graphics.forEach(function(item){ item.strokeColor = Color.red item.strokeThickness = 4 item.strokeType = StrokeType.Single }) } else { title = "SELECTION ERROR" message = "The selected object is not a group." new Alert(title, message).show(function(result){}) } }
omnigraffle:///omnijs-run?script=if%20%28document%2Ewindows%5B0%5D%2Eselection%2Egraphics%2Elength%20%21%3D%201%29%7B%0A%09title%20%3D%20%22SELECTION%20ERROR%22%0A%09message%20%3D%20%22Please%20select%20a%20single%20group%2E%22%0A%09new%20Alert%28title%2C%20message%29%2Eshow%28function%28result%29%7B%7D%29%0A%7D%20else%20%7B%0A%09obj%20%3D%20document%2Ewindows%5B0%5D%2Eselection%2Egraphics%5B0%5D%0A%09if%28obj%20instanceof%20Group%29%7B%0A%09%09obj%2Egraphics%2EforEach%28function%28item%29%7B%0A%09%09%09item%2EstrokeColor%20%3D%20Color%2Ered%0A%09%09%09item%2EstrokeThickness%20%3D%204%0A%09%09%09item%2EstrokeType%20%3D%20StrokeType%2ESingle%0A%09%09%7D%29%0A%09%7D%20else%20%7B%0A%09%09title%20%3D%20%22SELECTION%20ERROR%22%0A%09%09message%20%3D%20%22The%20selected%20object%20is%20not%20a%20group%2E%22%0A%09%09new%20Alert%28title%2C%20message%29%2Eshow%28function%28result%29%7B%7D%29%0A%09%7D%0A%7D
group-02

Instance Functions

The Group class offers a single instance function, which can be applied to a group in order to dissolve it back into its individual elements.

if (document.windows[0].selection.graphics.length != 1){ title = "SELECTION ERROR" message = "Please select a single group." new Alert(title, message).show(function(result){}) } else { obj = document.windows[0].selection.graphics[0] if(obj instanceof Group){ objects = obj.ungroup() document.windows[0].selection.view.select(objects) } else { title = "SELECTION ERROR" message = "The selected object is not a group." new Alert(title, message).show(function(result){}) } }
omnigraffle:///omnijs-run?script=if%20%28document%2Ewindows%5B0%5D%2Eselection%2Egraphics%2Elength%20%21%3D%201%29%7B%0A%09title%20%3D%20%22SELECTION%20ERROR%22%0A%09message%20%3D%20%22Please%20select%20a%20single%20group%2E%22%0A%09new%20Alert%28title%2C%20message%29%2Eshow%28function%28result%29%7B%7D%29%0A%7D%20else%20%7B%0A%09obj%20%3D%20document%2Ewindows%5B0%5D%2Eselection%2Egraphics%5B0%5D%0A%09if%28obj%20instanceof%20Group%29%7B%0A%09%09objects%20%3D%20obj%2Eungroup%28%29%0A%09%09document%2Ewindows%5B0%5D%2Eselection%2Eview%2Eselect%28objects%29%0A%20%20%20%20%7D%20else%20%7B%0A%09%09title%20%3D%20%22SELECTION%20ERROR%22%0A%09%09message%20%3D%20%22The%20selected%20object%20is%20not%20a%20group%2E%22%0A%09%09new%20Alert%28title%2C%20message%29%2Eshow%28function%28result%29%7B%7D%29%0A%20%20%20%20%7D%0A%7D
group-01
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.

DISCLAIMER