Frage

I'm building a plugin and I'm using actionscript to save the selection of an object in an illustrator document and then reference it later.

var arrObj:Array=new Array();
arrObj.push(app.activeDocument.selection[0]);

If I select now the same object in the document and check if its in the array it returns a -1 for the index value.

var id:int=arrObj.indexOf(app.activeDocument.selection[0]);
trace (id); //-1

Why is the selection not considered the same object as in that of the array?

War es hilfreich?

Lösung

I figured out a work around for saving the selected objects in an array and when selecting the object again in the illustrator document it would point out the index of that object in the array. Selected objects datatypes are "PathItems" and have a variable called name. All you have to do is set this variable to a value of your choice as well as saving it in an another array.

var arrObj:Array=new Array();
var nameHold:Array=new Array();

arrObj.push(document.selection[0]); // save the selection in an array
var hold:PathItem=document.selection[0];
hold.name="index1"; // setting the name variable of the selected object to a value of choice
nameHold.push(hold.name); // adding the name value in an array 

Now the selected object and its corresponding name value are stored in arrays at the same index...you can compare all "PathItems" to each other by using the name variable and if the names match then you can get the index by using the .indexOf("name") method in arrays.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top