Copy link to clipboard
Copied
Hi friends,
when clicking the button the selected items of list box should get deselected & deselected items get selected from list box? Can any one tell me.....
The following code for the button click handler should do the job.
button2.addEventListener("click",function(event)
{
for(var i = 0; i < listbox1.items.length; i++)
{
var a = listbox1.items[i]
listbox1.items[i].selected = !listbox1.items[i].selected
}
});
-Manan
Copy link to clipboard
Copied
Show us the sample code that you have, only then can we give proper suggestions.
-Manan
Copy link to clipboard
Copied
Thank you for ur reply Manan Joshi,
Here is the code,
when clicking the reverse selection button the items present in the listbox should get selected and the unselected items should get selected?
// GROUP2
// ======
var group2 = panel1.add("group", undefined, {name: "group2"});
group2.preferredSize.width = 200;
group2.orientation = "column";
group2.alignChildren = ["left","center"];
group2.spacing = 10;
group2.margins = 0;
var statictext1 = group2.add("statictext", undefined, undefined, {name: "statictext1"});
statictext1.text = "Please select Preset/Presets";
var button2 = group2.add("button", undefined, undefined, {name: "button2"});
button2.text = "Reverse Selection";
button2.addEventListener("click",function(event){
if(button2.text == "Reverse Selection") {
listbox1.selection = 0;
}
else(button2.text !== "Reverse Selection"){
listbox1.clearSelection = false;
}
});
var presetList = [];
for(var fp = 0; fp < app.pdfExportPresets.length; fp++){
presetList.push(app.pdfExportPresets[fp].name.toString());
}
var listbox1 = group2.add ("listbox", undefined, undefined, {name: "listbox1", items: presetList, multiselect: true});
listbox1.selection = 0;
listbox1.preferredSize.width = 179;
If you know means please reply me..........
Copy link to clipboard
Copied
Copy link to clipboard
Copied
The following code for the button click handler should do the job.
button2.addEventListener("click",function(event)
{
for(var i = 0; i < listbox1.items.length; i++)
{
var a = listbox1.items[i]
listbox1.items[i].selected = !listbox1.items[i].selected
}
});
-Manan
Copy link to clipboard
Copied
Thanks a lot Manan!! ur code works.perfectly. thank u so much.............
Copy link to clipboard
Copied
And one more doubt can you solve this?
. When Export button is pressed, pdf should export and naming conventions of pdf file/s will be like ["InDesignFileName_PresetSelected_LayerSelected.pdf"]
Note : If user is selecting 2 preset & 1 layer so total 2 pdf will be generated etc.
Here is my code,
var myDoc = app.documents[0];
for(var i = 0; i < myDoc.layers.length; i++){
myDoc.layers[i].visible = false;
}
for(var i = 0; i < myDoc.layers.length; i++){
var layerName = myDoc.layers[i].name;
myDoc.layers[i].visible = true;
app.activeDocument.exportFile(ExportFormat.pdfType, File(myDoc.filePath.fsName.replace(/\\/g,'/')+"/"+myDoc.name.replace(/\.indd/g,'')+"_"+layerName+".pdf"),false);
$.writeln(myDoc.filePath.fsName.replace(/\\/g,'/')+"/"+myDoc.name.replace(/\.indd/g,'')+"_"+layerName+".pdf");
myDoc.layers[i].visible = false;
}
pls refer the above screenshot which I had sent...
Copy link to clipboard
Copied
Place your export code in a loop that runs according to the length of the listbox's selection property.
listbox1.selection.length
The above would give you the total number of selected elements in the listbox.
Then you can access the text of each selected entry as the following
listbox1.selection[0].text
-Manan