Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

What is the best way to compare 2 arrays?

$
0
0

I am filtering through a lot of text frames to get some numbers. The numbers reside on 2 different layers.

 

So I have gathered just the numbers from each layer and given them each their own array.

 

I would like to compare the 2 arrays and if something is missing from either array have a text frame created under the correct header as a list of what is missing from each array (if any is missing at all).

 

So compare the sorted arrays....

tableCallouts to graphicCallouts

 

Any thoughts on the best method of doing this? There could also be duplicates in either list to throw another wrench into things

 

#target illustrator-22
var doc = app.activeDocument;


/* --------- Text filtering for the Tables layer --------- */
var tableText = doc.layers['Tables'].textFrames;


// Setup array to take data from loop
var tableCallouts = [];


// Loop to only find callout numbers
for (var i = 0; i < tableText.length; i++) {    var checkNumber = parseInt(tableText[i].contents);    if (isNaN(checkNumber) == false) {        //alert("Found a number " + tableText[i].contents);        tableCallouts.push(tableText[i].contents);    }
}


// Sort the array
tableCallouts.sort();


/* --------- Text filtering for the Callouts/CONNs layer --------- */
var graphicText = doc.layers['Callouts/CONNs'].textFrames;


// Setup array to take data from loop
var graphicCallouts = [];


// Loop to only find callout numbers
for (var i = 0; i < graphicText.length; i++) {    var checkNumber = parseInt(graphicText[i].contents);    if (isNaN(checkNumber) == false) {        graphicCallouts.push(graphicText[i].contents);    }
}


// Sort the array
graphicCallouts.sort();


var origin = doc.rulerOrigin
var graphicHeaderText = doc.textFrames.add();
graphicHeaderText.textRange.characterAttributes.textFont = app.textFonts.getByName("ArialMT");
graphicHeaderText.position = [-500, 0];
graphicHeaderText.contents = "MISSING FROM GRAPHICS"


var tableHeaderText = doc.textFrames.add();
tableHeaderText.textRange.characterAttributes.textFont = app.textFonts.getByName("ArialMT");
tableHeaderText.position = [-300, 0];
tableHeaderText.contents = "MISSING FROM TABLE"

Viewing all articles
Browse latest Browse all 12845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>