Last active
April 30, 2024 10:02
Revisions
-
abynim revised this gist
Aug 7, 2015 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -26,6 +26,9 @@ if( openDialog.runModal() == NSOKButton ) { duplicateLayerToCopy.removeFromParent() var currentDoc = context.document currentDoc.currentPage().currentArtboard().addLayers([duplicateLayerToCopy]) if(duplicateLayerToCopy.isSymbol()) { currentDoc.documentData().layerSymbols().addSymbolWithName_firstInstance(duplicateLayerToCopy.name(), duplicateLayerToCopy) } } } sourceDoc.close() -
abynim revised this gist
Aug 5, 2015 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,7 @@ var sourceLayerName = "gray_rectangle" // Ask user to select a Sketch file: var openDialog = NSOpenPanel.openPanel() openDialog.setCanChooseFiles(true) openDialog.setAllowedFileTypes(["sketch"]) openDialog.setCanChooseDirectories(false) openDialog.setAllowsMultipleSelection(false) openDialog.setCanCreateDirectories(false) -
abynim renamed this gist
Aug 5, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
abynim created this gist
Aug 5, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ // Name of layer to copy var sourceLayerName = "gray_rectangle" // Ask user to select a Sketch file: var openDialog = NSOpenPanel.openPanel() openDialog.setCanChooseFiles(true) openDialog.setCanChooseDirectories(false) openDialog.setAllowsMultipleSelection(false) openDialog.setCanCreateDirectories(false) openDialog.setTitle("Select the source Sketch document") if( openDialog.runModal() == NSOKButton ) { var sourceDoc = MSDocument.new() if(sourceDoc.readFromURL_ofType_error(openDialog.URL(), "com.bohemiancoding.sketch.drawing", nil)) { var allChildren = sourceDoc.pages().valueForKeyPath("@distinctUnionOfArrays.children") // Modify the predicate to change search parameters. Here it's by layer name var predicate = NSPredicate.predicateWithFormat("name == %@", sourceLayerName); var layerToCopy = allChildren.filteredArrayUsingPredicate(predicate).firstObject() if (layerToCopy) { var duplicateLayerToCopy = layerToCopy.duplicate() duplicateLayerToCopy.removeFromParent() var currentDoc = context.document currentDoc.currentPage().currentArtboard().addLayers([duplicateLayerToCopy]) } } sourceDoc.close() sourceDoc = nil }