3

I have a (very large) script running in InDesign that, at one point, places a Library asset onto the page, then moves it to a certain layer. This script runs just fine on all of our computers here, but only when there are no other documents open in InDesign at the time.

If another document is open, then an error shows up when script is trying to move the placed asset onto another layer:

JavaScript Error!

Error Number: 54 Error String: Uncaught JavaScript exception: ERROR at line number 2651 Invalid value for set property 'itemLayer'. Expected Layer, but received Layer.

Note the part in bold. It received what it was expecting, so it throws a tantrum? This makes no sense to me. And for the record, here's the line of code it is referencing:

curAsset[0].itemLayer = document.layers.item("Art Work (max imprint)");

And, for the record, curAsset[0] is an asset object taken from a Library and already placed on the document. And document is a variable that has already been assigned to the currently open document.

My working theory is that other documents open in InDesign are causing this error, as that is the only correlation I've been able to make so far, but I don't see how. The script already has the variable document, which references only one of the documents open. And everything else in the script runs fine, except for this one line (so far).

halfer
  • 19,824
  • 17
  • 99
  • 186
Sturm
  • 689
  • 2
  • 23
  • 52
  • Could it be that it's getting that `Layer` object from a different document when the others are open somehow? – Josh Voigts Oct 15 '13 at 13:13
  • That's pretty much my working theory, but I've no idea how, or why it only does it to this one line of code out of dozens of lines that refer to the `document` variable. I'm telling everyone here to make sure that no documents are open in InDesign before running the script for now, but that's not ideal, obviously. – Sturm Oct 15 '13 at 13:31
  • +1 just for the error message. – georg Oct 15 '13 at 13:34

2 Answers2

0

That's a very funny/infuriating error message. You can always try getElements(). It sometimes works like magic.

curAsset[0].itemLayer = document.layers.item("Art Work (max imprint)").getElements()[0];

One other thing to think about. Extendscript in InDesign sometimes doesn't distinguish between an object of a certain type, and an array of objects of said type. So you may want to make sure your query is only returning a single item.

Justin Putney
  • 752
  • 1
  • 5
  • 16
0

TLDR; Make sure your "document" object is the same object used to build your "curAsset" array of objects.

I hope you have found a solution since then, but if you haven't I may have a lead for you in finding a solution. I have dealt with this type of error "Expected X, but received X" myself.

It's hard to know without seeing the rest of the code, but I suspect that the reference to your "document" object is not referencing the same document that your "curAsset" objects refers to.

In my case when I had this happen I was trying to copy a paragraph from a document to another and then assign a paragraph style, but I was mistakenly using a reference of the paragraph style from the first document when trying to apply it to the paragraph on the second document. While both documents had the same template and paragraph styles, the reference to the paragraph style object is unique to the document.

Eric B.
  • 338
  • 3
  • 14