Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Import a desired SVG in to a Sketch canvas
// Import Ale's fantastic Sketch Sandbox
#import 'sketch-sandbox.js'
// Are we on a page or an artboard?
var page = doc.currentPage();
var canvas = page.currentArtboard() ? page.currentArtboard() : page;
// Define the location of the file you want to import, using file:// protocol
var fileURL = NSURL.URLWithString("file:///Users/johndoe/Downloads/my_cat.svg");
// Set up the SVG Importer
var svgImporter = MSSVGImporter.svgImporter();
// The SVG needs to be imported in to an MSLayerGroup, so let's create one
var containingGroup = canvas.addLayerOfType("group")
containingGroup.setName("Imported SVG")
// Run the sandbox authorization, and if it succeeds import the desired SVG
new AppSandbox().authorize("/Users/" + NSUserName(), function(){
MSImportInsert.importFromURL_inGroup_importer_completion(fileURL, containingGroup, svgImporter, nil);

monkpod commented Jun 3, 2015

Do you know where I can find documentation for MSImportInsert?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment