Open this file...
Document.ai - Google Drivehttps://drive.google.com/open?id=0B4ebfmBRxh3ATXBMbTUySmtpVWs
Then open this file so it is the active document...
I am running a script on the table I have pasted in from an Excel document. I am storing all of the names in an array.
Then it closes the table document and then searches document for matches.
The problem I am running into is that the table document is all a single line text frame and the document has text frames with carriage returns in them.
Here is my current code (which includes some clean up functions for odd spaces and such)....
#target illustrator var doc = app.activeDocument; var allText = doc.textFrames; var componentName = []; var theContents; // Remove spaces that are before, after, or double 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[i]; var newString = thisTextFrame.contents.replace(searchString, replaceString); if (newString != thisTextFrame.contents) { thisTextFrame.contents = newString; } } } for (i = 0; i < allText.length; i++) { theContents = allText[i].contents; theContents = myTrim(theContents); allText[i].contents = theContents; } removeDoubleSpaces(); // Read table data for (var i = allText.length - 1; i >= 0; i--) { //alert(allText[i].contents); componentName.push(allText[i].contents); } //alert(componentName.length); alert("Your component table has been successfully scanned!"); doc.close(SaveOptions.DONOTSAVECHANGES); // Format text on Hypertext layer to read (#) Component Name var doc = app.activeDocument; var allText = doc.textFrames; for (i = 0; i < allText.length; i++) { theContents = allText[i].contents; theContents = myTrim(theContents); allText[i].contents = theContents; } removeDoubleSpaces(); var calloutStartNumber = prompt("Start with callout number...", "1", "Callout Number"); var hyperLayer = doc.layers.getByName("Hypertext"); for (var i = 0; i < componentName.length; i++) { //alert(componentName.length); for (var z = 0; z < allText.length; z++) { //alert(allText.length); if (componentName[i] == allText[z]) { alert(componentName[i] + " " + allText[z]); allText[z].contents = "(" + (calloutStartNumber) + ") " + allText[z].contents; calloutStartNumber++; } } } alert("Your components have been numbered!");
My desired output is Accumulator Gp - Hydraulic (Charged) is number 1 and then each item after that on the table (that is in alphabetical order) will be numbered sequentially on the document. I don't want the script to change the text box or get rid of the carriage returns....just insert the sequential number in front of it like this....