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 characters
| function hexToColor(hex,alpha) { | |
| var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex), | |
| r = parseInt(result[1],16) / 255, | |
| g = parseInt(result[2],16) / 255, | |
| b = parseInt(result[3],16) / 255, | |
| a = (typeof alpha !== 'undefined') ? alpha : 1; | |
| return NSColor.colorWithCalibratedRed_green_blue_alpha(r,g,b,a); | |
| } |
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 characters
| var value = nil, | |
| key = "kModelPropertiesKey", | |
| layer = context.selection[0], | |
| plugin = "com.animaapp.stc-sketch-plugin"; | |
| // Get the value | |
| context.command.valueForKey_onLayer_forPluginIdentifier(key,layer,plugin); | |
| // Set the value | |
| context.command.setValue_forKey_onLayer_forPluginIdentifier(value,key,layer,plugin); |
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 characters
| // [0] represents first override, replace with appropriate index if other override is desired | |
| symbolInstance.setValue_forOverridePoint("New text", symbolInstance.overridePoints()[0]); |
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 characters
| var textLayers = getAllLayersOfClass("MSTextLayer"), | |
| textLayerLoop = textLayers.objectEnumerator(), | |
| textLayer; | |
| while (textLayer = textLayerLoop.nextObject()) { | |
| log(textLayer.attributedStringValue()); | |
| } | |
| function getAllLayersOfClass(className) { | |
| var array = NSArray.array(), |
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 characters
| var symbol = context.document.documentData().symbolWithID_('aa-bb-cc-dd'); |
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 characters
| var layer = context.selection[0], | |
| attributes = layer.attributedString().treeAsDictionary().value.attributes; | |
| attributes.forEach(function(attr) { | |
| log("Text:" + attr.text); | |
| log("Color:" + attr.MSAttributedStringColorAttribute.value); | |
| }); |
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 characters
| function truncateString(string,length) { | |
| return (string.length <= length) ? string : "…" + string.substr(string.length-length); | |
| } |
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 characters
| function createViewWithImage(context,file,frame) { | |
| var imageView = NSView.alloc().initWithFrame(frame), | |
| imagePath = context.plugin.urlForResourceNamed(file).path(), | |
| image = NSImage.alloc().initByReferencingFile(imagePath); | |
| imageView.setWantsLayer(1); | |
| imageView.layer().setBackgroundColor(CGColorCreateGenericRGB(255,255,255,1)); | |
| imageView.layer().contents = image; | |
| return imageView; |
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 characters
| for (var obj in arr) { | |
| var i = Object.keys(arr).indexOf(obj); | |
| } |
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 characters
| var libraries = AppController.sharedInstance().librariesController().libraries(), | |
| libraryLoop = libraries.objectEnumerator(), | |
| library; | |
| while (library = libraryLoop.nextObject()) { | |
| // Do something | |
| } |