├── gifs ├── Color-map.gif ├── Nobr-auto.gif ├── Save-pdf.gif ├── Scale-all.gif ├── Chart-Fix-Y.gif ├── Format-Num.gif ├── Quick-save.gif ├── Swap-Objects.gif ├── Ресурс 1@2x.png ├── Replace-Objects.gif ├── Replace-Objects.jpg ├── download-button.png ├── Chart-GroupByLines.gif ├── Replace-Objects-en.jpg └── Batch-Correct-Infgrf.gif ├── Artbord-rectangles.js ├── Nobr-auto.jsx ├── SwapObjects-TopLeft.js ├── Chart-GroupByLines.jsx ├── Chart-Fix-Y.jsx ├── Chart-GroupByLines-AndFixVert.jsx ├── SwapObjects-Center.js ├── SwapObjects-byHeight.js ├── SameScale.jsx ├── README.md ├── Color_map_range.js ├── FormatNum.jsx ├── Scale-all.jsx ├── Color_map_01.js ├── Batch-Correct-infgrf.jsx └── Replace-Objects-1a.jsx /gifs/Color-map.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daani-rika/Illustrator-scripts/HEAD/gifs/Color-map.gif -------------------------------------------------------------------------------- /gifs/Nobr-auto.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daani-rika/Illustrator-scripts/HEAD/gifs/Nobr-auto.gif -------------------------------------------------------------------------------- /gifs/Save-pdf.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daani-rika/Illustrator-scripts/HEAD/gifs/Save-pdf.gif -------------------------------------------------------------------------------- /gifs/Scale-all.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daani-rika/Illustrator-scripts/HEAD/gifs/Scale-all.gif -------------------------------------------------------------------------------- /gifs/Chart-Fix-Y.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daani-rika/Illustrator-scripts/HEAD/gifs/Chart-Fix-Y.gif -------------------------------------------------------------------------------- /gifs/Format-Num.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daani-rika/Illustrator-scripts/HEAD/gifs/Format-Num.gif -------------------------------------------------------------------------------- /gifs/Quick-save.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daani-rika/Illustrator-scripts/HEAD/gifs/Quick-save.gif -------------------------------------------------------------------------------- /gifs/Swap-Objects.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daani-rika/Illustrator-scripts/HEAD/gifs/Swap-Objects.gif -------------------------------------------------------------------------------- /gifs/Ресурс 1@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daani-rika/Illustrator-scripts/HEAD/gifs/Ресурс 1@2x.png -------------------------------------------------------------------------------- /gifs/Replace-Objects.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daani-rika/Illustrator-scripts/HEAD/gifs/Replace-Objects.gif -------------------------------------------------------------------------------- /gifs/Replace-Objects.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daani-rika/Illustrator-scripts/HEAD/gifs/Replace-Objects.jpg -------------------------------------------------------------------------------- /gifs/download-button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daani-rika/Illustrator-scripts/HEAD/gifs/download-button.png -------------------------------------------------------------------------------- /gifs/Chart-GroupByLines.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daani-rika/Illustrator-scripts/HEAD/gifs/Chart-GroupByLines.gif -------------------------------------------------------------------------------- /gifs/Replace-Objects-en.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daani-rika/Illustrator-scripts/HEAD/gifs/Replace-Objects-en.jpg -------------------------------------------------------------------------------- /gifs/Batch-Correct-Infgrf.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daani-rika/Illustrator-scripts/HEAD/gifs/Batch-Correct-Infgrf.gif -------------------------------------------------------------------------------- /Artbord-rectangles.js: -------------------------------------------------------------------------------- 1 | // A simple script to make a white background on every artboard. 2 | 3 | #target illustrator 4 | 5 | var doc = app.activeDocument; 6 | var artboard = doc.artboards; 7 | 8 | for(i=0; i 0) { 8 | if(docRef.selection.length == 2) { 9 | mySelection = docRef.selection; 10 | if(mySelection instanceof Array) { 11 | //create bounding objects 12 | var A_Bounds = mySelection[0].geometricBounds; 13 | var B_Bounds = mySelection[1].geometricBounds; 14 | 15 | //define parameters objects 16 | // object A 17 | var A_left = A_Bounds[0]; 18 | var A_top = A_Bounds[1]; 19 | 20 | // object B 21 | var B_left = B_Bounds[0]; 22 | var B_top = B_Bounds[1]; 23 | 24 | //move A (selection[0]) 25 | 26 | mySelection[0].position = [B_left, B_top]; 27 | 28 | //move B (selection[1]) 29 | 30 | mySelection[1].position = [A_left, A_top]; 31 | 32 | } 33 | } else { 34 | alert(mySelection + " is not an array!\n" + selObjs); 35 | } 36 | } else { 37 | alert("Selection is not 2 objects!\n" + selObjs); 38 | } 39 | } catch (e) { 40 | alert("problem:\n" + e); 41 | } 42 | -------------------------------------------------------------------------------- /Chart-GroupByLines.jsx: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Version: 2.0 4 | Made by daani-rika: https://github.com/daani-rika/Illustrator-scripts 5 | 6 | */ 7 | 8 | 9 | #target Illustrator 10 | 11 | group (); 12 | 13 | function group () 14 | { 15 | var thisDoc = app.activeDocument; 16 | var selObj = thisDoc.selection; 17 | 18 | sortVert(selObj); 19 | 20 | var Base; 21 | var top=0; 22 | var bottom=0; 23 | var iart; 24 | 25 | for (i = 0 ; ibottom) 51 | return "true"; 52 | else 53 | return "false"; 54 | } 55 | 56 | 57 | 58 | // -------------------------------------------------- 59 | // top -> down || left -> right 60 | function sortVert(tfs) { 61 | tfs.sort(function(a, b) { 62 | return a.top == b.top ? 63 | a.left - b.left : 64 | b.top - a.top 65 | }); 66 | } -------------------------------------------------------------------------------- /Chart-Fix-Y.jsx: -------------------------------------------------------------------------------- 1 | /* 2 | Version: 2.0 3 | Made by daani-rika: https://github.com/daani-rika/Illustrator-scripts 4 | */ 5 | 6 | #target Illustrator 7 | 8 | group (); 9 | 10 | function group () 11 | { 12 | var thisDoc = app.activeDocument; 13 | var selObj = thisDoc.selection; 14 | sortVert(selObj); 15 | 16 | var height = selObj[0].geometricBounds[1]-selObj[0].geometricBounds[3]; 17 | 18 | var Base; 19 | var top; 20 | var bottom ; 21 | var iHeight ; 22 | var shift=0; 23 | var iart; 24 | 25 | for (i = 0 ; ibottom) 59 | return "true"; 60 | else 61 | return "false"; 62 | } 63 | 64 | 65 | // top -> down || left -> right 66 | function sortVert(tfs) { 67 | tfs.sort(function(a, b) { 68 | return a.top == b.top ? 69 | a.left - b.left : 70 | b.top - a.top 71 | }); 72 | } -------------------------------------------------------------------------------- /Chart-GroupByLines-AndFixVert.jsx: -------------------------------------------------------------------------------- 1 | #target Illustrator 2 | 3 | group (); 4 | 5 | function group () 6 | { 7 | var thisDoc = app.activeDocument; 8 | var selObj = thisDoc.selection; 9 | sortVert(selObj); 10 | 11 | var height = selObj[0].geometricBounds[1]-selObj[0].geometricBounds[3]; 12 | 13 | var Base; 14 | var top; 15 | var bottom ; 16 | var iHeight ; 17 | var shift=0; 18 | var iart; 19 | 20 | for (i = 0 ; ibottom) 59 | return "true"; 60 | else 61 | return "false"; 62 | } 63 | 64 | 65 | // top -> down || left -> right 66 | function sortVert(tfs) { 67 | tfs.sort(function(a, b) { 68 | return a.top == b.top ? 69 | a.left - b.left : 70 | b.top - a.top 71 | }); 72 | } -------------------------------------------------------------------------------- /SwapObjects-Center.js: -------------------------------------------------------------------------------- 1 | //based on swapObjects.js by John Wundes: https://github.com/johnwun/js4ai 2 | //this script swaps position of the two objects, aligning centers. Size remains the same. 3 | 4 | 5 | try { 6 | var selObjs = "Please select two objects on the page."; 7 | var docRef = activeDocument; 8 | if(documents.length > 0) { 9 | if(docRef.selection.length == 2) { 10 | mySelection = docRef.selection; 11 | if(mySelection instanceof Array) { 12 | //create bounding objects 13 | var A_Bounds = mySelection[0].geometricBounds; 14 | var B_Bounds = mySelection[1].geometricBounds; 15 | 16 | //define parameters objects 17 | // object A 18 | var A_left = A_Bounds[0]; 19 | var A_top = A_Bounds[1]; 20 | var A_right = A_Bounds[2]; 21 | 22 | var A_bottom = A_Bounds[3]; 23 | var A_Width = (A_right - A_left); 24 | var A_Height = (A_bottom - A_top); 25 | var A_Pos = [A_left + A_Width / 2, A_top + A_Height / 2]; 26 | 27 | // object B 28 | var B_left = B_Bounds[0]; 29 | var B_top = B_Bounds[1]; 30 | var B_right = B_Bounds[2]; 31 | var B_bottom = B_Bounds[3]; 32 | var B_Width = (B_right - B_left); 33 | var B_Height = (B_bottom - B_top); 34 | 35 | var B_Pos = [B_left + (B_Width / 2), B_top + (B_Height / 2)]; 36 | 37 | 38 | //move A (selection[0]) 39 | var center_x_1 = B_Pos[0] - mySelection[0].width / 2; 40 | 41 | var center_y_1 = B_Pos[1] + mySelection[0].height / 2; 42 | mySelection[0].position = [center_x_1, center_y_1]; 43 | // mySelection[0].position = B_Pos; 44 | 45 | //move B (selection[1]) 46 | var center_x_2 = A_Pos[0] - mySelection[1].width / 2; 47 | var center_y_2 = A_Pos[1] + mySelection[1].height / 2; 48 | mySelection[1].position = [center_x_2, center_y_2]; 49 | //mySelection[1].position = A_Pos; 50 | 51 | 52 | } 53 | } else { 54 | alert(mySelection + " is not an array!\n" + selObjs); 55 | } 56 | } else { 57 | alert("Selection is not 2 objects!\n" + selObjs); 58 | } 59 | } catch (e) { 60 | alert("problem:\n" + e); 61 | } 62 | -------------------------------------------------------------------------------- /SwapObjects-byHeight.js: -------------------------------------------------------------------------------- 1 | //based on swapObjects.js by John Wundes: https://github.com/johnwun/js4ai 2 | //this script swaps position of the two objects, aligning centers. Size changes in proportion to height. 3 | 4 | 5 | try { 6 | var selObjs = "Please select two objects on the page."; 7 | var docRef = activeDocument; 8 | if(documents.length > 0) { 9 | if(docRef.selection.length == 2) { 10 | mySelection = docRef.selection; 11 | if(mySelection instanceof Array) { 12 | //create bounding objects 13 | var A_Bounds = mySelection[0].geometricBounds; 14 | var B_Bounds = mySelection[1].geometricBounds; 15 | 16 | //define parameters objects 17 | // object A 18 | var A_left = A_Bounds[0]; 19 | var A_top = A_Bounds[1]; 20 | var A_right = A_Bounds[2]; 21 | var A_bottom = A_Bounds[3]; 22 | var A_Width = (A_right - A_left); 23 | var A_Height = (A_bottom - A_top); 24 | var A_Pos = [A_left + A_Width / 2, A_top + A_Height / 2]; 25 | 26 | // object B 27 | var B_left = B_Bounds[0]; 28 | var B_top = B_Bounds[1]; 29 | var B_right = B_Bounds[2]; 30 | var B_bottom = B_Bounds[3]; 31 | var B_Width = (B_right - B_left); 32 | var B_Height = (B_bottom - B_top); 33 | var B_Pos = [B_left + (B_Width / 2), B_top + (B_Height / 2)]; 34 | 35 | //scale A (selection[0]) 36 | var factor = B_Height / A_Height; 37 | mySelection[0].height = Math.abs(B_Height); 38 | mySelection[0].width = mySelection[0].width * factor; 39 | 40 | //scale B (selection[1]) 41 | var factor2 = A_Height / B_Height; 42 | mySelection[1].height = Math.abs(A_Height); 43 | mySelection[1].width = mySelection[1].width * factor2; 44 | 45 | //move A (selection[0]) 46 | var center_x_1 = B_Pos[0] - mySelection[0].width / 2; 47 | var center_y_1 = B_Pos[1] + mySelection[0].height / 2; 48 | mySelection[0].position = [center_x_1, center_y_1]; 49 | // mySelection[0].position = B_Pos; 50 | 51 | //move B (selection[1]) 52 | var center_x_2 = A_Pos[0] - mySelection[1].width / 2; 53 | var center_y_2 = A_Pos[1] + mySelection[1].height / 2; 54 | mySelection[1].position = [center_x_2, center_y_2]; 55 | //mySelection[1].position = A_Pos; 56 | 57 | 58 | } 59 | } else { 60 | alert(mySelection + " is not an array!\n" + selObjs); 61 | } 62 | } else { 63 | alert("Selection is not 2 objects!\n" + selObjs); 64 | } 65 | } catch (e) { 66 | alert("problem:\n" + e); 67 | } 68 | -------------------------------------------------------------------------------- /SameScale.jsx: -------------------------------------------------------------------------------- 1 | //based on ScaleToFitVerticalAxis.jsx by Janne Ojala 2 | //make selected objects same width or height 3 | 4 | #target illustrator 5 | 6 | // SAMESCALE 7 | // ========= 8 | var SameScale = new Window("dialog"); 9 | SameScale.text = "SameScale"; 10 | SameScale.preferredSize.width = 150; 11 | SameScale.orientation = "column"; 12 | SameScale.alignChildren = ["center", "center"]; 13 | SameScale.spacing = 7; 14 | SameScale.margins = 16; 15 | 16 | // MAINGROUP 17 | // ========= 18 | var MainGroup = SameScale.add("group"); 19 | MainGroup.orientation = "column"; 20 | MainGroup.alignChildren = ["left", "center"]; 21 | MainGroup.spacing = 10; 22 | MainGroup.margins = [0, 0, 0, 2]; 23 | 24 | var SameWidth = MainGroup.add("radiobutton"); 25 | SameWidth.text = "Same width"; 26 | 27 | var SameHeight = MainGroup.add("radiobutton"); 28 | SameHeight.text = "Same height "; 29 | SameHeight.value = true; 30 | SameHeight.preferredSize.width = 100; 31 | 32 | // TEXT 33 | // ==== 34 | var Text = SameScale.add("group"); 35 | Text.orientation = "row"; 36 | Text.alignChildren = ["left", "center"]; 37 | Text.spacing = 0; 38 | Text.margins = [0, 6, 0, 8]; 39 | 40 | var ValueText = Text.add("edittext", undefined, Math.round(app.activeDocument.selection[0].height)); 41 | ValueText.preferredSize.width = 40; 42 | 43 | var Units_array = ["px", "mm"]; 44 | var Units = Text.add("dropdownlist", undefined, Units_array); 45 | Units.selection = 0; 46 | 47 | // FINALGROUP 48 | // ========== 49 | var FinalGroup = SameScale.add("group"); 50 | FinalGroup.orientation = "row"; 51 | FinalGroup.alignChildren = ["left", "center"]; 52 | FinalGroup.spacing = 10; 53 | FinalGroup.margins = 0; 54 | 55 | var Ok = FinalGroup.add("button", undefined, undefined, { 56 | name: "Ok" 57 | }); 58 | Ok.text = "OK"; 59 | Ok.preferredSize.width = 96; 60 | Ok.preferredSize.height = 24; 61 | Ok.justify = "center"; 62 | 63 | var myResult = SameScale.show(); 64 | 65 | ////////////////////////////////////////////// 66 | 67 | var Value = ValueText.text; 68 | 69 | var validValue = /^[0-9.]+$/.test(Value); 70 | if(!validValue | Value == 0) { 71 | alert("Please enter a valid size. \nDon't use coma."); 72 | myResult = false; 73 | } 74 | 75 | if(myResult == true) { 76 | //alert(Units.value); 77 | 78 | if(Units.selection == 1) { 79 | Value = Value * 2.834645669; 80 | } 81 | 82 | if(SameHeight.value) { 83 | visitObjects(app.activeDocument.selection, scaleByHeight, Value); 84 | } 85 | 86 | if(SameWidth.value) { 87 | visitObjects(app.activeDocument.selection, scaleByWidth, Value); 88 | } 89 | 90 | function scaleByWidth(item, targetWidth) { 91 | var factor = targetWidth / item.width; 92 | 93 | if(item.width != 0) { 94 | if(item.height != 0) { 95 | item.height *= factor; 96 | } 97 | item.width *= factor; 98 | } 99 | } 100 | 101 | function scaleByHeight(item, targetHeight) { 102 | 103 | if(item.height != 0) { 104 | var factor = targetHeight / item.height; 105 | 106 | item.height *= factor; 107 | if(item.width != 0) { 108 | item.width *= factor; 109 | } 110 | } 111 | } 112 | 113 | 114 | function visitObjects(sel, func, opts) { 115 | for(var i = 0; i < sel.length; i++) { 116 | func(sel[i], opts); 117 | } 118 | } 119 | 120 | } 121 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | [![Behance](https://img.shields.io/badge/Behance-%40Daani_Rika-0055FF.svg)](https://www.behance.net/daanirika) 3 | [![Instagram](https://img.shields.io/badge/Instagram-%40daanirika-8034B2.svg)](https://www.instagram.com/daanirika/) 4 | 5 | 6 | # Illustrator scripts 7 | 8 | Scripts for the Illustrator, which I wrote or modified. Many scripts are made to speed up infographics creations. If you know how to improve them, write me, I will be glad :) 9 | 10 | 11 | 12 | 13 | ### Replace-Objects.jsx 14 | Based on Replace Items script by Alexander Ladygin. 15 | Script replaces selected objects with an object from the clipboard. 16 | 17 | ![Replace-Objects](gifs/Replace-Objects.gif) 18 | alt text 19 | 20 | ### Swap-Objects 21 | A set of scripts to swap objects in places. Based on the script by Herman van Boeijen, [www.nimbling.com](http://www.nimbling.com/). 22 | 23 | ![Swap-Objects](gifs/Swap-Objects.gif) 24 | 25 | ### Format-Num.jsx 26 | Script for rounding up numbers right in the Illustrator. It can also do simple mathematical operations. 27 | 28 | ![Format-Num](gifs/Format-Num.gif) 29 | 30 | ### Scale-all.jsx 31 | Script for assigning precise sizes to objects.  You can change only height or width, all together, save proportions or not. 32 | 33 | ![Scale-all](gifs/Scale-all.gif) 34 | 35 | ### Nobr-auto.jsx 36 | Mode 1: When a text frame is selected, the script uses a regular expression to find one or two-letter words and assign them the no-break attribute. Regex supports Ukrainian and Russian, does not work with English and numbers.  37 | 38 | Mode 2: if text is selected, applies no-break to it. 39 | 40 | ![Nobr-autol](gifs/Nobr-auto.gif) 41 | 42 | ### Batch-Correct-Infgrf.jsx 43 | Based on BatchTextEdit.jsx by shspage. The script helps to quickly change values in simple charts. 44 | 45 | ![Batch-Correct-Infgrf](gifs/Batch-Correct-Infgrf.gif) 46 | 47 | ### Chart-GroupByLines.jsx 48 | Groups the selected elements by rows. Useful for charts and tables. 49 | 50 | ![Chart-GroupByLines](gifs/Chart-GroupByLines.gif) 51 | 52 | ### Chart-Fix-Y.jsx 53 | The script sets equal spacing between the rows. 54 | 55 | ![Chart-Fix-Y](gifs/Chart-Fix-Y.gif) 56 | 57 | 58 | ### Quick-save.jsx 59 | A script for quickly saving pictures in jpg and png format. By default, script saves the current artboard. 60 | 61 | ![Quick-save](gifs/Quick-save.gif) 62 | 63 | ### Color-map.js 64 | A script for creating heat maps: it recolors polygons according to a range of numbers. The colors should be highlighted in the swatch panel from light to dark. Registration point of the text must be inside the polygon. 65 | 66 | Color-map-range.js 67 | Version that automatically generates colors based on selected swatches. The new colors will be generated in rgb. 68 | 69 | ![Color-map](gifs/Color-map.gif) 70 | 71 | 72 | 73 | 74 | 75 | ### Installation 76 | 77 | Download and unpack the archive. Place the script in the Illustrator scripts folder: 78 | 79 | 80 | For Windows (32 bit): C:\Program Files (x86)\Adobe\Adobe Illustrator\Presets\en_GB[your localisation]\Scripts 81 | 82 | For Windows (64 bit): C:\Program Files\Adobe\Adobe Illustrator(64 Bit)\Presets\en_GB[your localisation]\Scripts\ 83 | 84 | 85 | Restart the Illustrator. To launch the script, go to the File > Scripts. 86 | -------------------------------------------------------------------------------- /Color_map_range.js: -------------------------------------------------------------------------------- 1 | startAction(); 2 | 3 | function startAction() { 4 | 5 | var doc = app.activeDocument; 6 | var sel = doc.selection; 7 | var polygons = []; 8 | var values = []; 9 | var a = 0; 10 | var b = 0; 11 | var currentPathPoints; 12 | var erorr = null; 13 | var textPath = []; 14 | /* 15 | var col = new RGBColor(); 16 | col.red = 48; 17 | col.green = 32; 18 | col.blue = 126; 19 | */ 20 | var polygonsNew = []; 21 | 22 | // разделяем текст и полигоны 23 | for (var i = 0; i < sel.length; i++) { 24 | 25 | if (sel[i].typename == "PathItem") { 26 | polygons[a] = sel[i]; 27 | currentPathPoints = polygons[a].selectedPathPoints; 28 | var polygonsNewObj = []; 29 | for (var t = 0; t < currentPathPoints.length; t++) { 30 | polygonsNewObj[t] = currentPathPoints[t].anchor; 31 | } 32 | polygonsNew.push(polygonsNewObj); 33 | a++; 34 | 35 | } else if (sel[i].typename == "TextFrame") { 36 | // values[b] = sel[i]; 37 | textPath.push(sel[i]); 38 | values.push(sel[i].contents 39 | .replace(new RegExp(",", 'g'), ".") 40 | .replace(new RegExp("%", 'g'), "") 41 | ); 42 | 43 | b++; 44 | } 45 | } 46 | 47 | if (polygonsNew.length != values.length) { 48 | erorr = "Please, select the same number of objects and captions"; 49 | } 50 | 51 | //// 52 | // работаем с образцами 53 | var swatchesSel = doc.swatches.getSelected(); 54 | if (swatchesSel.length == 0) { 55 | erorr = "Please, select at least 2 swatches"; 56 | } 57 | 58 | var colors = []; 59 | 60 | for (var b = 0; b < swatchesSel.length; b++) { 61 | var color; 62 | if (swatchesSel[b].color.typename == "SpotColor") { 63 | color = swatchesSel[b].color.spot.color; 64 | } else { 65 | color = swatchesSel[b].color; 66 | } 67 | 68 | if (color.typename == "RGBColor") { 69 | colors[b] = color; 70 | } else if (color.typename == "CMYKColor") { 71 | colors[b] = ConvertCMYKSwatch(color); 72 | } else { 73 | erorr = "Please, select RGB or CMYK swatches!"; 74 | } 75 | } 76 | 77 | ////////////// 78 | if (erorr != null) { 79 | alert(erorr); 80 | return; 81 | } 82 | //////////// 83 | 84 | var indx1; 85 | var indx2; 86 | var fractBetween = 0; 87 | 88 | var minDataVal = Math.min.apply(Math, values); 89 | var maxDataValue = Math.max.apply(Math, values); 90 | var parts = colors.length - 1; 91 | 92 | //////////// 93 | 94 | for (var d = 0; d < values.length; d++) { 95 | 96 | var value = ((values[d] - minDataVal) / (maxDataValue - minDataVal)); 97 | if (value <= 0) { 98 | indx1 = indx2 = 0; 99 | } else if (value >= 1) { 100 | indx1 = indx2 = parts; 101 | } else { 102 | indx1 = Math.floor(value * parts); 103 | indx2 = indx1 + 1; 104 | fractBetween = value * parts - indx1; 105 | } 106 | 107 | var col = new RGBColor(); 108 | col.red = ((colors[indx2].red - colors[indx1].red) * fractBetween + colors[indx1].red); 109 | col.green = ((colors[indx2].green - colors[indx1].green) * fractBetween + colors[indx1].green); 110 | col.blue = ((colors[indx2].blue - colors[indx1].blue) * fractBetween + colors[indx1].blue); 111 | 112 | ///////////////// 113 | 114 | for (var z = 0; z < polygonsNew.length; z++) { 115 | var IsInside = inside(textPath[d].anchor, polygonsNew[z]); 116 | 117 | if (IsInside == true) { 118 | polygons[z].fillColor = col; 119 | break; 120 | } 121 | } 122 | 123 | if (IsInside == false) { 124 | erorr = ("Text anchors should be inside poligons! "); 125 | } 126 | } 127 | 128 | if (erorr != null) { 129 | alert(erorr); 130 | return; 131 | } 132 | 133 | } 134 | 135 | /////////////// 136 | function ConvertCMYKSwatch(swatch) { 137 | var cmyk = [ 138 | swatch.cyan, 139 | swatch.magenta, 140 | swatch.yellow, 141 | swatch.black 142 | ]; 143 | var rgb = (app.convertSampleColor( 144 | ImageColorSpace.CMYK, 145 | cmyk, ImageColorSpace.RGB, 146 | ColorConvertPurpose.defaultpurpose)); 147 | 148 | var newRGBColor = new RGBColor(); 149 | newRGBColor.red = rgb[0].toFixed(1) * 1; 150 | newRGBColor.green = rgb[1].toFixed(1) * 1; 151 | newRGBColor.blue = rgb[2].toFixed(1) * 1; 152 | 153 | return newRGBColor; 154 | } 155 | 156 | /////////////////////////// 157 | 158 | function inside(point, vs) { 159 | // ray-casting algorithm based on 160 | // https://wrf.ecse.rpi.edu/Research/Short_Notes/pnpoly.html/pnpoly.html 161 | 162 | var x = point[0], 163 | y = point[1]; 164 | 165 | var inside = false; 166 | for (var i = 0, j = vs.length - 1; i < vs.length; j = i++) { 167 | var xi = vs[i][0], 168 | yi = vs[i][1]; 169 | var xj = vs[j][0], 170 | yj = vs[j][1]; 171 | 172 | var intersect = ((yi > y) != (yj > y)) && 173 | (x < (xj - xi) * (y - yi) / (yj - yi) + xi); 174 | if (intersect) inside = !inside; 175 | } 176 | 177 | return inside; 178 | }; -------------------------------------------------------------------------------- /FormatNum.jsx: -------------------------------------------------------------------------------- 1 | #target illustrator 2 | 3 | /* 4 | Version: 1.07 5 | Made by daani-rika: https://github.com/daani-rika/Illustrator-scripts 6 | Based on: 7 | //https://graphicdesign.stackexchange.com/questions/50503/how-to-do-a-wildcard-grep-regex-find-replace-in-illustrator/50504#50504 8 | //https://stackoverflow.com/a/19529302 9 | //https://stackoverflow.com/a/55848405 10 | */ 11 | 12 | 13 | 14 | // ROUNDNUM 15 | // ======== 16 | var RoundNum = new Window("dialog"); 17 | RoundNum.text = "Round Numbers"; 18 | RoundNum.orientation = "column"; 19 | RoundNum.alignChildren = ["left","top"]; 20 | RoundNum.spacing = 10; 21 | RoundNum.margins = 16; 22 | 23 | // ROUNDINGGROUP 24 | // ============= 25 | var RoundingGroup = RoundNum.add("group", undefined, {name: "RoundingGroup"}); 26 | RoundingGroup.orientation = "row"; 27 | RoundingGroup.alignChildren = ["left","bottom"]; 28 | RoundingGroup.spacing = 10; 29 | RoundingGroup.margins = 0; 30 | 31 | var Round_Check = RoundingGroup.add("checkbox", undefined, undefined, {name: "Round_Check"}); 32 | Round_Check.text = "Round places"; 33 | Round_Check.value = true; 34 | 35 | 36 | var RoundPlace = RoundingGroup.add('edittext {justify: "center", properties: {name: "RoundPlace"}}'); 37 | RoundPlace.text = "1"; 38 | RoundPlace.preferredSize.width = 40; 39 | RoundPlace.preferredSize.height = 24; 40 | RoundPlace.alignment = ["left","center"]; 41 | 42 | // AFFECT_GROUP 43 | // ============ 44 | var Affect_Group = RoundNum.add("group", undefined, {name: "Affect_Group"}); 45 | Affect_Group.orientation = "row"; 46 | Affect_Group.alignChildren = ["left","top"]; 47 | Affect_Group.spacing = 10; 48 | Affect_Group.margins = 0; 49 | 50 | var Affect_Check = Affect_Group.add("checkbox", undefined, undefined, {name: "Affect_Check"}); 51 | Affect_Check.text = "Round small numbers"; 52 | 53 | // OPERATEGROUP 54 | // ============ 55 | var OperateGroup = RoundNum.add("group", undefined, {name: "OperateGroup"}); 56 | OperateGroup.orientation = "row"; 57 | OperateGroup.alignChildren = ["left","bottom"]; 58 | OperateGroup.spacing = 10; 59 | OperateGroup.margins = 0; 60 | 61 | 62 | // GROUP1 63 | // ====== 64 | var group1 = OperateGroup.add("group", undefined, {name: "group1"}); 65 | group1.orientation = "row"; 66 | group1.alignChildren = ["left","bottom"]; 67 | group1.spacing = 0; 68 | group1.margins = 0; 69 | 70 | var Operate_Check = group1.add("checkbox", undefined, undefined, {name: "Operate_Check"}); 71 | Operate_Check.alignment = ["left","bottom"]; 72 | 73 | var Operation_array = ["×","/","+","–"]; 74 | var Operation = group1.add("dropdownlist", undefined, undefined, {name: "Operation", items: Operation_array}); 75 | Operation.selection = 1; 76 | 77 | // OPERATEGROUP 78 | // ============ 79 | var Operator = OperateGroup.add('edittext {justify: "center", properties: {name: "Operator"}}'); 80 | Operator.text = "1000"; 81 | Operator.preferredSize.width = 80; 82 | 83 | // REGEXGROUP 84 | // ========== 85 | var RegExGroup = RoundNum.add("group", undefined, {name: "RegExGroup"}); 86 | RegExGroup.orientation = "row"; 87 | RegExGroup.alignChildren = ["left","bottom"]; 88 | RegExGroup.spacing = 4; 89 | RegExGroup.margins = 0; 90 | 91 | // GROUP2 92 | // ====== 93 | var group2 = RegExGroup.add("group", undefined, {name: "group2"}); 94 | group2.orientation = "row"; 95 | group2.alignChildren = ["left","bottom"]; 96 | group2.spacing = 0; 97 | group2.margins = 0; 98 | 99 | var Regex_Check = group2.add("checkbox", undefined, undefined, {name: "Regex_Check"}); 100 | 101 | var statictext1 = group2.add("statictext", undefined, undefined, {name: "statictext1"}); 102 | statictext1.text = " RegEx"; 103 | statictext1.preferredSize.width = 47; 104 | statictext1.alignment = ["left","top"]; 105 | 106 | // REGEXGROUP 107 | // ========== 108 | var RegEx = RegExGroup.add('edittext {justify: "center", properties: {name: "RegEx"}}'); 109 | RegEx.text = "\\d+(?:[,.]\\d+)?(?: \\d+(?:[,.]\\d+)?)*"; 110 | RegEx.preferredSize.width = 80; 111 | RegEx.alignment = ["left","bottom"]; 112 | 113 | // ROUNDNUM 114 | // ======== 115 | var divider1 = RoundNum.add("panel", undefined, undefined, {name: "divider1"}); 116 | divider1.alignment = "fill"; 117 | 118 | // FINALBUTTONS 119 | // ============ 120 | var FinalButtons = RoundNum.add("group", undefined, {name: "FinalButtons"}); 121 | FinalButtons.orientation = "row"; 122 | FinalButtons.alignChildren = ["center","center"]; 123 | FinalButtons.spacing = 10; 124 | FinalButtons.margins = 0; 125 | 126 | var OkButton = FinalButtons.add("button", undefined, undefined, {name: "OkButton"}); 127 | OkButton.text = "OK"; 128 | OkButton.preferredSize.width = 60; 129 | OkButton.onClick = findnum; 130 | 131 | var CancelButton = FinalButtons.add("button", undefined, undefined, {name: "CancelButton"}); 132 | CancelButton.text = "Cancel"; 133 | CancelButton.preferredSize.width = 74; 134 | CancelButton.onClick = function() { 135 | RoundNum.close(); 136 | } 137 | 138 | RoundNum.show(); 139 | 140 | 141 | function commafy(inVal) { 142 | var arrWhole = inVal.toString(); 143 | arrWhole = arrWhole.split("."); 144 | var arrTheNumber = arrWhole[0].split("").reverse(); 145 | var newNum = Array(); 146 | for (var i = 0; i < arrTheNumber.length; i++) { 147 | newNum[newNum.length] = ((i % 3 === 2)) ? " " + arrTheNumber[i] : arrTheNumber[i]; //format all figures 148 | // newNum[newNum.length] = ((i%3===2) && (i 1) { 214 | current = current.toFixed(RoundPlace.text); 215 | } else if (current < 1) { 216 | current = current; 217 | } 218 | } 219 | 220 | } 221 | 222 | current = commafy(current); 223 | current = current.replace(new RegExp("^\\s", 'g'), ""); 224 | current = current.toString().replace(".", ","); 225 | 226 | if (current != finded[a]) { 227 | var newstring2 = string.replace(finded[a], current); 228 | text.contents = newstring2; 229 | changes++; 230 | } 231 | 232 | } 233 | 234 | } 235 | 236 | } 237 | } 238 | 239 | if (gr != 0) { 240 | alert("You have " + gr + " groups here!"); 241 | } 242 | alert(changes == 1 ? "1 text object changed" : changes + " text objects changed"); 243 | 244 | RoundNum.close(); 245 | 246 | } -------------------------------------------------------------------------------- /Scale-all.jsx: -------------------------------------------------------------------------------- 1 | #target illustrator; 2 | 3 | /* 4 | Version: 1.07 5 | Made by daani-rika: https://github.com/daani-rika/Illustrator-scripts 6 | */ 7 | 8 | 9 | 10 | 11 | 12 | // DIALOG 13 | // ====== 14 | var Dialog = new Window("dialog"); 15 | Dialog.text = "Change size"; 16 | Dialog.preferredSize.width = 250; 17 | Dialog.orientation = "column"; 18 | Dialog.alignChildren = ["center","top"]; 19 | Dialog.spacing = 10; 20 | Dialog.margins = 16; 21 | 22 | // MAINGROUP 23 | // ========= 24 | var MainGroup = Dialog.add("group", undefined, {name: "MainGroup"}); 25 | MainGroup.preferredSize.height = 29; 26 | MainGroup.orientation = "row"; 27 | MainGroup.alignChildren = ["center","center"]; 28 | MainGroup.spacing = 4; 29 | MainGroup.margins = 0; 30 | 31 | var iconbutton1_imgString = "%C2%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%06%00%00%00%10%08%06%00%00%01BD%3EX%00%00%00%09pHYs%00%00%0B%12%00%00%0B%12%01%C3%92%C3%9D~%C3%BC%00%00%00%C2%A9IDAT%18%C2%95MP%01%11%C3%82%40%0CK8%04L%028%40%02s%C2%80%C2%84%C2%A1%00%0B8%C2%99%04%24l%0E%C2%98%03%24%C3%B0%0E%C3%82%C2%A5%C3%97%3E%C3%AB%C3%9D%C3%9F7%C3%BD%7C%C3%93%14%11%C2%92%C3%94%C2%B3%2F%0B%1EP!%C3%A9%C3%9A%09%C3%8F%3F%C3%95%C3%B5%60g%C3%B2*%C2%A0d%7C%C3%9C%C3%A3%C2%9E%C2%85%C3%95%C2%95A%C3%92%C2%A9%1A%C2%BC%25%C3%8DQ(%05%C3%9F%C3%BE%C3%A3nA3h%00%16%00%C2%9B%C3%81F%C3%B2%0C%C3%A0%12%C3%A3%C2%B9c%C3%B7%C3%90%7DH%C2%9Ar%C2%BE%C2%8Ai%C3%8F*)%0F%13%C2%B8%C2%ACZ%09%24%C3%A3.%C3%B9%15%C2%80'%C2%B5%C2%BB%C3%9B~'%C3%B1U%C3%92%C2%92%C2%8F%C3%8E%C2%87c%11H%C2%8E%C2%BB%C3%AD%C2%8E%C3%A5%C3%A4%C2%91%C3%82%C2%B9G4%26%C3%8B~%7D%1A%C3%89%0D%00~*%C3%B2%C2%B4%C2%B1%25z*H%00%00%00%00IEND%C2%AEB%60%C2%82"; 32 | var iconbutton1 = MainGroup.add("iconbutton", undefined, File.decode(iconbutton1_imgString), {name: "iconbutton1", style: "toolbutton", toggle: true}); 33 | iconbutton1.preferredSize.width = 30; 34 | iconbutton1.preferredSize.height = 30; 35 | iconbutton1.alignment = ["left","top"]; 36 | 37 | var px = MainGroup.add("radiobutton", undefined, undefined, {name: "radiobutton1"}); 38 | px.text = "px"; 39 | // px.value = true; 40 | px.preferredSize.height = 22; 41 | px.alignment = ["center","bottom"]; 42 | 43 | var mm = MainGroup.add("radiobutton", undefined, undefined, {name: "radiobutton2"}); 44 | mm.text = "mm"; 45 | mm.preferredSize.height = 22; 46 | mm.alignment = ["center","bottom"]; 47 | 48 | 49 | 50 | var Center = MainGroup.add("checkbox", undefined, undefined, {name: "Center"}); 51 | Center.text = "From center"; 52 | Center.preferredSize.height = 21; 53 | Center.alignment = ["center","bottom"]; 54 | Center.value = true; 55 | 56 | // DIALOG 57 | // ====== 58 | var divider1 = Dialog.add("panel", undefined, undefined, {name: "divider1"}); 59 | divider1.alignment = "fill"; 60 | 61 | // CONFIRM_PANEL 62 | // ============= 63 | var Confirm_panel = Dialog.add("group", undefined, {name: "Confirm_panel"}); 64 | Confirm_panel.orientation = "row"; 65 | Confirm_panel.alignChildren = ["right","top"]; 66 | Confirm_panel.spacing = 9; 67 | Confirm_panel.margins = 0; 68 | 69 | var Width_value = Confirm_panel.add('edittext {justify: "center", properties: {name: "Width_value"}}'); 70 | 71 | 72 | Width_value.preferredSize.width = 105; 73 | Width_value.preferredSize.height = 24; 74 | 75 | var Width_ok = Confirm_panel.add("button", undefined, undefined, {name: "Width_ok"}); 76 | Width_ok.text = "Only width"; 77 | Width_ok.preferredSize.width = 99; 78 | Width_ok.onClick = Change_width; 79 | 80 | // EDITTEXT_PANEL 81 | // ============== 82 | var EditText_panel = Dialog.add("group", undefined, {name: "EditText_panel"}); 83 | EditText_panel.orientation = "row"; 84 | EditText_panel.alignChildren = ["center","center"]; 85 | EditText_panel.spacing = 10; 86 | EditText_panel.margins = 0; 87 | EditText_panel.alignment = ["center","top"]; 88 | 89 | var Height_value = EditText_panel.add('edittext {justify: "center", properties: {name: "Height_value"}}'); 90 | Height_value.preferredSize.width = 105; 91 | Height_value.preferredSize.height = 24; 92 | 93 | if (app.activeDocument.rulerUnits == "RulerUnits.Pixels"){ 94 | px.value = true; 95 | Width_value.text = (app.activeDocument.selection[0].width).toFixed(0); 96 | Height_value.text=(app.activeDocument.selection[0].height).toFixed(0); 97 | } else { 98 | mm.value = true; 99 | Width_value.text = (app.activeDocument.selection[0].width/2.834645669).toFixed(2); 100 | Height_value.text=(app.activeDocument.selection[0].height/2.834645669).toFixed(2); 101 | } 102 | 103 | var Height_ok = EditText_panel.add("button", undefined, undefined, {name: "Height_ok"}); 104 | Height_ok.text = "Only height"; 105 | Height_ok.preferredSize.width = 99; 106 | Height_ok.alignment = ["center","center"]; 107 | Height_ok.onClick = Change_height; 108 | 109 | // DIALOG 110 | // ====== 111 | var divider2 = Dialog.add("panel", undefined, undefined, {name: "divider2"}); 112 | divider2.alignment = "fill"; 113 | 114 | // GROUP1 115 | // ====== 116 | var group1 = Dialog.add("group", undefined, {name: "group1"}); 117 | group1.orientation = "row"; 118 | group1.alignChildren = ["left","center"]; 119 | group1.spacing =22; 120 | group1.margins = 0; 121 | group1.alignment = ["center","top"]; 122 | 123 | 124 | var Cancel = group1.add("button", undefined, undefined, {name: "Cancel"}); 125 | Cancel.text = "Cancel"; 126 | Cancel.preferredSize.width = 95; 127 | Cancel.preferredSize.height = 30; 128 | Cancel.alignment = ["left","center"]; 129 | /* 130 | 131 | var iconbutton1_imgString = "%C2%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%06%00%00%00%10%08%06%00%00%01BD%3EX%00%00%00%09pHYs%00%00%0B%12%00%00%0B%12%01%C3%92%C3%9D~%C3%BC%00%00%00%C2%A9IDAT%18%C2%95MP%01%11%C3%82%40%0CK8%04L%028%40%02s%C2%80%C2%84%C2%A1%00%0B8%C2%99%04%24l%0E%C2%98%03%24%C3%B0%0E%C3%82%C2%A5%C3%97%3E%C3%AB%C3%9D%C3%9F7%C3%BD%7C%C3%93%14%11%C2%92%C3%94%C2%B3%2F%0B%1EP!%C3%A9%C3%9A%09%C3%8F%3F%C3%95%C3%B5%60g%C3%B2*%C2%A0d%7C%C3%9C%C3%A3%C2%9E%C2%85%C3%95%C2%95A%C3%92%C2%A9%1A%C2%BC%25%C3%8DQ(%05%C3%9F%C3%BE%C3%A3nA3h%00%16%00%C2%9B%C3%81F%C3%B2%0C%C3%A0%12%C3%A3%C2%B9c%C3%B7%C3%90%7DH%C2%9Ar%C2%BE%C2%8Ai%C3%8F*)%0F%13%C2%B8%C2%ACZ%09%24%C3%A3.%C3%B9%15%C2%80'%C2%B5%C2%BB%C3%9B~'%C3%B1U%C3%92%C2%92%C2%8F%C3%8E%C2%87c%11H%C2%8E%C2%BB%C3%AD%C2%8E%C3%A5%C3%A4%C2%91%C3%82%C2%B9G4%26%C3%8B~%7D%1A%C3%89%0D%00~*%C3%B2%C2%B4%C2%B1%25z*H%00%00%00%00IEND%C2%AEB%60%C2%82"; 132 | var iconbutton1 = group1.add("iconbutton", undefined, File.decode(iconbutton1_imgString), {name: "iconbutton1", style: "button", toggle: true}); 133 | iconbutton1.preferredSize.width = 30; 134 | iconbutton1.preferredSize.height = 30; 135 | iconbutton1.alignment = ["left","top"]; 136 | 137 | */ 138 | var Change_all = group1.add("button", undefined, undefined, {name: "Change_all"}); 139 | Change_all.text = "Make equal"; 140 | Change_all.preferredSize.width = 99; 141 | Change_all.preferredSize.height = 31; 142 | Change_all.alignment = ["left","center"]; 143 | Change_all.onClick = Change_all_start; 144 | 145 | Dialog.show(); 146 | 147 | 148 | ////////////////////////////////////////////////////////////// 149 | 150 | function Change_width() { 151 | var Height_v = (Height_value.text.replace(new RegExp(",", 'g'), "."))*1; 152 | var Width_v = (Width_value.text.replace(new RegExp(",", 'g'), "."))*1; 153 | 154 | if (mm.value == true) { 155 | Height_v = Height_v * 2.834645669; 156 | Width_v = Width_v * 2.834645669; 157 | } 158 | 159 | for (var x = 0; x < activeDocument.selection.length; x++) { 160 | item = activeDocument.selection[x]; 161 | center_point = [item.top-(item.height/2),item.left+(item.width/2)]; 162 | 163 | 164 | if (iconbutton1.value == true){ 165 | item.height = item.height * Width_v/item.width; 166 | } 167 | 168 | item.width = Width_v; 169 | 170 | if (Center.value == true){ 171 | item.top = center_point[0] + (item.height/2); 172 | item.left = center_point[1] - (item.width/2); 173 | } 174 | } 175 | Dialog.close(); 176 | } 177 | 178 | ////////////////////////////////////////////////////////////// 179 | function Change_height(Height_v) { 180 | var Height_v = (Height_value.text.replace(new RegExp(",", 'g'), "."))*1; 181 | var Width_v = (Width_value.text.replace(new RegExp(",", 'g'), "."))*1; 182 | 183 | if (mm.value == true) { 184 | Height_v = Height_v * 2.834645669; 185 | Width_v = Width_v * 2.834645669; 186 | } 187 | 188 | for (var x = 0; x < activeDocument.selection.length; x++) { 189 | item = activeDocument.selection[x]; 190 | center_point = [item.top-(item.height/2),item.left+(item.width/2)]; 191 | 192 | 193 | if (iconbutton1.value == true){ 194 | item.width = item.width * Height_v/item.height; 195 | } 196 | 197 | item.height = Height_v; 198 | 199 | if (Center.value == true){ 200 | item.top = center_point[0] + (item.height/2); 201 | item.left = center_point[1] - (item.width/2); 202 | } 203 | } 204 | Dialog.close(); 205 | } 206 | 207 | ////////////////////////////////////////////////////////////// 208 | function Change_all_start() { 209 | var Height_v = (Height_value.text.replace(new RegExp(",", 'g'), "."))*1; 210 | var Width_v = (Width_value.text.replace(new RegExp(",", 'g'), "."))*1; 211 | 212 | if (mm.value == true) { 213 | Height_v = Height_v * 2.834645669; 214 | Width_v = Width_v * 2.834645669; 215 | } 216 | 217 | for (var x = 0; x < activeDocument.selection.length; x++) { 218 | item = activeDocument.selection[x]; 219 | center_point = [item.top-(item.height/2),item.left+(item.width/2)]; 220 | 221 | item.width = Width_v; 222 | item.height = Height_v; 223 | 224 | if (Center.value == true){ 225 | item.top = center_point[0] + (item.height/2); 226 | item.left = center_point[1] - (item.width/2); 227 | } 228 | } 229 | Dialog.close(); 230 | } -------------------------------------------------------------------------------- /Color_map_01.js: -------------------------------------------------------------------------------- 1 | /* 2 | Code for Import https://scriptui.joonas.me — (Triple click to select): 3 | {"activeId":13,"items":{"item-0":{"id":0,"type":"Dialog","parentId":false,"style":{"enabled":true,"varName":null,"windowType":"Dialog","creationProps":{"su1PanelCoordinates":false,"maximizeButton":false,"minimizeButton":false,"independent":false,"closeButton":true,"borderless":false,"resizeable":false},"text":"Dialog","preferredSize":[0,0],"margins":16,"orientation":"column","spacing":10,"alignChildren":["center","top"]}},"item-1":{"id":1,"type":"Group","parentId":26,"style":{"enabled":true,"varName":"ColorGroup","preferredSize":[0,0],"margins":0,"orientation":"row","spacing":0,"alignChildren":["left","center"],"alignment":null}},"item-4":{"id":4,"type":"EditText","parentId":28,"style":{"enabled":true,"varName":"ValueTx","creationProps":{"noecho":false,"readonly":false,"multiline":false,"scrollable":false,"borderless":false,"enterKeySignalsOnChange":false},"softWrap":false,"text":"25","justify":"center","preferredSize":[80,0],"alignment":null,"helpTip":null}},"item-7":{"id":7,"type":"Button","parentId":1,"style":{"enabled":false,"varName":"ColorSw","text":"","justify":"center","preferredSize":[90,30],"alignment":null,"helpTip":null}},"item-13":{"id":13,"type":"StaticText","parentId":28,"style":{"enabled":true,"varName":"maxValue","creationProps":{"truncate":"none","multiline":false,"scrolling":false},"softWrap":false,"text":"100","justify":"right","preferredSize":[30,0],"alignment":null,"helpTip":null}},"item-22":{"id":22,"type":"Group","parentId":0,"style":{"enabled":true,"varName":"FinalGroup","preferredSize":[0,0],"margins":0,"orientation":"row","spacing":10,"alignChildren":["left","center"],"alignment":null}},"item-23":{"id":23,"type":"Button","parentId":22,"style":{"enabled":true,"varName":"OK","text":"OK","justify":"center","preferredSize":[0,0],"alignment":null,"helpTip":null}},"item-26":{"id":26,"type":"Group","parentId":0,"style":{"enabled":true,"varName":"ColorsGroup","preferredSize":[0,0],"margins":0,"orientation":"column","spacing":10,"alignChildren":["center","center"],"alignment":null}},"item-28":{"id":28,"type":"Group","parentId":26,"style":{"enabled":true,"varName":"ValueGroup","preferredSize":[0,0],"margins":0,"orientation":"row","spacing":10,"alignChildren":["center","center"],"alignment":"fill"}},"item-32":{"id":32,"type":"StaticText","parentId":28,"style":{"enabled":true,"varName":"minValue","creationProps":{"truncate":"none","multiline":false,"scrolling":false},"softWrap":false,"text":"0","justify":"left","preferredSize":[30,0],"alignment":null,"helpTip":null}}},"order":[0,26,1,7,28,32,4,13,22,23],"settings":{"importJSON":true,"indentSize":false,"cepExport":false,"includeCSSJS":true,"showDialog":true,"functionWrapper":false,"afterEffectsDockable":false,"itemReferenceList":"None"}} 4 | */ 5 | 6 | // DIALOG 7 | // ====== 8 | var dialog = new Window("dialog"); 9 | dialog.text = "Dialog"; 10 | dialog.orientation = "column"; 11 | dialog.alignChildren = ["center", "top"]; 12 | dialog.spacing = 10; 13 | dialog.margins = 16; 14 | 15 | // COLORSGROUP 16 | // =========== 17 | var ColorsGroup = dialog.add("group", undefined, { 18 | name: "ColorsGroup" 19 | }); 20 | ColorsGroup.orientation = "column"; 21 | ColorsGroup.alignChildren = ["center", "center"]; 22 | ColorsGroup.spacing = 10; 23 | ColorsGroup.margins = 0; 24 | 25 | // COLORGROUP 26 | // ========== 27 | var ColorGroup = ColorsGroup.add("group", undefined, { 28 | name: "ColorGroup" 29 | }); 30 | ColorGroup.orientation = "row"; 31 | ColorGroup.alignChildren = ["left", "center"]; 32 | ColorGroup.spacing = 0; 33 | ColorGroup.margins = 0; 34 | 35 | // VALUEGROUP 36 | // ========== 37 | var ValueGroup = ColorsGroup.add("group", undefined, { 38 | name: "ValueGroup" 39 | }); 40 | ValueGroup.orientation = "row"; 41 | ValueGroup.alignChildren = ["center", "center"]; 42 | ValueGroup.spacing = 10; 43 | ValueGroup.margins = 0; 44 | ValueGroup.alignment = ["fill", "center"]; 45 | 46 | var minValue = ValueGroup.add("statictext", undefined, undefined, {name: "minValue"}); 47 | minValue.preferredSize.width = 30; 48 | 49 | // FINALGROUP 50 | // ========== 51 | var FinalGroup = dialog.add("group", undefined, {name: "FinalGroup"}); 52 | FinalGroup.orientation = "row"; 53 | FinalGroup.alignChildren = ["left", "center"]; 54 | FinalGroup.spacing = 10; 55 | FinalGroup.margins = 0; 56 | 57 | var OK = FinalGroup.add("button", undefined, undefined, {name: "OK"}); 58 | OK.text = "OK"; 59 | 60 | var CancelButton =FinalGroup.add("button", undefined, undefined, {name: "CancelButton"}); 61 | CancelButton.text = "Cancel"; 62 | CancelButton.preferredSize.width = 74; 63 | 64 | /////////// 65 | 66 | var doc = app.activeDocument; 67 | var sel = doc.selection; 68 | var polygons = []; 69 | var values = []; 70 | var a = 0; 71 | var b = 0; 72 | var currentPathPoints; 73 | var erorr = null; 74 | var textPath = []; 75 | var polygonsNew = []; 76 | 77 | // разделяем текст и полигоны 78 | for (var i = 0; i < sel.length; i++) { 79 | 80 | if (sel[i].typename == "PathItem") { 81 | polygons[a] = sel[i]; 82 | currentPathPoints = polygons[a].selectedPathPoints; 83 | var polygonsNewObj = []; 84 | for (var t = 0; t < currentPathPoints.length; t++) { 85 | polygonsNewObj[t] = currentPathPoints[t].anchor; 86 | } 87 | polygonsNew.push(polygonsNewObj); 88 | a++; 89 | 90 | } else if (sel[i].typename == "TextFrame") { 91 | // values[b] = sel[i]; 92 | textPath.push(sel[i]); 93 | values.push(sel[i].contents 94 | .replace(new RegExp(",", 'g'), ".") 95 | .replace(new RegExp("%", 'g'), "") 96 | ); 97 | 98 | b++; 99 | } 100 | } 101 | 102 | var minVal = Math.min.apply(Math, values); 103 | var maxVal = Math.max.apply(Math, values); 104 | minValue.text = minVal ; 105 | 106 | var swatchesSel = doc.swatches.getSelected(); 107 | if (swatchesSel.length <= 1) { 108 | erorr = "Please, select at least 3 swatches"; 109 | } 110 | 111 | var colors = []; 112 | 113 | for (var b = 0; b < swatchesSel.length; b++) { 114 | var color; 115 | if (swatchesSel[b].color.typename == "SpotColor") { 116 | color = swatchesSel[b].color.spot.color; 117 | } else { 118 | color = swatchesSel[b].color; 119 | } 120 | 121 | if (color.typename == "RGBColor") { 122 | colors[b] = color; 123 | } else if (color.typename == "CMYKColor") { 124 | colors[b] = ConvertCMYKSwatch(color); 125 | } else { 126 | erorr = "Please, select RGB or CMYK swatches!"; 127 | } 128 | 129 | // COLORGROUP 130 | // ========== 131 | var ColorSw = ColorGroup.add("button", undefined, undefined, { 132 | name: "ColorSw" 133 | }); 134 | ColorSw.enabled = false; 135 | ColorSw.preferredSize.width = 90; 136 | ColorSw.preferredSize.height = 30; 137 | 138 | ColorSw.fillBrush = ColorSw.graphics.newBrush(ColorSw.graphics.BrushType.SOLID_COLOR, ConvertToUIColor(colors[b])); 139 | ColorSw.onDraw = customDraw; 140 | 141 | if (b != swatchesSel.length - 1) { 142 | var ValueTx = ValueGroup.add('edittext {justify: "center"}}'); 143 | ValueTx.text = Math.floor(minVal + ((maxVal - minVal) / swatchesSel.length) * (b + 1)); 144 | ValueTx.preferredSize.width = 80; 145 | } 146 | 147 | } 148 | 149 | var maxValue = ValueGroup.add("statictext", undefined, undefined, {name: "maxValue"}); 150 | maxValue.text =maxVal; 151 | maxValue.preferredSize.width = 30; 152 | maxValue.justify = "right"; 153 | 154 | 155 | if (polygonsNew.length != values.length) { 156 | erorr = "Please, select the same number of objects and captions"; 157 | } 158 | 159 | if (erorr != null) { 160 | alert(erorr); 161 | dialog.close(); 162 | } 163 | 164 | CancelButton.onClick = function() { 165 | dialog.close(); 166 | } 167 | 168 | OK.onClick = MakeColorMap; 169 | dialog.show(); 170 | 171 | 172 | 173 | 174 | 175 | ////////////////// 176 | function MakeColorMap(){ 177 | 178 | 179 | for (var d = 0; d < values.length; d++) { 180 | 181 | var value = values[d]; 182 | var col; 183 | 184 | for (var u = 0; u < colors.length; u++) { 185 | if (value <= ValueGroup.children[u + 1].text * 1) { 186 | col = colors[u]; 187 | break; 188 | } 189 | } 190 | 191 | for (var z = 0; z < polygonsNew.length; z++) { 192 | var IsInside = inside(textPath[d].anchor, polygonsNew[z]); 193 | 194 | if (IsInside == true) { 195 | polygons[z].fillColor = col; 196 | break; 197 | } 198 | } 199 | 200 | if (IsInside == false) { 201 | erorr = ("Text anchors should be inside poligons! "); 202 | } 203 | 204 | } 205 | if (erorr != null) { 206 | alert(erorr); 207 | dialog.close(); 208 | return; 209 | } 210 | 211 | dialog.close(); 212 | } 213 | 214 | 215 | 216 | 217 | 218 | //////////////// 219 | function customDraw() { 220 | with(this) { 221 | graphics.drawOSControl(); 222 | graphics.rectPath(0, 0, size[0], size[1]); 223 | graphics.fillPath(fillBrush); 224 | 225 | } 226 | } 227 | 228 | function ConvertCMYKSwatch(swatch) { 229 | var cmyk = [ 230 | swatch.cyan, 231 | swatch.magenta, 232 | swatch.yellow, 233 | swatch.black 234 | ]; 235 | var rgb = (app.convertSampleColor( 236 | ImageColorSpace.CMYK, 237 | cmyk, ImageColorSpace.RGB, 238 | ColorConvertPurpose.defaultpurpose)); 239 | 240 | var newRGBColor = new RGBColor(); 241 | newRGBColor.red = rgb[0].toFixed(1) * 1; 242 | newRGBColor.green = rgb[1].toFixed(1) * 1; 243 | newRGBColor.blue = rgb[2].toFixed(1) * 1; 244 | 245 | return newRGBColor; 246 | } 247 | 248 | function ConvertToUIColor(swatch) { 249 | 250 | var newUIColor = []; 251 | newUIColor[0] = swatch.red / 255; 252 | newUIColor[1] = swatch.green / 255; 253 | newUIColor[2] = swatch.blue / 255; 254 | 255 | return newUIColor; 256 | } 257 | 258 | function inside(point, vs) { 259 | // ray-casting algorithm based on 260 | // https://wrf.ecse.rpi.edu/Research/Short_Notes/pnpoly.html/pnpoly.html 261 | 262 | var x = point[0], 263 | y = point[1]; 264 | 265 | var inside = false; 266 | for (var i = 0, j = vs.length - 1; i < vs.length; j = i++) { 267 | var xi = vs[i][0], 268 | yi = vs[i][1]; 269 | var xj = vs[j][0], 270 | yj = vs[j][1]; 271 | 272 | var intersect = ((yi > y) != (yj > y)) && 273 | (x < (xj - xi) * (y - yi) / (yj - yi) + xi); 274 | if (intersect) inside = !inside; 275 | } 276 | 277 | return inside; 278 | }; -------------------------------------------------------------------------------- /Batch-Correct-infgrf.jsx: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Code for Import https://scriptui.joonas.me — (Triple click to select): 4 | {"activeId":14,"items":{"item-0":{"id":0,"type":"Dialog","parentId":false,"style":{"enabled":true,"varName":"ChartEdit","windowType":"Dialog","creationProps":{"su1PanelCoordinates":false,"maximizeButton":false,"minimizeButton":false,"independent":false,"closeButton":true,"borderless":false,"resizeable":false},"text":"ChartEdit","preferredSize":[0,0],"margins":16,"orientation":"column","spacing":10,"alignChildren":["left","top"]}},"item-1":{"id":1,"type":"EditText","parentId":0,"style":{"enabled":true,"varName":"et","creationProps":{"noecho":false,"readonly":false,"multiline":true,"scrollable":true,"borderless":false,"enterKeySignalsOnChange":false},"softWrap":false,"text":"fdgd","justify":"left","preferredSize":[209,300],"alignment":null,"helpTip":null}},"item-3":{"id":3,"type":"RadioButton","parentId":14,"style":{"enabled":true,"varName":"BarChart","text":"Bar chart","preferredSize":[0,0],"alignment":null,"helpTip":null,"checked":true}},"item-4":{"id":4,"type":"RadioButton","parentId":14,"style":{"enabled":true,"varName":"LineWidth","text":"Line width","preferredSize":[0,0],"alignment":null,"helpTip":null,"checked":false}},"item-5":{"id":5,"type":"RadioButton","parentId":14,"style":{"enabled":true,"varName":"Area","text":"Area","preferredSize":[0,0],"alignment":null,"helpTip":null,"checked":false}},"item-6":{"id":6,"type":"Group","parentId":0,"style":{"enabled":true,"varName":null,"preferredSize":[0,0],"margins":0,"orientation":"row","spacing":10,"alignChildren":["left","center"],"alignment":null}},"item-8":{"id":8,"type":"RadioButton","parentId":15,"style":{"enabled":true,"varName":"Horizontal","text":"Top to bottom","preferredSize":[0,0],"alignment":null,"helpTip":null,"checked":true}},"item-9":{"id":9,"type":"RadioButton","parentId":15,"style":{"enabled":true,"varName":"Vertical","text":"Left to right","preferredSize":[0,0],"alignment":null,"helpTip":null,"checked":false}},"item-10":{"id":10,"type":"Checkbox","parentId":15,"style":{"enabled":true,"varName":"sortReverse","text":"Reverse order","preferredSize":[0,0],"alignment":null,"helpTip":null,"checked":false}},"item-11":{"id":11,"type":"Group","parentId":0,"style":{"enabled":true,"varName":null,"preferredSize":[200,0],"margins":0,"orientation":"row","spacing":15,"alignChildren":["center","center"],"alignment":null}},"item-12":{"id":12,"type":"Button","parentId":11,"style":{"enabled":true,"varName":"btn_ok","text":"OK","justify":"center","preferredSize":[80,0],"alignment":null,"helpTip":null}},"item-13":{"id":13,"type":"Button","parentId":11,"style":{"enabled":true,"varName":"btn_cancel","text":"Cancel","justify":"center","preferredSize":[80,0],"alignment":null,"helpTip":null}},"item-14":{"id":14,"type":"Panel","parentId":6,"style":{"enabled":true,"varName":"ChartType","creationProps":{"borderStyle":"etched","su1PanelCoordinates":false},"text":"Chart type","preferredSize":[0,0],"margins":[13,2,6,2],"orientation":"column","spacing":10,"alignChildren":["left","top"],"alignment":null}},"item-15":{"id":15,"type":"Panel","parentId":6,"style":{"enabled":true,"varName":"Sorting","creationProps":{"borderStyle":"etched","su1PanelCoordinates":false},"text":"Sort","preferredSize":[0,0],"margins":[13,2,6,2],"orientation":"column","spacing":10,"alignChildren":["left","top"],"alignment":null}}},"order":[0,1,6,14,3,4,5,15,8,9,10,11,12,13],"settings":{"importJSON":true,"indentSize":false,"cepExport":false,"includeCSSJS":true,"showDialog":true,"functionWrapper":false,"afterEffectsDockable":false,"itemReferenceList":"None"}} 5 | */ 6 | 7 | 8 | // - settings ------------- 9 | // return code alternative character(s) used while editting 10 | var return_code_alt = "@/"; 11 | 12 | // return code that used in regexp (escape the characters if it needs) 13 | var return_code_alt_for_rex = return_code_alt; 14 | 15 | // edittext size 16 | var edittext_width = 200; 17 | var edittext_height = 300; 18 | 19 | var erorr = null; 20 | 21 | // - settings end ------------- 22 | 23 | 24 | 25 | // CHARTEDIT 26 | // ========= 27 | var ChartEdit = new Window("dialog"); 28 | ChartEdit.text = "ChartEdit"; 29 | ChartEdit.orientation = "column"; 30 | ChartEdit.alignChildren = ["fill","top"]; 31 | ChartEdit.spacing = 10; 32 | ChartEdit.margins = 16; 33 | 34 | 35 | 36 | // GROUP1 37 | // ====== 38 | var group1 = ChartEdit.add("group", undefined, {name: "group1"}); 39 | group1.orientation = "row"; 40 | group1.alignChildren = ["left","top"]; 41 | group1.spacing = 10; 42 | group1.margins = 0; 43 | 44 | // CHARTTYPE 45 | // ========= 46 | var ChartType = group1.add("panel", undefined, undefined, {name: "ChartType"}); 47 | ChartType.text = "Chart type"; 48 | ChartType.orientation = "column"; 49 | ChartType.alignChildren = ["left","top"]; 50 | ChartType.spacing = 10; 51 | ChartType.margins = [2,13,2,6]; 52 | 53 | var BarChart = ChartType.add("radiobutton", undefined, undefined, {name: "BarChart"}); 54 | BarChart.text = "Bar chart"; 55 | BarChart.value = true; 56 | 57 | var LineWidth = ChartType.add("radiobutton", undefined, undefined, {name: "LineWidth"}); 58 | LineWidth.text = "Line width"; 59 | 60 | var Area = ChartType.add("radiobutton", undefined, undefined, {name: "Area"}); 61 | Area.text = "Area"; 62 | 63 | // SORTING 64 | // ======= 65 | var Sorting = group1.add("panel", undefined, undefined, {name: "Sorting"}); 66 | Sorting.text = "Sort"; 67 | Sorting.orientation = "column"; 68 | Sorting.alignChildren = ["left","top"]; 69 | Sorting.spacing = 10; 70 | Sorting.margins = [2,13,2,6]; 71 | 72 | var Horizontal = Sorting.add("radiobutton", undefined, undefined, {name: "Horizontal"}); 73 | Horizontal.text = "Horizontal"; 74 | 75 | var Vertical = Sorting.add("radiobutton", undefined, undefined, {name: "Vertical"}); 76 | Vertical.text = "Vertical"; 77 | 78 | 79 | 80 | 81 | function sortCheckboxes(__reverse) { 82 | tfs = tfsSort; 83 | PthItm = PthItmSort; 84 | sortTopToBottom(tfs); 85 | if (sortReverse.value) { 86 | tfs.reverse(); 87 | PthItm.reverse(); 88 | } 89 | getConts(); 90 | et.text = conts.join("\n"); 91 | ChartEdit.update(); 92 | } 93 | 94 | Horizontal.onClick = function() { 95 | sortTopToBottom(tfs); 96 | sortTopToBottom(PthItm); 97 | getConts(); 98 | et.text = conts.join("\n"); 99 | ChartEdit.update(); 100 | } 101 | 102 | Vertical.onClick = function() { 103 | sortLeftToRight(tfs); 104 | sortLeftToRight(PthItm); 105 | getConts(); 106 | et.text = conts.join("\n"); 107 | ChartEdit.update(); 108 | } 109 | 110 | 111 | 112 | // GROUP2 113 | // ====== 114 | var group2 = ChartEdit.add("group", undefined, {name: "group2"}); 115 | group2.orientation = "row"; 116 | group2.alignChildren = ["left","center"]; 117 | group2.spacing = 10; 118 | group2.margins = 0; 119 | group2.alignment = ["left","top"]; 120 | 121 | var MoveText = group2.add("checkbox", undefined, undefined, {name: "MoveText"}); 122 | MoveText.text = "Move text"; 123 | MoveText.value=true; 124 | 125 | 126 | LineWidth.onClick=function() { MoveText.enabled = false}; 127 | Area.onClick=function() { MoveText.enabled = false}; 128 | BarChart.onClick=function() { MoveText.enabled = true}; 129 | 130 | var sortReverse = group2.add("checkbox", undefined, undefined, {name: "sortReverse"}); 131 | sortReverse.text = "Reverse order"; 132 | 133 | 134 | ///sorting 135 | sortReverse.onClick = function() { 136 | tfs.reverse(); 137 | PthItm.reverse(); 138 | getConts(); 139 | et.text = conts.join("\n"); 140 | ChartEdit.update(); 141 | }; 142 | 143 | 144 | 145 | 146 | var et = ChartEdit.add('edittext {properties: {name: "et", multiline: true, scrollable: true}}'); 147 | et.text = ""; 148 | et.preferredSize.width = 209; 149 | et.preferredSize.height = 200; 150 | 151 | 152 | 153 | // GET TEXT 154 | 155 | var tfs = [], 156 | tfsSort = [], 157 | tfsOriginal = []; // textframes 158 | extractTextFramesAsVTextFrameItem(app.activeDocument.selection, tfs, tfsOriginal, tfsSort); 159 | 160 | if (tfs.length < 1) { 161 | erorr = "Please select textframes"; 162 | } 163 | 164 | var PthItm = [], 165 | PthItmSort = [], 166 | PthItmOriginal = []; // textframes 167 | extractPthItms(app.activeDocument.selection, PthItm, PthItmOriginal, PthItmSort); 168 | 169 | // sort 170 | sortTopToBottom(PthItm); 171 | sortTopToBottom(tfs); 172 | Horizontal.value = true; 173 | 174 | if (PthItm.length!=tfs.length){ 175 | erorr = "Please, select the same number of objects and captions. There should be no groups"; 176 | } else { 177 | if (tfs[0].leftPthItm[0].top){ 184 | sortLeftToRight(PthItm); 185 | sortLeftToRight(tfs); 186 | Vertical.value = true; 187 | MoveText.value=true; 188 | } 189 | } 190 | 191 | 192 | // get the contents of tfs 193 | var conts = [] 194 | 195 | function getConts() { 196 | conts = []; 197 | var rex_return_code = new RegExp("\r", "g"); 198 | for (var i = 0; i < tfs.length; i++) { 199 | conts.push(tfs[i].tf.contents.replace( 200 | rex_return_code, return_code_alt)); 201 | } 202 | } 203 | 204 | getConts(); 205 | 206 | 207 | et.text = conts.join("\n"); 208 | et.active = true; 209 | 210 | var find = '\\d+(?:[,.]\\d+)?(?: \\d+(?:[,.]\\d+)?)*'; 211 | var Numtest = et.text.match(find, 'g') ; 212 | if(Numtest == null || Numtest.length != tfs.length ){ 213 | erorr= "Please select marks and corresponding numbers"; 214 | } 215 | 216 | 217 | // GROUP3 218 | // ====== 219 | var group3 = ChartEdit.add("group", undefined, {name: "group2"}); 220 | group3.preferredSize.width = 200; 221 | group3.orientation = "row"; 222 | group3.alignChildren = ["center","center"]; 223 | group3.spacing = 15; 224 | group3.margins = 0; 225 | 226 | var btn_ok = group3.add("button", undefined, undefined, {name: "btn_ok"}); 227 | btn_ok.text = "OK"; 228 | btn_ok.preferredSize.width = 80; 229 | 230 | var btn_cancel = group3.add("button", undefined, undefined, {name: "btn_cancel"}); 231 | btn_cancel.text = "Cancel"; 232 | btn_cancel.preferredSize.width = 80; 233 | 234 | 235 | 236 | ///ACTION 237 | btn_ok.onClick = function() { 238 | var OldNumbers = []; 239 | var Numbers =[]; 240 | 241 | Numbers = et.text.split("\n"), new RegExp(return_code_alt_for_rex, "g") 242 | var Numtest2 = et.text.match(find, 'g'); 243 | if ( Numtest2 == null || Numtest2.length != Numbers.length || Numtest2.length != PthItm.length ){ 244 | ChartEdit.close(); 245 | alert ("Please, enter only numbers. There should be as many numbers as paths selected"); 246 | 247 | return; 248 | } 249 | 250 | 251 | for (a=0; a= et_texts.length) break; 364 | 365 | tfs[i].tf.contents = et_texts[i].replace(rex_return_code_alt, "\r"); 366 | } 367 | } 368 | 369 | // -------------------------------------------------- 370 | function extractPthItms(s, r, _r, __r) { 371 | // s is an array of pageitems ( ex. selection ) 372 | for (var i = 0; i < s.length; i++) { 373 | if (s[i].typename === "PathItem") { 374 | r.push(s[i]); 375 | _r.push(s[i]); 376 | __r.push(s[i]); 377 | } 378 | } 379 | } 380 | 381 | // -------------------------------------------------- 382 | function sortLeftToRight(tfs) { 383 | 384 | var rect = []; 385 | // reft, top, right, bottom 386 | getVTextFramesRect(tfs, rect); 387 | tfs.sort(function(a, b) { 388 | return a.left == b.left ? 389 | b.top - a.top : 390 | a.left - b.left 391 | }); 392 | 393 | } 394 | // -------------------------------------------------- 395 | function sortTopToBottom(tfs) { 396 | 397 | var rect = []; 398 | // reft, top, right, bottom 399 | getVTextFramesRect(tfs, rect); 400 | 401 | // top -> down || left -> right 402 | tfs.sort(function(a, b) { 403 | return a.top == b.top ? 404 | a.left - b.left : 405 | b.top - a.top 406 | }); 407 | 408 | } 409 | // -------------------------------------------------- 410 | function getVTextFramesRect(tfs, rect) { 411 | // get the rect that includes each top-left corner of tfs 412 | var top, left; 413 | 414 | for (var i = 0; i < tfs.length; i++) { 415 | top = tfs[i].top; 416 | left = tfs[i].left; 417 | 418 | if (i == 0) { 419 | // reft, top, right, bottom 420 | rect.push(left); 421 | rect.push(top); 422 | rect.push(left); 423 | rect.push(top); 424 | } else { 425 | rect[0] = Math.min(rect[0], left); 426 | rect[1] = Math.max(rect[1], top); 427 | rect[2] = Math.max(rect[2], left); 428 | rect[3] = Math.min(rect[3], top); 429 | } 430 | } 431 | } 432 | // -------------------------------------------------- 433 | function extractTextFramesAsVTextFrameItem(s, r, _r, __r) { 434 | // s is an array of pageitems ( ex. selection ) 435 | for (var i = 0; i < s.length; i++) { 436 | if (s[i].typename === "TextFrame") { 437 | r.push(new vTextFrameItem(s[i])); 438 | _r.push(new vTextFrameItem(s[i])); 439 | __r.push(new vTextFrameItem(s[i])); 440 | } else if (s[i].typename == "GroupItem") { 441 | extractTextFramesAsVTextFrameItem(s[i].pageItems, r, _r, __r); 442 | } 443 | } 444 | } -------------------------------------------------------------------------------- /Replace-Objects-1a.jsx: -------------------------------------------------------------------------------- 1 | /* Program version: Adobe Illustrator CC+ */ 2 | var scriptName = 'ReplaceItems-2', 3 | settingFile = { 4 | name: scriptName + '__setting.json', 5 | folder: Folder.myDocuments + '/Scripts/' 6 | }; 7 | 8 | // DIALOG 9 | var dialog = new Window("dialog"); 10 | dialog.text = "Replace objects"; 11 | dialog.orientation = "column"; 12 | dialog.alignChildren = ["center", "top"]; 13 | dialog.spacing = 10; 14 | 15 | // MAINGROUP 16 | var MainGroup = dialog.add("group"); 17 | MainGroup.orientation = "row"; 18 | MainGroup.alignChildren = ["left", "fill"]; 19 | MainGroup.spacing = 10; 20 | MainGroup.margins = 0; 21 | 22 | // FIRSTCOLUMN 23 | var FirstColumn = MainGroup.add("panel"); 24 | FirstColumn.text = ""; 25 | FirstColumn.preferredSize.width = 175; 26 | FirstColumn.orientation = "column"; 27 | FirstColumn.alignChildren = ["left", "top"]; 28 | FirstColumn.spacing = 8; 29 | FirstColumn.margins = [10, 5, 0, 10]; 30 | 31 | 32 | var saveOriginalCheckbox = FirstColumn.add("checkbox"); 33 | saveOriginalCheckbox.text = "Save original"; 34 | //saveOriginalCheckbox.value = true; 35 | 36 | var copyColorsCheckbox = FirstColumn.add("checkbox"); 37 | copyColorsCheckbox.text = "Copy fill color (for simple objects)"; 38 | 39 | var ignoreStroke = FirstColumn.add("checkbox"); 40 | ignoreStroke.text = "Ignore stroke"; 41 | //ignoreStroke.value = true; 42 | try { 43 | if ( selection[0].typename=="GroupItem"){ 44 | //ignoreStroke.enabled = false; 45 | ignoreStroke.text = "Ignore stroke of the replaced objects"; 46 | } 47 | }catch (e){ 48 | alert ("Plese, select some objects"); 49 | } 50 | 51 | var TopObj= FirstColumn.add("checkbox"); 52 | TopObj.text = "Replace with the top object"; 53 | 54 | var ResizeStroke= FirstColumn.add("checkbox"); 55 | ResizeStroke.text = "Resize stroke"; 56 | 57 | 58 | // SECONDCOLUMN 59 | var SecondColumn = MainGroup.add("panel"); 60 | SecondColumn.text = "Size"; 61 | SecondColumn.orientation = "column"; 62 | SecondColumn.alignChildren = ["left", "top"]; 63 | SecondColumn.spacing = 8; 64 | SecondColumn.margins = [10, 15, 10, 10]; 65 | 66 | var NochangeCheckbox = SecondColumn.add("radiobutton"); 67 | NochangeCheckbox.text = "No changes"; 68 | //NochangeCheckbox.value = true; 69 | 70 | var fitInWidthCheckbox = SecondColumn.add("radiobutton"); 71 | fitInWidthCheckbox.text = "Fit width"; 72 | //fitInWidthCheckbox.value = false; 73 | 74 | var fitInHeightCheckbox = SecondColumn.add("radiobutton"); 75 | fitInHeightCheckbox.text = "Fit height"; 76 | //fitInHeightCheckbox.value = false; 77 | 78 | var copySize= SecondColumn.add("radiobutton"); 79 | copySize.text = "Copy"; 80 | 81 | 82 | // THIRDCOLUMN 83 | var ThirdColumn = MainGroup.add("panel"); 84 | ThirdColumn.text = "Alignment"; 85 | ThirdColumn.preferredSize.width = 100; 86 | ThirdColumn.orientation = "row"; 87 | ThirdColumn.alignChildren = ["left", "top"]; 88 | ThirdColumn.spacing = 22; 89 | ThirdColumn.margins = [10, 17, 0, 11]; 90 | ThirdColumn.alignment = ["left", "fill"]; 91 | 92 | // GROUP1 93 | var group1 = ThirdColumn.add("group"); 94 | group1.orientation = "column"; 95 | group1.alignChildren = ["left", "center"]; 96 | group1.spacing = 19; 97 | group1.margins = 0; 98 | 99 | var AlignTopLeft = group1.add("radiobutton"); 100 | var AlignCenterLeft = group1.add("radiobutton"); 101 | var AlignBottomLeft = group1.add("radiobutton"); 102 | 103 | // GROUP2 104 | var group2 = ThirdColumn.add("group"); 105 | group2.orientation = "column"; 106 | group2.alignChildren = ["left", "center"]; 107 | group2.spacing = 19; 108 | group2.margins = 0; 109 | 110 | var AlignTopCenter = group2.add("radiobutton"); 111 | var AlignCenterCenter = group2.add("radiobutton"); 112 | var AlignBottomCenter = group2.add("radiobutton"); 113 | 114 | // GROUP3 115 | var group3 = ThirdColumn.add("group"); 116 | group3.orientation = "column"; 117 | group3.alignChildren = ["left", "center"]; 118 | group3.spacing = 19; 119 | group3.margins = 0; 120 | 121 | var AlignTopRight = group3.add("radiobutton"); 122 | var AlignCenterRight = group3.add("radiobutton"); 123 | var AlignBottomRight = group3.add("radiobutton"); 124 | 125 | AlignCenterCenter.value = true; 126 | var myRadioButtons = []; 127 | 128 | AlignTopLeft.onClick = toggleRadioButtons; 129 | myRadioButtons.push(AlignTopLeft); 130 | AlignCenterLeft.onClick = toggleRadioButtons; 131 | myRadioButtons.push(AlignCenterLeft); 132 | AlignBottomLeft.onClick = toggleRadioButtons; 133 | myRadioButtons.push(AlignBottomLeft); 134 | AlignTopCenter.onClick = toggleRadioButtons; 135 | myRadioButtons.push(AlignTopCenter); 136 | AlignCenterCenter.onClick = toggleRadioButtons; 137 | myRadioButtons.push(AlignCenterCenter); 138 | AlignBottomCenter.onClick = toggleRadioButtons; 139 | myRadioButtons.push(AlignBottomCenter); 140 | AlignTopRight.onClick = toggleRadioButtons; 141 | myRadioButtons.push(AlignTopRight); 142 | AlignCenterRight.onClick = toggleRadioButtons; 143 | myRadioButtons.push(AlignCenterRight); 144 | AlignBottomRight.onClick = toggleRadioButtons; 145 | myRadioButtons.push(AlignBottomRight); 146 | 147 | function toggleRadioButtons() { 148 | for (var i = 0, il = myRadioButtons.length; i < il; i ++) { 149 | if (myRadioButtons[i] !== this) { 150 | myRadioButtons[i].value = false; 151 | } 152 | } 153 | this.value = true; 154 | } 155 | 156 | // FINALBUTTONS 157 | //var divider2 = dialog.add("panel"); 158 | //divider2.alignment = "fill"; 159 | 160 | var FinalButtons = dialog.add("group"); 161 | FinalButtons.orientation = "row"; 162 | FinalButtons.alignChildren = ["left", "center"]; 163 | FinalButtons.spacing = 10; 164 | FinalButtons.margins = 0; 165 | 166 | var cancel = FinalButtons.add("button", undefined, undefined, {name: "Cancel"}); 167 | cancel.text = "Cancel"; 168 | cancel.justify = "center"; 169 | cancel.onClick = function() { 170 | dialog.close(); 171 | } 172 | 173 | var ok = FinalButtons.add("button", undefined, undefined, {name: "Ok"}); 174 | ok.text = "Ok"; 175 | ok.justify = "center"; 176 | ok.onClick = startAction; 177 | ok.active = true; 178 | 179 | var progressBar = dialog.add('progressbar', [0, 0, 110, 5]), 180 | progressBarCounter = 100; 181 | progressBar.value = 0; 182 | progressBar.minvalue = 0; 183 | progressBar.maxvalue = progressBarCounter; 184 | 185 | 186 | /////// 187 | //FUNCTIONS// 188 | function setFillColor(items, color) { 189 | if (color) { 190 | var i = items.length; 191 | if (i) 192 | while (i--) { 193 | if (items[i].typename === 'GroupItem') { 194 | setFillColor(items[i].pageItems, color); 195 | } 196 | else if (items[i].typename === 'CompoundPathItem') { 197 | if (items[i].pathItems.length) items[i].pathItems[0].fillColor = color; 198 | } 199 | else if (items[i].typename === 'PathItem') { 200 | items[i].fillColor = color; 201 | } 202 | } 203 | } 204 | } 205 | 206 | function getFillColor(items) { 207 | var i = items.length, 208 | gc; 209 | if (i) 210 | while (i--) { 211 | if (items[i].typename === 'GroupItem' && (gc = getFillColor(items[i].pageItems))) return gc; 212 | else if (items[i].typename === 'CompoundPathItem' && items[i].pathItems.length) return items[i].pathItems[0].fillColor; 213 | else if (items[i].typename === 'PathItem') return items[i].fillColor; 214 | } 215 | } 216 | 217 | 218 | ///////////////////////// 219 | 220 | function startAction() { 221 | if (selection.length) { 222 | items = selection, 223 | i = items.length; 224 | progressBarCounter = progressBar.maxvalue / i; 225 | var nodes = selection[0]; 226 | 227 | if (TopObj.value == false) { 228 | selection = null; 229 | app.paste(); 230 | nodes = selection[0]; 231 | selection = null; 232 | } 233 | 234 | 235 | 236 | //// 237 | while (i--) { 238 | var err = null; 239 | var item = items[i]; 240 | var node = nodes.duplicate(item, ElementPlacement.PLACEBEFORE); 241 | 242 | if (node.typename != "GroupItem"){ 243 | var nd_s =ignoreStroke.value? 0:(node.visibleBounds[1]-node.geometricBounds[1])*2; 244 | } else { 245 | var nd_Bounds = FindBounds(node); 246 | var nd_height = nd_Bounds[1] - nd_Bounds[3]; 247 | var nd_width = nd_Bounds[2] - nd_Bounds[0]; 248 | // var nd_height = nd_Bounds[5] - nd_Bounds[7]; 249 | //var nd_width = nd_Bounds[6] - nd_Bounds[4]; 250 | } 251 | 252 | ////if ignoreStroke true calculate parameters of geometric bounds 253 | if (ignoreStroke.value == true){ 254 | if (item.typename != "GroupItem") { 255 | var it_top = item.geometricBounds[1]; 256 | var it_left = item.geometricBounds[0]; 257 | var it_width = item.geometricBounds[2] - item.geometricBounds[0]; 258 | var it_height = item.geometricBounds[1] - item.geometricBounds[3]; 259 | 260 | } else if (item.typename == "GroupItem") { 261 | var it_Bounds = FindBounds(item); 262 | var it_top = it_Bounds[1]; 263 | var it_left = it_Bounds[0]; 264 | var it_width = it_Bounds[2] - it_Bounds[0]; 265 | var it_height = it_Bounds[1] - it_Bounds[3]; 266 | } 267 | 268 | ////if ignoreStroke false calculate parameters of visible bounds 269 | } else if (ignoreStroke.value == false) { 270 | if (item.typename != "GroupItem") { 271 | var it_top = item.visibleBounds[1]; 272 | var it_left = item.visibleBounds[0]; 273 | var it_width = item.visibleBounds[2] - item.visibleBounds[0]; 274 | var it_height = item.visibleBounds[1] - item.visibleBounds[3]; 275 | 276 | }else if (item.typename == "GroupItem"){ 277 | var it_Bounds = FindBounds(item); 278 | var it_top = it_Bounds[5]; 279 | var it_left = it_Bounds[4]; 280 | var it_width = it_Bounds[6] - it_Bounds[4]; 281 | var it_height = it_Bounds[5] - it_Bounds[7]; 282 | } 283 | } 284 | 285 | 286 | 287 | ////////////////////////// 288 | ///change size/// 289 | 290 | var newStroke, newHeight, newWidth; 291 | newStroke = newHeight = newWidth = 100; 292 | 293 | 294 | if (fitInHeightCheckbox.value) { 295 | 296 | //if node is vertical line 297 | if (node.width == 0) { 298 | newStroke = newHeight = it_height * 100 / node.height; 299 | newWidth = 100; 300 | 301 | //if node is horisontal line 302 | } else if (node.height == 0) { 303 | newStroke = it_height * 100 / node.strokeWidth; 304 | newHeight = newWidth = 100; 305 | 306 | //if node isnot a group 307 | } else if (it_height != 0) { 308 | if (node.typename != "GroupItem") { 309 | newWidth = newHeight = newStroke = ResizeStroke.value 310 | ? (it_height / (node.height + nd_s)) * 100 311 | : ((it_height - nd_s) / node.height) * 100; 312 | 313 | //if node is a group 314 | } else if (node.typename == "GroupItem") { 315 | newWidth = newHeight = newStroke = it_height / nd_height * 100; 316 | } 317 | } else { 318 | err = "There is an object with zero height"; 319 | } 320 | 321 | 322 | } else if (fitInWidthCheckbox.value) { 323 | 324 | //if node is vertical line 325 | if (node.width == 0) { 326 | newStroke = it_width * 100 / node.strokeWidth; 327 | newHeight = 100; 328 | 329 | //if node is horisontal line 330 | } else if (node.height == 0) { 331 | newStroke = newWidth = it_width * 100 / node.width; 332 | newHeight = 100; 333 | 334 | //if node is not a group 335 | } else if (it_width != 0) { 336 | if (node.typename != "GroupItem" & node.height != 0 & node.width != 0) { 337 | newWidth = newHeight = newStroke = ResizeStroke.value 338 | ? (it_width / (node.width + nd_s)) * 100 339 | : ((it_width - nd_s) / node.width) * 100; 340 | 341 | //if node is a group 342 | } else if (node.typename == "GroupItem") { 343 | newWidth = newHeight = newStroke = it_width / nd_width * 100; 344 | } 345 | } else { 346 | err = "There is an object with zero width"; 347 | } 348 | 349 | 350 | } else if (copySize.value) { 351 | 352 | //if node is vertical line 353 | if (node.width == 0) { 354 | newWidth = 100; 355 | newHeight = it_height * 100 / node.height; 356 | newStroke = it_width * 100 / node.strokeWidth; 357 | 358 | //if node is horisontal line 359 | } else if (node.height == 0) { 360 | newWidth = it_width * 100 / node.width; 361 | newHeight = 100; 362 | newStroke = it_height * 100 / node.strokeWidth; 363 | 364 | } else if (it_width != 0 | it_height != 0) { 365 | //if node is not a group 366 | if (node.typename != "GroupItem") { 367 | newWidth = ((it_width - nd_s) / node.width) * 100; 368 | newHeight = ((it_height - nd_s) / node.height) * 100; 369 | newStroke = 100; 370 | 371 | //if node is a group 372 | } else if (node.typename == "GroupItem") { 373 | newHeight = it_height / nd_height * 100; 374 | newWidth = it_width / nd_width * 100; 375 | newStroke = undefined; /// ? 376 | } 377 | } else { 378 | err = "There is an object with zero width or height"; 379 | } 380 | } 381 | 382 | 383 | node.resize( 384 | scaleX=newWidth, 385 | scaleY= newHeight, 386 | changePositions= undefined, 387 | changeFillPatterns= undefined, 388 | changeFillGradients= undefined, 389 | changeStrokePattern= undefined, 390 | changeLineWidths = ResizeStroke.value ? newStroke : 100); 391 | 392 | // end changing size 393 | 394 | 395 | /// calculate node parametres 396 | if (node.typename == "GroupItem") { 397 | var nd_Bounds = FindBounds(node); 398 | var nd_top = nd_Bounds[1]; 399 | var nd_left = nd_Bounds[0]; 400 | var nd_width = nd_Bounds[2] - nd_Bounds[0]; 401 | var nd_height = nd_Bounds[1] - nd_Bounds[3]; 402 | var nd_str = 0; 403 | 404 | } else if (node.typename != "GroupItem") { 405 | 406 | if (ignoreStroke.value == true) { 407 | var nd_str = node.visibleBounds[1] - node.geometricBounds[1]; 408 | var nd_width = node.geometricBounds[2] - node.geometricBounds[0]; 409 | var nd_height = node.geometricBounds[1] - node.geometricBounds[3]; 410 | var nd_top = node.geometricBounds[1]; 411 | var nd_left = node.geometricBounds[0]; 412 | 413 | if (node.height == 0 || node.width == 0) { 414 | nd_str = 0; 415 | nd_height = node.visibleBounds[1] - node.visibleBounds[3]; 416 | nd_width = node.visibleBounds[2] - node.visibleBounds[0]; 417 | } 418 | 419 | } else if (ignoreStroke.value == false) { 420 | var nd_str = 0; 421 | var nd_width = node.visibleBounds[2] - node.visibleBounds[0]; 422 | var nd_height = node.visibleBounds[1] - node.visibleBounds[3]; 423 | var nd_top = node.visibleBounds[1]; 424 | var nd_left = node.visibleBounds[0]; 425 | } 426 | } 427 | 428 | 429 | ////////////////////////// 430 | ///change position/// 431 | 432 | 433 | //if node is clipping mask 434 | if (node.typename == "GroupItem"){ 435 | 436 | ///TOP 437 | if (AlignTopLeft.value | AlignTopRight.value | AlignTopCenter.value) { 438 | node.top = node.top - (nd_top - it_top) + nd_str; 439 | } 440 | if (AlignCenterLeft.value | AlignCenterRight.value | AlignCenterCenter.value) { 441 | node.top = node.top - ((nd_top - nd_height / 2) - (it_top - it_height / 2)) + nd_str; 442 | } 443 | if (AlignBottomLeft.value | AlignBottomRight.value | AlignBottomCenter.value) { 444 | node.top = node.top - ((nd_top - nd_height) - (it_top - it_height)) + nd_str; 445 | } 446 | 447 | ///LEFT 448 | if (AlignTopLeft.value | AlignCenterLeft.value | AlignBottomLeft.value) { 449 | node.left = node.left - (nd_left - it_left) - nd_str; 450 | } 451 | if (AlignTopCenter.value | AlignCenterCenter.value | AlignBottomCenter.value) { 452 | node.left = node.left + ((it_left + it_width / 2) - (nd_left + nd_width / 2)) - nd_str; 453 | } 454 | if (AlignTopRight.value | AlignCenterRight.value | AlignBottomRight.value) { 455 | node.left = node.left + ((it_left + it_width) - (nd_left + nd_width)) - nd_str; 456 | } 457 | 458 | /// 459 | } else { 460 | 461 | ///TOP 462 | if (AlignTopLeft.value | AlignTopRight.value | AlignTopCenter.value) { 463 | node.top = it_top + nd_str; 464 | } 465 | if (AlignCenterLeft.value | AlignCenterRight.value | AlignCenterCenter.value) { 466 | node.top = it_top + (nd_height - it_height) / 2 + nd_str; 467 | } 468 | if (AlignBottomLeft.value | AlignBottomRight.value | AlignBottomCenter.value) { 469 | node.top = it_top + nd_height - it_height + nd_str; 470 | } 471 | 472 | ///LEFT 473 | if (AlignTopLeft.value | AlignCenterLeft.value | AlignBottomLeft.value) { 474 | node.left = it_left - nd_str; 475 | } 476 | if (AlignTopCenter.value | AlignCenterCenter.value | AlignBottomCenter.value) { 477 | node.left = it_left - (nd_width - it_width) / 2 - nd_str; 478 | } 479 | if (AlignTopRight.value | AlignCenterRight.value | AlignBottomRight.value) { 480 | node.left = it_left - (nd_width - it_width) - nd_str; 481 | } 482 | } 483 | 484 | 485 | 486 | ///////////////////////////// 487 | 488 | if (copyColorsCheckbox.value) { 489 | try { 490 | setFillColor([node], getFillColor([item])); 491 | } catch (e) { 492 | alert(e + '\n' + e.line) 493 | } 494 | } 495 | 496 | 497 | if (err != null) { 498 | node.remove(); 499 | } 500 | 501 | 502 | if (!saveOriginalCheckbox.value) { 503 | if (item.clipping == true) { 504 | item = item.parent; 505 | } 506 | item.remove(); 507 | } 508 | 509 | progressBar.value += progressBarCounter; 510 | dialog.update(); 511 | 512 | } //end while 513 | 514 | 515 | 516 | if (saveOriginalCheckbox.value == true & TopObj.value == true) { 517 | node.remove(); 518 | } 519 | 520 | if (TopObj.value == false) { 521 | nodes.remove(); 522 | } 523 | 524 | } 525 | 526 | dialog.close(); 527 | 528 | if (err!=null) alert (err); 529 | 530 | } // end StartAction 531 | 532 | 533 | 534 | /////////////////////// 535 | /* //////////////////////////////Get object size-support mask function/////////////////////////////////// */ 536 | function FindBounds(obj) { 537 | var Bounds = new Array(); 538 | GET_Bounds(obj); 539 | var v_left = new Array(); 540 | var g_left = new Array(); 541 | var v_top = new Array(); 542 | var g_top = new Array(); 543 | var v_right = new Array(); 544 | var g_right = new Array(); 545 | var v_bottom = new Array(); 546 | var g_bottom = new Array(); 547 | for (var i = 0; i < Bounds.length; i += 1) { 548 | g_left[i] = Bounds[i].geometricBounds[0]; 549 | v_left[i] = Bounds[i].visibleBounds[0]; 550 | g_top[i] = Bounds[i].geometricBounds[1]; 551 | v_top[i] = Bounds[i].visibleBounds[1]; 552 | g_right[i] = Bounds[i].geometricBounds[2]; 553 | v_right[i] = Bounds[i].visibleBounds[2]; 554 | g_bottom[i] = Bounds[i].geometricBounds[3]; 555 | v_bottom[i] = Bounds[i].visibleBounds[3]; 556 | } 557 | var v_L = MIN_IN_ARRAY(v_left); 558 | var g_L = MIN_IN_ARRAY(g_left); 559 | var v_T = MAX_IN_ARRAY(v_top); 560 | var g_T = MAX_IN_ARRAY(g_top); 561 | var v_R = MAX_IN_ARRAY(v_right); 562 | var g_R = MAX_IN_ARRAY(g_right); 563 | var v_B = MIN_IN_ARRAY(v_bottom); 564 | var g_B = MIN_IN_ARRAY(g_bottom); 565 | return [g_L, g_T, g_R, g_B, v_L, v_T, v_R, v_B]; 566 | 567 | function GET_Bounds(obj) { 568 | if (IS_CLIP(obj)) { 569 | Bounds.push(obj.pageItems[0]); 570 | return; 571 | } 572 | if (obj.constructor.name == "GroupItem") { 573 | try { 574 | var N_sub_obj = obj.pageItems.length; 575 | for (var i = 0; i < N_sub_obj; i += 1) { 576 | GET_Bounds(obj.pageItems[i]); 577 | } 578 | } catch (error) {} 579 | return; 580 | } 581 | Bounds.push(obj); 582 | return; 583 | } 584 | } 585 | //////////////// 586 | function IS_CLIP(obj) { 587 | try { 588 | if (obj.constructor.name == "GroupItem") { 589 | if (obj.clipped) { 590 | return true; 591 | } 592 | } 593 | } catch(error) { 594 | 595 | } 596 | return false; 597 | } 598 | 599 | function MAX_IN_ARRAY(the_array) { 600 | var MAX = the_array[0]; 601 | for (var i = 0; i < the_array.length; i += 1) { 602 | if (the_array[i] > MAX) { 603 | MAX = the_array[i] 604 | } 605 | } 606 | return MAX; 607 | } 608 | 609 | function MIN_IN_ARRAY(the_array) { 610 | var MIN = the_array[0]; 611 | for (var i = 0; i < the_array.length; i += 1) { 612 | if (the_array[i] < MIN) { 613 | MIN = the_array[i] 614 | } 615 | } 616 | return MIN; 617 | } 618 | 619 | 620 | ////////////////////// 621 | function saveSettings() { 622 | var $file = new File(settingFile.folder + settingFile.name), 623 | data = [ 624 | 625 | saveOriginalCheckbox.value, 626 | copyColorsCheckbox.value, 627 | ignoreStroke.value, 628 | NochangeCheckbox.value, 629 | fitInWidthCheckbox.value, 630 | fitInHeightCheckbox.value, 631 | copySize.value, 632 | TopObj.value, 633 | ResizeStroke.value 634 | 635 | ].toString(); 636 | 637 | $file.open('w'); 638 | $file.write(data); 639 | $file.close(); 640 | } 641 | 642 | function loadSettings() { 643 | var $file = File(settingFile.folder + settingFile.name); 644 | if ($file.exists) { 645 | try { 646 | $file.open('r'); 647 | var data = $file.read().split('\n'), 648 | $main = data[0].split(','); 649 | 650 | 651 | saveOriginalCheckbox.value = ($main[0] === 'true'); 652 | copyColorsCheckbox.value = ($main[1] === 'true'); 653 | ignoreStroke.value = ($main[2] === 'true'); 654 | NochangeCheckbox.value = ($main[3] === 'true'); 655 | fitInWidthCheckbox.value = ($main[4] === 'true'); 656 | fitInHeightCheckbox.value = ($main[5] === 'true'); 657 | copySize.value = ($main[6] === 'true'); 658 | TopObj.value= ($main[7] === 'true'); 659 | ResizeStroke.value= ($main[8] === 'true'); 660 | 661 | } 662 | catch (e) {} 663 | $file.close(); 664 | } 665 | } 666 | 667 | 668 | dialog.onClose = function() { 669 | saveSettings(); 670 | return true; 671 | } 672 | 673 | function checkSettingFolder() { 674 | var $folder = new Folder(settingFile.folder); 675 | if (!$folder.exists) $folder.create(); 676 | } 677 | 678 | checkSettingFolder(); 679 | loadSettings(); 680 | dialog.center(); 681 | dialog.show(); 682 | 683 | 684 | --------------------------------------------------------------------------------