Copy link to clipboard
Copied
Please don't ask how I inherited this text, but I have a book where every paragraph starts with a lowercase letter.
I was able to convert all of the lowercase letters to uppercase by running ^a to A, then ^b to B, ^c to C, etc. It only took 26 times.
But would there have been a more succinct way to do it in one fell swoop?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
You sir, are a genius!!!
Copy link to clipboard
Copied
… Simply a Jedi!
(^/)
Copy link to clipboard
Copied
Hi!
I was struggling with similar problem couple of weeks ago.
I like you approach, but from my point of view it has one gap - it does not handle paragraph styles or character styles placed in groups.
To deal with it I came with something like this:
var myDoc = app.activeDocument;
// array of paragraph styles names to populate ddl
// it uses allParagraphStyles to get every paragraph style, regardles of the group
var myParagraphStyles = [];
for(i=0; i < myDoc.allParagraphStyles.length; i++){
myParagraphStyles.push(myDoc.allParagraphStyles.name);
};
// remove [no paragraph] from array
myParagraphStyles.shift();
// dialog window with ddl of documents paragraph styles
var w = new Window('dialog', 'chose style');
var ddlApplyStyle = w.add('dropdownlist', undefined, myParagraphStyles);
w.add ('button', undefined, 'apply', {name: 'ok'});
w.add ('button', undefined, 'cancel', {name: 'cancel'});
// apply style or exit
if(w.show() == 1){
applyStyle();
};
else{
exit();
};
function applyStyle(){
// name of chosen style transformed by function into real paragraph style object
var pickedStyle = getStyleFromDDL(ddlApplyStyle.selection.text);
// reference to text we want to change
var myText = myDoc.stories[0];
/// applying desired paragraph style
myText.appliedParagraphStyle = pickedStyle;
}
// function takes ddl selection and returns paragraph style object
function getStyleFromDDL(myDDLtext){
// check if style selected in ddl is outside of any group and create variable with paragraph style object
if (myDoc.paragraphStyles.item(myDDLtext) != null && myDoc.paragraphStyles.item(myDDLtext).parent.constructor.name == 'Document') {
var styleToApply = myDoc.paragraphStyles.item(myDDLtext);
};
// or create reference with parent group
else{
var myGroups = myDoc.paragraphStyleGroups;
for(var i = 0; i < myGroups.length; i++) {
for (var j = 0; j < myGroups.paragraphStyles.length; j++) {
if (myGroups.paragraphStyles
.name == myDDLtext) { var styleToApply = myGroups.paragraphStyles.item(myDDLtext);
};
};
};
};
return styleToApply;
};
What do you think about this?
..
Jarek
Copy link to clipboard
Copied
Your going to have to have this discussion with Monsieur Obi Wan Kenobi as I am hardly the script person he is.
Copy link to clipboard
Copied
foltman, combination script of Obi Wan Kenobi and your is solution of my problem (i have styles in group), but im no programmer. Can you combine this scripts? it certainly will not only help me.
Thanks
Copy link to clipboard
Copied
Can you send the link of Change Case
Copy link to clipboard
Copied
Hi together,
I hope Foltman is looking into this thread again.
His script code was damaged by moving this thread to the new forum.
Example: The iterator i is missing inside the for-loop:
for(i=0; i < myDoc.allParagraphStyles.length; i++){
myParagraphStyles.push(myDoc.allParagraphStyles.name);
};
The corrected code for this part is this:
for(i=0; i < myDoc.allParagraphStyles.length; i++){
myParagraphStyles.push(myDoc.allParagraphStyles[i].name);
};
Other corrections should be made as well. Only Foltman could edit this old post from 2017, I think.
Regards,
Uwe Laubender
( ACP )