Skip to content

Instantly share code, notes, and snippets.

@jodyheavener
Last active February 11, 2020 17:44
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jodyheavener/186bebf0855d680a47f2 to your computer and use it in GitHub Desktop.
Save jodyheavener/186bebf0855d680a47f2 to your computer and use it in GitHub Desktop.
Import a desired SVG in to a Sketch canvas
// Import Ale's fantastic Sketch Sandbox
// https://github.com/bomberstudios/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);
});
@adamthesax
Copy link

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