我想出了一个解决方法,将选定的对象保存在一个数组中,当在 illustrator 文档中再次选择该对象时,它会指出该对象在数组中的索引。选定的对象数据类型是“PathItems”,并有一个名为 name 的变量。您所要做的就是将此变量设置为您选择的值并将其保存在另一个数组中。
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
现在所选对象及其对应的名称值存储在同一索引处的数组中...您可以使用 name 变量将所有“PathItems”相互比较,如果名称匹配,则可以使用 .数组中的 indexOf("name") 方法。