-
1. Re: [JS][CS5] Finding an object (group) by its label
Marijan Tompa Aug 28, 2010 5:22 AM (in response to Roy Marshall)What do you mean by label? Is it "Script Label", label inserted with "insertLabel" or "itemByName" (object label in layers panel)?
--
tomaxxi
-
2. Re: [JS][CS5] Finding an object (group) by its label
Roy Marshall Aug 28, 2010 1:14 PM (in response to Marijan Tompa)The label I am trying to access is the label from the script label panel. I have brought in a library item onto my page, and the only way I know to get a handle on it is to give it a label before it gets put in the library.
What I need to do is find this item quickly.
I hope that makes it clearer!
-
3. Re: [JS][CS5] Finding an object (group) by its label
Marijan Tompa Aug 28, 2010 1:37 PM (in response to Roy Marshall)--
-
4. Re: [JS][CS5] Finding an object (group) by its label
Marijan Tompa Aug 28, 2010 1:40 PM (in response to Roy Marshall)Hey!
Yeah, it's known issue with script labels and CS5.
You can find answer here: http://forums.adobe.com/message/2800152#2800152
Hope it helps!
--
tomaxxi
-
5. Re: [JS][CS5] Finding an object (group) by its label
Roy Marshall Aug 29, 2010 3:57 AM (in response to Marijan Tompa)yes, that helps loads, but I have one problem. The item I am looking for is contained within a group. Looping through all the page items as I have done in the past seems to look within the group, but the method in your reply only seems to look at the actual page items, not within the grouped items. Can I get around this?
Cheers
Roy
-
6. Re: [JS][CS5] Finding an object (group) by its label
Roy Marshall Aug 29, 2010 4:36 AM (in response to Roy Marshall)OK.
I got around this by un-grouping before using the function, then myDoc.undo(); to get the group back!
Works OK, but seems more a hack! Are there any problems to doing this as far as anyone can see?
Roy
-
7. Re: [JS][CS5] Finding an object (group) by its label
Marijan Tompa Aug 29, 2010 12:31 PM (in response to Roy Marshall)Hey!
Nice hack I think there is nothing wrong with that
I created short snippet that searches through activeDocument.allPageItems looking for specific label, it runs pretty fast. I tested it on about 5000 objects, and it needs 3-4 seconds for search, also you can search in activePage.allPageItems, so it runs lot faster. One difference is that you can search inside groups. This script returns index number in allPageItems array, so you can access object really easy.
Array.prototype.exists = function(search){ var foundCount = Array(); for (var i = 0; i < this.length; i++) if (this[i] == search) foundCount.push(i); if (foundCount.length != 0) return foundCount; else return false; } var myDoc = app.activeDocument; var myPage = app.activeWindow.activePage; //for active document var myObjList = myDoc.allPageItems; // or for active page // var myObjList = myPage.allPageItems; var myLblList = Array(); for(var i = 0; i < myObjList.length; i++){ myLblList.push(myObjList[i].label); } var myID = myLblList.exists("myText"); myObjList[myID].contents = "ccc";If you have more than one object with same label, it will return array of object numbers.
Hope it helps!
--
tomaxxi



