I remember that in previous version of InDesign was possible to target, addressing box by label with something like
set myBox to page item “Abc”
Reading in old forum previously seems that was possible to target box by name or by script label.
Now in CS5 or higher this seems changed.
But every page item has also a unique ID.
So, suppose to generate a catalog with hundreds of box. If I need to store my info in array I can put the ID of every created box and retrieve it after, if i need, with something like:
tell application “Adobe InDesign CS5.5”
tell active document
set selection to page item id 201 (or the number of box ID stored)
end tell
end tell
I suppose that the stored ID remain unique for all life of document even if I close it end re-open. Or not?
But about targeting page item by label, what’s the short and fast syntax?
I find that:
tell application “Adobe InDesign CS5.5”
tell active document
set myBox to item 1 of (every page item whose label is “London”)
end tell
end tell
OR
tell application “Adobe InDesign CS5.5”
tell active document
set myBox to first item of (page items whose label is “London”)
end tell
end tell
is too verbose. The function return a list of elements (because more than one box can have the same name/labeI)
But if all my name/labels are unique, I would like a “direct” link to a page item called for example “London” with something like:
guess you can use the name property. It’s shown in the layerwindow.
Choices are label, insert label or name …
tell application "Adobe InDesign CS5.5"
tell active document
set name of page item 1 to "Hello here I am"
select page item "Hello here I am"
end tell
end tell
tell application “Adobe InDesign CS6”
tell active document
– CASE 1
set boxRef to item 1 of page items whose label is “London” – As Shane suggest
– Result is returned as List so the following command fail
– set fill color of boxRef to “C=0 M=0 Y=100 K=0”
– Should be
– set fill color of item 1 of boxRef to “C=0 M=0 Y=100 K=0”
-- CASE 2
set boxRef to page item 1 whose label is "London"
set fill color of boxRef to "C=0 M=0 Y=100 K=0"
end tell
end tell
The question is: why the command
set boxRef to item 1 of page items whose label is “London”
return a reference to the box as list???
And:
set fill color of boxRef to “C=0 M=0 Y=100 K=0”
and
set fill color of boxRef to color “C=0 M=0 Y=100 K=0”
It looks like a bug introduced in CS6 to me. So you probably need to either use the parentheses or coerce it, or something.
If you’re after all the items on the page, not just directly on the page, you can use:
set boxRef to item 1 of all page items whose label is "London"
The second one can fail if you’re within certain tell blocks. I reckon the safest thing to do is to make a reference to the color, and use that:
tell application "Adobe InDesign CS6"
tell document 1
set theColor to color "C=0 M=0 Y=100 K=0"
-- [...]
set fill color of boxRef to theColor
end tell
end tell
is returned as list. I think to is more useful the syntax in Case 2:
set boxRef to page item 1 whose label is “London”
that can produce a direct reference to pilot any object
tell application “Adobe InDesign CS4”
tell active document
– CASE 1
set boxRef to item 1 of page items whose label is “London”
– Result: {rectangle id 200 of page id 190 of spread id 185 of document “Senza titolo-1” of application “Adobe InDesign CS4”}
-- CASE 2
set boxRef to page item 1 whose label is "London"
-- Result: rectangle id 200 of page id 190 of spread id 185 of document "Senza titolo-1" of application "Adobe InDesign CS4"
end tell
end tell
I have a doubt: because the reference contains reference to the document I see that to target box I can both use:
tell application “Adobe InDesign CS4”
tell active document
set blablabla of boxRef…
end tell
end tell
or
tell application “Adobe InDesign CS4”
set blablabla of boxRef…
end tell
Any problem if I use the first (tell app and tell document)?