4.5 Groups

Grouping is a way to make a single object out of a number of independent objects. It is an easily reversible action; objects combined into a group can be ungrouped and made independent again. Moreover, many of the tools in Inkscape completely disregard grouping and allow you to work directly with individual objects regardless of whether they are grouped or not. The Selector tool by default selects the group as a whole, but even in it, there are methods to select an object inside the group without ungrouping it (5.10 Selecting in Groups).

To group some objects, just select them and choose ObjectGroup (). Groups can be further grouped just like any other objects. You can even group a single object; for example, select a rectangle and press . Now you have a group with a single rectangle inside (such groups may be useful in a number of situations, such as blurring a clipped object; see 18.4 Clipping and Masking).

When a single group is selected, the status bar indicates how many member objects are within this group, for example: Group of 3 objects in layer Background.

To ungroup a group, select it and choose ObjectUngroup (); the group no longer exists, but all its former members, now released, remain where they were on the canvas (both the coordinates and the z-order of the objects are preserved).

You can select any number of groups and ungroup them all at once. Moreover, you can select any number of different objects, only some of which are groups, and press ; groups will be ungrouped, but all nongroup objects will remain intact.

Note

The Ungroup command removes only the topmost level of grouping. For example, if you have a group containing two other groups, pressing will release the two groups—they will stay selected but not ungrouped. You will need to press again to ungroup them. To ungroup all groups in a complex drawing, just select all objects and keep pressing until the status bar says, No groups to ungroup in the selection.

XML

In XML, a group is the g element (see A.5 Layers and Groups), which is a parent of its member objects. This means, among other things, that objects with unset style properties (8.1.1 Paint) will inherit these properties from their parent group or from an ancestor further up the tree.

Why group objects? There may be different reasons to use grouping.

An important thing to remember is that a group, as an object in its own right, has its own place in the z-order stack of your document, and all the members of the group share its z-order position.

This means that if object A is on top of B and B is on top of C, you cannot group A and C without changing the z-order. If you attempt to do that, C will jump up under A, and you will have a group containing A and C lying on top of the object B.

Ungrouping a group in that case does not restore the original z-order. If you ungroup the “A and C” group, you will get three independent objects, but they will be now in the order A, C, B (top to bottom). (Of course, if you simply Undo () right after grouping, both grouping and the z-order change will be reverted.)

For the same reason, you cannot group objects from different layers. Both layers and groups are branches of the XML tree of the document, and you cannot have a branch (group) growing from more than one parent branch (layer). If you try to group objects selected in different layers or within different groups, Inkscape will complain (with a message in the status bar) and do nothing.