[ExtendScript] Can't update placed graphic if document was opened by script
- May 29, 2023
- 5 replies
- 1223 views
Hi scripters, I am experiencing a bug trying to update a placed pdf graphic (.ai document). I came across this bug, lodged by @Peter Kahrel which describes the same bug I'm experiencing, but it seems that it wasn't able to be followed-up due to difficulty in reproducing it.
I have put together a simple test case that reliably (for me) triggers the bug, and I would be grateful if people could try it out and report if they see the bug like I do, or not. Please leave comment if you get a result either way, including your OS and Indesign version.
Needless to say if anyone knows a solution, or a workaround, I would love to hear that too.
To set up the test, just download the attached script, .indd and .pdf and put them into a folder together. I've put instructions for two tests in the comment at the start of the script. Here it is:
/**
* To set up the tests:
* 1. have the demo.indd in folder with this script
* 2. have the linked graphic in folder with this script
*
* TEST 1: Do not open "demo.indd" before running script (let the script do it).
* TEST 2: have "demo.indd" open before running the script.
*
* My results, using Indesign 18.3 MacOS 13.4:
*
* TEST 1 RESULT:
* - error during call to "graphic.place"
* - throws "Error: This file is already open by another user or another application. This file may be stored on a network server and cannot be opened until the other user closes it."
* - placed pdf graphic DOES NOT change to page 2.
*
* TEST 2 RESULT:
* - works as expected: no error, and placed pdf graphic changes to page 2.
*
* NOTE: if TEST 1 works as expected for you, please run the test several times.
* Initially I had a more complicated version of the test, which failed, while this one passed,
* but it passed only once (if I remember right!) and thereafter failed, and now I can make it pass.
* So please test multiple times.
*/
function main() {
// set path to the same folder as this script
var path = File($.fileName).parent.fsName;
// open the demo indesign document
var doc1 = app.open(File(path + '/demo.indd'));
// the graphic we want to update
var graphic = doc1.allGraphics[0];
// we want to update to show artboard 2 (currently showing 1)
app.pdfPlacePreferences.pageNumber = 2;
try {
// here's where the problem occurs
graphic.place(File(graphic.itemLink.filePath), false);
} catch (error) {
alert(error);
}
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Test Graphic Update Bug');
So, the script just opens a document and attempts to update the graphic (by linking to another page in the same pdf). In my test, if I have the demo.indd document open already, it works fine and I see the graphic change to "SUCCESS". But if I let the script open the document, it fails. I would love to know your experience.
@Peter Kahrel you found the bug using link.update(). This has the same problem when I test it, but isn't as obvious for testing purposes because it doesn't throw an error (it just fails to update).
Thanks for your help. If I get some useful responses I will update the bug report with a link here and hopefully the developers will have something to get their teeth into. @amaarora you requested further information on this bug.
- Mark


