[sketchplugins-dev] Converting text to outlines?

Andrey Shakhmin andrey.shakhmin at gmail.com
Fri Nov 7 21:02:28 CST 2014


Oooopppss... forgot to say that the code sample in the previous letter
works only for selected text layers since it actually triggers action.

In order to convert any text layer to outlines use this (works only in
Sketch 3.2):

(function(){
    function convertToOutlines(layer) {
        if(!layer.isKindOfClass(MSTextLayer)) return;

        var parent=layer.parentGroup();
        var
shape=MSShapeGroup.shapeWithBezierPath(layer.bezierPathWithTransforms());
        shape.style = layer.style();

        var style=shape.style();
        if(!style.fill()) {
            var fill=style.fills().addNewStylePart();
            fill.color =
MSColor.colorWithNSColor(layer.style().textStyle().attributes().NSColor);
        }

        var isSelected=layer.isSelected();
        shape.name = layer.name();
        parent.removeLayer(layer);

        parent.addLayers([shape]);
        shape.setIsSelected(isSelected);

        return shape;
    }

    var layer=selection.firstObject();
    if(layer) {
        var vectorizedTextLayer=convertToOutlines(layer);
        print(vectorizedTextLayer);
    }

})();

--
Andrey Shakhmin

On Sat, Nov 8, 2014 at 9:31 AM, Andrey Shakhmin <andrey.shakhmin at gmail.com>
wrote:

> Joe,
>
> You can use `MSVectorizeTextAction` class to do that. Here is the complete
> example:
>
> var layer=selection.firstObject();
> if(layer && layer.isKindOfClass(MSTextLayer)) {
>     var
> action=doc.actionsController().actionWithName("MSVectorizeTextAction");
>     if(action.validate()) {
>         action.vectorizeLayer(layer);
>     }
> }
>
> --
> Andrey Shakhmin
>
> On Sat, Nov 8, 2014 at 6:58 AM, Joe Girolamo <joegirolamo at gmail.com>
> wrote:
>
>> Hi all,
>>
>> I'm wondering if there is a way to programmatically perform the "Convert
>> to Outlines" action on a text object in a Sketch plugin.  After a bit of
>> digging the most relevant method I could find was "outlineStrokePath:" but
>> I have no idea what it does or what to pass it...
>>
>> Any help is greatly appreciated!
>>
>> Joseph Girolamo
>>
>> _______________________________________________
>> dev mailing list
>> dev at sketchplugins.com
>> http://mail.sketchplugins.com/mailman/listinfo/dev_sketchplugins.com
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.sketchplugins.com/pipermail/dev_sketchplugins.com/attachments/20141108/cd0644b8/attachment.html>


More information about the dev mailing list