Function 'createPlainTextQRCode' crashes Adobe InDesign without any reason provided
Hi! I'm trying to write a function, that could update QR code on a page after save. I used code examples from these two discussions in order to solve my problem:
https://community.adobe.com/t5/indesign-discussions/is-it-possible-to-generate-qr-codes-in-indesign-using-current-page-number/m-p/13749888
https://community.adobe.com/t5/indesign-discussions/is-it-possible-to-run-a-script-automatically-when-a-document-is-saved/m-p/7257249
In the end I got the following code:
#target indesign
#targetengine "session"
var myEventListener = app.eventListeners.item("mAfSave");
if (!myEventListener.isValid) {
myEventListener = app.addEventListener("afterSave", updateQR);
myEventListener.name = "mAfSave";
}
function updateQR() {
if (!app.documents.length) {
return;
}
var doc = app.activeDocument;
var label = 'QRCode';
for (var i = 0; i < doc.pages.length; i++) {
var page = doc.pages[i];
var qrCodeFrame = getPageItemByLabel(page, label);
if (qrCodeFrame != undefined && qrCodeFrame.isValid) {
qrCodeFrame.allGraphics[0].createPlainTextQRCode('test');
}
}
alert('QRCode updated!');
}
function getPageItemByLabel(page, label) {
for (var i = 0; i < page.pageItems.length; i++) {
if (page.pageItems[i].label === label) {
return page.pageItems[i];
}
}
}It works fine, but the app crashes on this line: "qrCodeFrame.allGraphics[0].createPlainTextQRCode('test');"
The QR code isn't undefined and 'allGraphis[0]' has a type 'object EPS'. What could be the reason for this behaviour? Windows event logger tells that the problem is in InDesign's 'EPS PAGE ITEM.RPLN' module, but it doesn't say much. I'd be much obliged for any help with this problem. Maybe there are other ways to update QR code in a document.
