Script to change the color of the border and shading of a paragraph
Hello
I need help with a script for Adobe Indesign which must change the border color and shading in a specific paragraph called offer_module

Hello
I need help with a script for Adobe Indesign which must change the border color and shading in a specific paragraph called offer_module

Hello.
I cannot send the code I am working on since it is very extensive and executes several tasks that have nothing to do with the problem I am presenting, so I sent an example code. I reviewed the code I had sent them and it had errors, I corrected them and found how to change the color of the shading and the border of the paragraph.
#targetengine "session"
main();
function main(){
snippet();
}
function snippet(){
var layoutContextMenu = app.menus.item("$ID/RtMouseLayout");
layoutContextMenu.addEventListener("beforeDisplay", beforeDisplayHandler, false);
}
function beforeDisplayHandler(event){
var textContextMenu = app.menus.item("$ID/RtMouseLayout");
menu6Name = "Color offer module"
if(checkForMenuItem(textContextMenu, menu6Name) == false ){
k = changeStoryColors;
makeLabelGraphicMenuItem(menu6Name, k );
}
}
function checkForMenuItem(mn, str){
var result = false;
try{
var mnItem = mn.menuItems.item(str);
mnItem.name;
result = true
}
catch(error){}
// alert("Menu item found? " + result);
return result;
}
function makeLabelGraphicMenuItem(menu6Name, k ){
if(checkForScriptMenuItem(menu6Name) == false){
labelGraphicMenuAction = app.scriptMenuActions.add(menu6Name);
labelGraphicEventListener = labelGraphicMenuAction.eventListeners.add("onInvoke", k, false);
}
var rMouseMnu = app.menus.item("$ID/RtMouseLayout");
var mName6 = app.scriptMenuActions.item(menu6Name);
var mElement1 = rMouseMnu.menuItems.add(mName6, LocationOptions.AT_BEGINNING );
rMouseMnu.menuSeparators.add(LocationOptions.AFTER, mElement1);
}
function checkForScriptMenuItem(str){
var result = false;
try{
var scriptMenuAction = app.scriptMenuActions.item(str);
scriptMenuAction.name;
result = true
}
catch(error){}
// alert("Script menu action found? " + result);
return result;
}
function changeStoryColors(){
var myDocument = app.activeDocument;
var values = [];
for(sw= 0; sw< myDocument.swatches.length; sw++){
values.push(myDocument.swatches[sw].name);
}
var w = new Window ('dialog', "Change colors");
var main = w.add ("group");
main.add ("statictext", undefined, "Color Module Offer: ");
var lBox = main.add ("dropdownlist", undefined, values);
var main3 = w.add ("group");
var imp = main3.add ("button", undefined, "OK");
var btnClose = main3.add('button', undefined, 'Close');
var userSelection;
btnClose.size = [60, 20];
imp.onClick = function (){
userSelection = lBox.selection.text;
if(userSelection == null ){
alert('Select a color')
}
else{
try{
w.close(1);
}
catch(e){
alert(e.message)
}
}
}
btnClose.onClick = function(){w.close();}
var wResults = w.show();
if(wResults === 1){
var userColor = app.activeDocument.swatches.item(userSelection);
var storiesLenght = app.selection.length;
for(x=0; x<storiesLenght; x++){
var storySelected = app.selection[x];
if(storySelected.associatedXMLElement != null){
var STRStoryTreeElements = storySelected.associatedXMLElement.xmlElements;
for(d=0; d<STRStoryTreeElements.length; d++){
with(STRStoryTreeElements.item(d)){
if(markupTag.name == "offer_module"){
with(xmlElements){
texts[0].paragraphs[0].paragraphBorderColor = userColor;
texts[0].paragraphs[0].paragraphShadingColor = userColor;
}
}
}
}
}
}
}
}
When one or more text boxes are selected and right-clicked, a tab called 'Color offer module' is displayed in the menu. When it is executed, it shows the list of colors that are saved in the document, then you select the color by which you want to change the color of the shading and the paragraph of all the boxes that contain an xml object called 'offer_module'.
I performed tests on the code I am making and it works without problems.
There are times when creating scripts for indesign I have had problems because the documentation is not very detailed, especially when it is the part of how to work with XML objects in inDesign.
Anyway, thank you all very much for your collaboration.
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.