I am pulling 2 arrays and having them be reformatted and spit out next to the artboard. I can't seem to get the first column of names to sort. Then once they are sorted I need the second column to sort with the first column. Here is my script.... #target illustrator-22 var doc = app.activeDocument; var allLayers = doc.layers; var layerRename = "Grid Location"; var triggerAlert = 0; for (var i = 0; i < allLayers.length; i++) { if (allLayers.name == "42 Pg Grid Location" || allLayers.name == "36 Pg Grid Location" || allLayers.name == "30 Pg Grid Location" || allLayers.name == "24 Pg Grid Location" || allLayers.name == "20 Pg Grid Location" || allLayers.name == "16 Pg Grid Location" || allLayers.name == "12 Pg Grid Location" || allLayers.name == "8 Pg Grid Location" || allLayers.name == "4 Pg Grid Location") { allLayers.name = layerRename; triggerAlert++; } else if (allLayers.name == layerRename) { triggerAlert++; } } if (triggerAlert == 1) { function findGrid() { var d = activeDocument, ps = d.layers['Grid Location'].pathItems, l = ps.length, o = 'ABCDEFGHIJKLMNOPQRST...', W, H, rows = columns = 1, origin = d.rulerOrigin, /*newOrigin = new Array(2),*/ newOrigin = new Array(0, 0), t, b, center, gx, gy, i = 0; for (; i < l; i++) { if (ps.width == 0) { columns++; !newOrigin[1] && newOrigin[1] = origin[1] + ps.geometricBounds[3]; !H && H = ps.height; } if (ps.height == 0) { rows++; !newOrigin[0] && newOrigin[0] = origin[0] + ps.geometricBounds[2]; !W && W = ps.width; } } d.rulerOrigin = newOrigin; W = W / columns; H = H / rows; t = app.selection ; b = t.geometricBounds; center = [b[0] + (b[2] - b[0]) / 2, b[1] + (b[3] - b[1]) / 2]; gx = Math.abs(center[0]) / W; gy = Math.abs(center[1]) / H; d.rulerOrigin = origin; xCoor = -50; yCoor = 0; createGridText = d.textFrames.add(); createGridText.position = [xCoor, yCoor = (inc -= 20)]; createGridText.contents = '' + o[Math.ceil(gy - 1)] + "-" + Math.ceil(gx); } inc = 0; incTwo = 0; d = activeDocument; for (var z = 0; z < selection.length; z++) { xC = -350; yC = 0; createComponentText = d.textFrames.add(); createComponentText.position = [xC, yC = (incTwo -= 20)]; createComponentText.contents = selection .contents; findGrid(); } var doc = app.activeDocument var allText = doc.textFrames; formatCompTable(); removeLamps(); removeUnderscores(); /* CODE TO FORMAT SWITCH, RELAY, SOLENOID, SENSOR, GROUND, ETC. */ function formatCompTable() { var aCon; for (var i = 0; i < allText.length; i++) { //alert(allText.layer); //if (allText.layer == "[Layer Hypertext]"){ aCon = allText.contents; if (aCon.match(/_SWITCH|SWITCH_|SWITCH/) != null) { aCon = aCon.replace(/_SWITCH|SWITCH_|SWITCH/, ""); aCon = "SWITCH - " + aCon; allText.contents = aCon; } else if (aCon.match(/_SW(?!\w)|SW_/) != null) { aCon = aCon.replace(/_SW|SW_/, ""); aCon = "SWITCH - " + aCon; allText.contents = aCon; } else if (aCon.match(/_RLY|RLY_/) != null) { aCon = aCon.replace(/_RLY|RLY_/, ""); aCon = "RELAY - " + aCon; allText.contents = aCon; } else if (aCon.match(/RELAY/) != null) { aCon = aCon.replace(/RELAY/, ""); aCon = "RELAY - " + aCon; allText.contents = aCon; } else if (aCon.match(/_FUSE|FUSE_/) != null) { aCon = aCon.replace(/_FUSE|FUSE_/, ""); aCon = "FUSE - " + aCon; allText.contents = aCon; } else if (aCon.match(/_SOL(?!\w)|SOL_|SOL(?!\w)/) != null) { aCon = aCon.replace(/_SOL|SOL_|SOL/, ""); aCon = "SOLENOID - " + aCon; allText.contents = aCon; } else if (aCon.match(/_SNSR|SNSR_/) != null) { aCon = aCon.replace(/_SNSR|SNSR_/, ""); aCon = "SENSOR - " + aCon; allText.contents = aCon; } else if (aCon.match(/_SENSOR|SENSOR_/) != null) { aCon = aCon.replace(/_SENSOR|SENSOR_/, ""); aCon = "SENSOR - " + aCon; allText.contents = aCon; } else if (aCon.match(/GND($^)/) != null) { aCon = aCon.replace(/GND/, ""); aCon = "GROUND - " + aCon; allText.contents = aCon; } else if (aCon.match(/_GROUND|GROUND_/) != null) { aCon = aCon.replace(/_GROUND|GROUND_/, ""); aCon = "GROUND - " + aCon; allText.contents = aCon; } else if (aCon.match(/GND/) != null) { aCon = aCon.replace(/GND/, ""); aCon = "GROUND - " + aCon; allText.contents = aCon; } else if (aCon.match(/_ALARM|ALARM_/) != null) { aCon = aCon.replace(/_ALARM|ALARM_/, ""); aCon = "ALARM - " + aCon; allText.contents = aCon; } /*else if (aCon.match(/_ECM|ECM_/) != null) { aCon = aCon.replace(/_ECM|ECM_/, ""); aCon = "CONTROL - " + aCon; allText.contents = aCon; }*/ else if (aCon.match(/_CONTROL|CONTROL_/) != null) { aCon = aCon.replace(/_CONTROL|CONTROL_/, ""); aCon = "CONTROL - " + aCon; allText.contents = aCon; } else if (aCon.match(/CTRL/) != null) { aCon = aCon.replace(/CTRL/, ""); aCon = "CONTROL - " + aCon; allText.contents = aCon; } else if (aCon.match(/RESISTOR/) != null) { aCon = aCon.replace(/RESISTOR/, ""); aCon = "RESISTOR - " + aCon; allText.contents = aCon; } else if (aCon.match(/_CAN|CAN_/) != null) { aCon = aCon.replace(/_CAN|CAN_/, ""); aCon = "RESISTOR - CAN " + aCon; allText.contents = aCon; } //else if (aCon.match(/RES(?=\s)|RES_/) != null) { else if (aCon.match(/_RES|RES_/) != null) { aCon = aCon.replace(/_RES|RES_/, ""); aCon = "RESISTOR - " + aCon; allText.contents = aCon; } //else if (aCon.match(/MOTOR|MOT(?=\s)|MOT_/) != null) { else if (aCon.match(/_MOTOR|MOTOR_/) != null) { aCon = aCon.replace(/_MOTOR|MOTOR_/, ""); aCon = "MOTOR - " + aCon; allText.contents = aCon; } } } } else { alert("Couldn't find the proper Grid Location layer format. \nMake sure the layer with your grid locations is labeled...\nGrid Location"); } /* CODE TO FORMAT LAMPS */ function removeLamps() { var aCon; for (var i = 0; i < allText.length; i++) { aCon = allText.contents; if (aCon.match(/_LAMP|LAMP_/) != null) { aCon = aCon.replace(/_LAMP|LAMP_/, ""); aCon = "XXXX LAMPS - " + aCon; allText.contents = aCon; } else if (aCon.match(/_LTS|LTS_/) != null) { aCon = aCon.replace(/_LTS|LTS_/, ""); aCon = "XXXX LAMPS - " + aCon; allText.contents = aCon; } } } /* CODE TO REMOVE UNDERSCORES */ function removeUnderscores() { var searchString = /_/g; var replaceString = " "; for (var i = 0; i < allText.length; i++) { var thisTextFrame = allText; var newString = thisTextFrame.contents.replace(searchString, replaceString); if (newString != thisTextFrame.contents) { thisTextFrame.contents = newString; } } } var theContents; for (i = 0; i < allText.length; i++) { theContents = allText.contents; theContents = myTrim(theContents); allText.contents = theContents; } removeDoubleSpaces(); function myTrim(x) { return x.replace(/^\s+|\s+$/gm, ''); } function removeDoubleSpaces() { var searchString = / /g; var replaceString = " "; for (var i = 0; i < allText.length; i++) { var thisTextFrame = allText; var newString = thisTextFrame.contents.replace(searchString, replaceString); if (newString != thisTextFrame.contents) { thisTextFrame.contents = newString; } } } function removeDoubleDashes() { var searchString = /--/g; var replaceString = "-"; for (var i = 0; i < allText.length; i++) { var thisTextFrame = allText; var newString = thisTextFrame.contents.replace(searchString, replaceString); if (newString != thisTextFrame.contents) { thisTextFrame.contents = newString; } } } removeDoubleDashes(); alert("Your component table has been successfully created!"); Here is a test file.... Test File.ai - Google Drive A couple bonus items I would love to do.... no selection needed. Anything that is on the Hypertext layer is what would get used for column 1. Would also love to spit out a .csv file to import into Excel. This may be too much to ask at one time. If so.... I apologize. Any help would be appreciated though!
... View more