Last active
February 11, 2020 17:44
-
-
Save jodyheavener/186bebf0855d680a47f2 to your computer and use it in GitHub Desktop.
Import a desired SVG in to a Sketch canvas
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
// 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); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you know where I can find documentation for
MSImportInsert
?