Kasyan Servetsky wrote:
I remember I encountered the same issue when I was writing this script — check out the code to see how I solved it.
app.documents.toSpecifier() Result: /document
app.documents.selection.toSpecifier() Result: /document[@name="Untitled"]//text-frame[@id=199]
I'm sorry for confusing you.
The actual problem is that the collections within same-named documents refer to the wrong one.
The APID solution was an attempt to solve the issue, but since it wasn't the document reference that was broken, the fix didn't help...
So in other words, there is nothing I can do about it except to look for same-named documents and politely ask the user to close them?
Since the problem wasn't quite what I expected, was the real problem fixed in CS4 or CS5?
That's about the size of it...
Mayhem SWE wrote:was the real problem fixed in CS4 or CS5?
I haven't looked into this in a while, but I think it was fixed in CS5.
Welll...chances are the selected item will not be a valid ID in both documents of the same name. (I don't think ID's are globally unique, so that's not a guarantee -- but it's something you can check and only give an error if it happens to be that there is a collison).
So, get the transaction specifier of the selection:
app.activeWindow.selection.toSpecifier() Result: /document[@name="u1.indd"]//text-frame[@id=211]
Then, iterate over app.documents to find the indexes of the documents with that name.
In my test, of course it is just zero and one.
Then, try to resolve the specifiers against those documents:
resolve("/document//text-frame[@id=211]") Result: [object TextFrame] resolve("/document//text-frame[@id=211]") Error: Object is invalid
Since only doc 0 has a textFrame with id 211, you know it's doc 0 and you have a valid specifier.
I chose to adjust the specifier by hand, because I think that's probably the most general. The other choice would be to call app.documents.textFrames.itemByID(211), but then you would need to map "text-frame" to "textFrames" and that seems annoying and errorprone.
Too bad it doesn't work though -- resolve() hands back an object that is invalid for some reason.
So I guess you do need to use itemByID(). So maybe something like:
resolve("/document//text-frame[@id=211]").constructor.name Error: Object is invalid resolve("/document//text-frame[@id=211]").constructor.name Result: TextFrame eval("app.documents." (t=(resolve("/document//text-frame[@id=211]"). constructor.name), t.toLowerCase()+t.substr(1)+ "s")+".itemByID(211)").contents Result: U1 in the X2 folder
I'm sure you can make it prettier :-).
John, If you have a page item with the same ID in both docs (which can happen), this isn't going to work either...
Yeah, I know.
When I said:
> but it's something you can check and only give an error if it happens to be that there is a collison
The idea was you'd check and see if there was a collision, and only then give an error.
It's just easier to not support docs with the same name...
Yes, I think the only sensible solution is to simply not support having multiple documents with the same name open. Writing a complex workaround for an issue which has already been resolved in CS5 (which we will finally receive soon-ish...) doesn't seem worth the effort it'd require. Thanks!