Copy link to clipboard
Copied
I have 2 documents open. A hyperText document and then I am pasting in a table from excel into a new blank document that is just text in alphabetical order already. I push the textFrames from the excel table to an array called componentName and then close the document. The hyperText document has a ton of text and is all over the artboard. I am wanting to find the text from excel table that matches the textFrame on the hyperText document. This is my current working code. Only issue is I am not sure how to make it more efficient and error free by finding the match on ONLY the hyperText layer. The match will be and should only be on the hyperText layer. Any help would be appreciated!!
#target illustrator
//var start = new Date().getTime();
var doc = app.activeDocument;
var allText = doc.textFrames;
var componentName = [];
var count = 0;
// Remove spaces that are before, after, or double
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;
}
}
}
// End of space removing script
// Read table data
for (var i = allText.length - 1; i >= 0; i--) {
//alert(allText.contents);
componentName.push(allText.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;
var theContents;
var calloutStartNumber = prompt("Start with callout number...", "1", "Callout Number");
for (i = 0; i < allText.length; i++) {
theContents = allText.contents;
theContents = myTrim(theContents);
allText.contents = theContents;
}
removeDoubleSpaces();
var hyperLayer = doc.layers.getByName("Hypertext");
for (var i = 0; i < componentName.length; i++){
//alert(componentName.length);
//for (var z = allText.length - 1; z > 0; z--) {
for (var z = 0; z < allText.length; z++){
//alert(allText.length);
if (componentName == allText
.contents){ allText
.contents = "(" + (calloutStartNumber) + ") " + allText .contents; calloutStartNumber++;
}
}
}
alert("Your components have been numbered!");
/*
var end = new Date().getTime();
var time = (end - start) / 1000;
alert('Execution time: ' + time + ' seconds\nTotal textFrames tested: ' + allText.length + '\nNumber of affected textFrames: ' + count);
*/
Copy link to clipboard
Copied
If your text frames are inside your hyperText layer without being contained within any sublayers or being grouped within groups, it's quite easy as you would just use: var targetFrameCollection = doc.layers.getByName("Hypertext").textFrames;