Last active
January 8, 2016 05:09
-
-
Save blvz/aa000d02ff2109ba4155 to your computer and use it in GitHub Desktop.
Creates a primitive rectangle for the current selection. Useful when adding background for text boxes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// by @blvz | |
var padding = 10 | |
, radius = 10; | |
(function(doc) { | |
var bounds, rect, newRect, fill, stroke | |
, tml = doc.getTimeline() | |
, sel = doc.selection.concat() | |
, rs = sel.filter(function(e) { return e.elementType == 'shape' | |
&& e.isRectangleObject }) | |
sel = sel.filter(function(e) { return e !== rect }) | |
if (!sel.length) return | |
rect = rs[0] | |
if (rect) rect.selected = false | |
bounds = doc.getSelectionRect() | |
bounds.left -= padding | |
bounds.top -= padding | |
bounds.right += padding | |
bounds.bottom += padding | |
doc.selectNone() | |
if (rect) rect.selected = true, fill = doc.getCustomFill(), stroke = doc.getCustomStroke() | |
doc.addNewPrimitiveRectangle(bounds, 0) | |
doc.selectNone() | |
newRect = tml.layers[tml.currentLayer].frames[tml.currentFrame].elements.concat().pop() | |
newRect.selected = true | |
doc.setRectangleObjectProperty('lockFlag', true) | |
doc.setRectangleObjectProperty('topLeftRadius', radius) | |
if (rect) doc.setCustomFill(fill), doc.setCustomStroke(stroke) | |
doc.selectNone() | |
if (rect) rect.selected = true, doc.deleteSelection() | |
sel.forEach(function(e) { e.selected = true }) | |
doc.clipCut() | |
doc.clipPaste(true) | |
newRect.selected = true | |
})(fl.getDocumentDOM()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment