The requested action could not be completed because the object no longer exists

New Here ,
Dec 29, 2021 Dec 29, 2021

Copy link to clipboard

Copied

I have a problem with a script execution in indesign version release.

I have a plug-in that launch indesign javascript and when i launch the script in indesign debug the script run, put when i launch the script in release indesign, i hace a error message "The requested action could not be completed because the object no longer exists".

The script is a new menu that is created dinamically. The menu is visible, but when i select any scriptmenuaction, dont run the listener.

My script code is:

 

#targetengine "createMenuJobOptions"

var pathJobOptionFiles= app.scriptArgs.getValue("pathJobOptionFiles");

var composicionMenu = app.menus.item("Main").submenus.item("Composición");
var jobOptionsMenuTitle= "Seleccionar Tipo Impresión";

var fileJobOptions= File(pathJobOptionFiles+"JobOptions.xml");
if (!fileJobOptions.exists) {
throw("No existe el fichero de JobOptions en la ruta "+ pathJobOptionFiles + ". No se puede seleccionar las opciones de exportación de los PDF's.");
}

fileJobOptions.open("r");
var contenidoXLM= fileJobOptions.read();
fileJobOptions.close();
var root= new XML(contenidoXLM);
if (root == null) {
throw("El fichero de JobOptions en la ruta "+ pathJobOptionFiles + " es incorrecto. No se puede seleccionar las opciones de exportación de los PDF's.");
}

//Eliminamos el menú de los ficheros de impresión
app.scriptMenuActions.everyItem().remove();
var jobOptionsMenu= composicionMenu.submenus.item(jobOptionsMenuTitle);
if (jobOptionsMenu.isValid) {
jobOptionsMenu.remove();
}

var rootXMLElements= root.elements();
var rootXMLElementLength= rootXMLElements.length();
if (rootXMLElementLength <= 0) {
throw("El fichero de JobOptions en la ruta "+ pathJobOptionFiles + " no tiene opciones de impresión. No se puede seleccionar las opciones de exportación de los PDF's.");
}

//Creamos el menú.
composicionMenu.menuSeparators.add(LocationOptions.AT_END);
var jobOptionsMenu=composicionMenu.submenus.add(jobOptionsMenuTitle, LocationOptions.AT_END);

for (index=0; index<rootXMLElementLength; index++) {
var xmlElement= rootXMLElements[index];

var nameTag= xmlElement.@etiqueta.toString();
var nameFile= xmlElement.@nombre.toString();

// Create the Script Menu Action (SMA)
var jobOptionAction = app.scriptMenuActions.add(nameTag);
var eventJobOptions= jobOptionAction.addEventListener("onInvoke", changeJobOption, false);

if (index == 0) {
jobOptionAction.checked = true;
jobOptionAction.enabled = false;

} else {
jobOptionAction.checked = false;
jobOptionAction.enabled = true;
}

// Create a new menu item in the Help submenu
jobOptionsMenu.menuItems.add(jobOptionAction, LocationOptions.AT_END);
}

/*
*/

function changeJobOption(event) {
var action= event.parent;
alert(action.title);
}

 

thanks.

 

TOPICS
Bug , How to , Scripting , SDK

Views

110

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 29, 2021 Dec 29, 2021

Copy link to clipboard

Copied

Hi israelp20923262,

this line of code is very dangerous:

app.scriptMenuActions.everyItem().remove();

Assume that other scripts with access to scriptMenuActions are running as well.

You will destroy their functionality.

 

Something like that should work where you give the menu action a unique name:

// Create the Script Menu Action (SMA)
var jobOptionAction = app.scriptMenuActions.add(nameTag);
jobOptionAction.name = "MyUniqueName";

 

And before, you use that name to remove that particular script menu action:

app.scriptMenuActions.itemByName( "MyUniqueName" ).remove();

 

Don't know if that will solve all your issues, but it could be a first step.

I also do not know if the string in variable nameTag will always qualify as a "title" of a script menu action.

 

Regards,
Uwe Laubender

( ACP )

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 29, 2021 Dec 29, 2021

Copy link to clipboard

Copied

Thanks Uwe.

First for your quick rely and second for your help.

Your reply has improved my code, but it keep crashing, because the problem is related to compiling the code.

If i run the code with a jsx file, this works, but if i export the code to jsxbin, the code don't works.

 

I don't know why with the jsxbin file the code don't works.

 

Regards.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 29, 2021 Dec 29, 2021

Copy link to clipboard

Copied

Hi israelp20923262,

you can do a mix of "readable" code and binary code in one *.jsx file.

The issue is the targetengine statement that cannot be inside the binary code.

 

Read more about the problem and its solution here:

 

Binary JavaScript Embedment (CS4/CS5)
Marc Autret, April 13, 2010

https://www.indiscripts.com/post/2010/04/binary-javascript-embedment-cs4-cs5

 

Especially read all under section 2 of Marc's article.
Note: I cannot use the title of that section here in the forum, because there is a banned word in its name:

BannedWordBastard.PNG

 

Regards,
Uwe Laubender

( ACP )

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 09, 2022 Jan 09, 2022

Copy link to clipboard

Copied

LATEST

Thanks Uwe.

That solution was what I had in mind, because I had seen examples, but with the link that you sent me in your answer I already have it clearer.

 

Regards.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines