Split Rectangle into equal segments with padding
✓ Published0🌍 Public
KKevinGutowski
Last edited Feb 10, 2020
Created on Feb 8, 2020
This example demonstrates a Sketch plugin script that splits a selected rectangle into five equal segments with consistent padding between each segment. It shows how to programmatically resize the original shape and duplicate it to create evenly spaced copies. The code uses the Sketch JavaScript API, specifically `sketch.getSelectedDocument()`, `ShapePath`, and the `selection.duplicate()` method, along with frame properties like `frame.width` and `frame.x`. The calculation accounts for the fixed padding of 4 pixels when determining the new width of each segment and the offset for each duplicated copy.
AI-generated description