2

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?

2
  • Are you using the CS Extension builder ? Is there some functionality to save references to objects ? I haven't used it, just scripted with ExtendScript Toolkit. From my experience, as soon as the calls to Illustrator finish, I imagine the scope to variables would be lost, so you need to find other ways to keep track of that selected object (position, appearance, etc.) Commented Jan 29, 2012 at 23:46
  • Yes I'm using Cs Extension builder. I can access the objects in the arrObj array and apply changes to them and it would appear in the illustrator document. But it doesn't work the other way around when I would like to check if the object in the document has been saved in the array or not. Commented Jan 30, 2012 at 0:09

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.