-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathSave Open Docs.jsx
236 lines (202 loc) · 6.44 KB
/
Save Open Docs.jsx
1
/** * @author Scott Lewis <scott@iconify.it> * @copyright 2017 Scott Lewis * @version 1.0.0 * @url http://github.com/iconifyit * * ABOUT: * * This script demonstrates how to implement a progress bar in your script. * * USAGE: * * 1. Place this script in Applications > Adobe Illustrator > Presets > en_US > Scripts * 2. Restart Adobe Illustrator to activate the script * 3. The script will be available under menu File > Scripts > Ai Sessions * * NO WARRANTIES: * * You are free to use, modify, and distribute this script as you see fit. * No credit is required but would be greatly appreciated. * * THIS SCRIPT IS OFFERED AS-IS WITHOUT ANY WARRANTY OR GUARANTEES OF ANY KIND. * YOU USE THIS SCRIPT COMPLETELY AT YOUR OWN RISK AND UNDER NO CIRCUMSTANCES WILL * THE DEVELOPER AND/OR DISTRIBUTOR OF THIS SCRIPT BE HELD LIABLE FOR DAMAGES OF * ANY KIND INCLUDING LOSS OF DATA OR DAMAGE TO HARDWARE OR SOFTWARE. IF YOU DO * NOT AGREE TO THESE TERMS, DO NOT USE THIS SCRIPT. *//** * Declare the target app. */#target illustrator/** * Include the libraries we need. */#includepath "/Users/scott/github/iconify/jsx-common/";#include "JSON.jsxinc";#include "Utils.jsxinc";#include "Logger.jsxinc";#include "Helpers.jsx";/** * Name that script. */#script "Save Open Docs";/** * Disable Illustrator's alerts. */// Utils.displayAlertsOff();/** * Run the script using the Module pattern. This pattern isn't required, * but it is a nice clean and organized way to write the code. It also avoids * cluttering the global scope. */var MyModule = (function(CONFIG) { /** * The local scope logger object. * @type {Logger} */ var logger = new Logger(CONFIG.APP_NAME, CONFIG.LOGFOLDER); function doSaveDocs() { for (i = 0; i < app.documents.length; i++) { app.activeDocument = app.documents[i]; app.activeDocument.save(); } } /** * Get the current timestamp. * @returns {number} * @private */ function now() { return (new Date()).getTime(); } function getPathItems(src) { var pathItems = []; var groupItems = []; var compoundPathItems = []; var pageItems = []; if (isDefined(src.pathItems)) { pathItems = pathItems.concat(src.pathItems); $.writeln("src.pathItems : " + src.pathItems.length); } if (isDefined(src.pageItems)) { for (var i = 0; i < src.pageItems.length; i++) { var thisItem = src.pageItems[i]; pathItems = pathItems.concat(getPathItems(thisItem)); $.writeln("src.pageItems : " + getPathItems(thisItem).length); } } if (isDefined(src.groupItems)) { for (var i = 0; i < src.groupItems.length; i++) { var thisItem = src.groupItems[i]; pathItems = pathItems.concat(getPathItems(thisItem)); $.writeln("src.groupItems : " + getPathItems(thisItem).length); } } if (isDefined(src.compoundPathItems)) { for (var i = 0; i < src.compoundPathItems.length; i++) { var thisItem = src.compoundPathItems[i]; pathItems = pathItems.concat(getPathItems(thisItem)); $.writeln("src.compoundPathItems : " + getPathItems(thisItem).length); } } return pathItems; } function getSource(object) { try { object.toSource(); } catch(e) { return e.message; } } function getSelectedPathItems() { var doc = app.activeDocument; var selected = [], pathItems = doc.pathItems; for (var i=0; i<pathItems.length; i++) { if (pathItems[i].selected) { selected.push(pathItems[i]); } } return selected; } /** * Deselect all page items. * @private */ function _deselectAll() { for (var i = 0; i<app.activeDocument.pageItems.length; i++) { app.activeDocument.pageItems[i].selected = false; } } function _selectByUUID(uuid) { $.writeln("UUID : " + uuid); // Utils.logger("Host._selectByUUID(uuid) : " + uuid); var doc = app.activeDocument; $.writeln('Path Items : ' + doc.pathItems.length); for (var i = 0; i<doc.pathItems.length; i++) { thisItem = doc.pathItems[i]; $.writeln('thisItem.note : ' + uuid); // Utils.logger("Host._selectByUUID(uuid) thisItem.note == uuid : " + thisItem.note + " == " + uuid); // if (strcmp(thisItem.note, uuid)) { if (thisItem.name == uuid) { thisItem.selected = true; $.writeln('SELECTED : ' + thisItem.selected); return doc.selection; } } return false; } function main() { // $.writeln("window.__adobe_cep__ : " + typeof(window.__adobe_cep__) ); if ( app.documents.length > 0 ) { // doSaveDocs(); var doc = app.activeDocument; // doc.pathItems[0].selected = true; _selectByUUID('d05fd8b7-7e82-4d3a-b350-cd0866dad6cc'); // $.writeln( getSource(selection) ); // alert( getPathItems(selection).length ); return; try { for (x in selection) { if (typeof(selection[x]) == 'function') continue; if (selection[x].typename == 'PathItem') { svgCoords = pathItemToSVG( selection[x] ); $.writeln( svgCoords ); // $.writeln( SVGToPathPointArray( svgCoords ) ); } } } catch(e) { $.writeln(e); } return void(0); } else { alert("There are no open documents"); } try { userInteractionLevel = originalInteractionLevel; } catch(ex) {/*Exit Gracefully*/} } /** * Returns the public module object/interface. */ return { /** * Runs the module code. */ run: function() { main(); } }})({ APP_NAME : "save-open-docs", LOGFOLDER : (new Folder($.getenv("HOME"))).absoluteURI + "/ai-logs/"});/** * Run the module. */MyModule.run();