Grouping Layers - Remove Parents for Each Layer
✓ Published0🌍 Public
KKevinGutowski
Last edited May 1, 2019
Created on Apr 27, 2019
This example demonstrates how to detach shape layers from their parent artboard, re-parent them into a new group, and automatically resize the group to fit its contents. The Sketch API creates four shapes—a square, triangle, hexagon, and oval—on an artboard, then calls `layer.remove()` on each to sever their parent relationships. The shapes are subsequently added to a new `Group` via the `layers` property, and `adjustToFit()` recalculates the group’s bounding frame. The code uses `sketch.ShapePath`, `sketch.Artboard`, and `sketch.Group` to manage the layer hierarchy programmatically.
AI-generated description