Copy link to clipboard
Copied
I'm wondering if anyone can help me with a little script ...
I have reocurring documents that consist of several pages. In a document I need to place icons at the beginning of certain paragraphs, e.g. I need to place Icon-A at the beginning of Para-style-A, Icon-B at the beginning of Para-style-B, and Icon-C at the beginning of Para-style-C. I can do this no problem using find/change and GREP, e.g. copying Icon-A to the pasteboard and running a command to find the beginning of Para-style-A and paste the icon. Then repeating the process for the other icons/paragraphs.
Is it at all possible that a script could add all the icons to the relevant paragraph styles?
Any help is much appreciated.
I'm just answering to the op's question [without digression]!
Take care to give the same name to the para styles and the icon applied object styles to target. 😉
Before The Script
After The Script
The op just needs to Select All The Icons On Pasteboard and then play the Script below:
// by FRIdNGE, Michel Allio [01/04/2023]
// Select All The Icons On Pasteboard [Including Corresponding Object Style (same name as para style)]:
var mySel = app.selection;
for ( var s = 0; s < mySel.length ; s++ )
...
Copy link to clipboard
Copied
A script can almost certainly be created, but the fundamental layout can be handled in one of two ways: with a bullet Paragraph Style, probably using a Character Style override on the bullet glyph itself, or by defining a Drop Cap, similarly using a Character style to set the 'icon' font and characteristics. (The third way would be to place the icon glyph or image in a frame, and then anchor it so that it takes the place of a drop cap or large bullet, as desired.)
Once set up, all of these methods should be easy and quick to apply. A script may be... superfluous. But the script gurus here will ring in on an actual solution once a layout method is chosen.
Copy link to clipboard
Copied
Hi @Jahrod, it's probably only worth writing a script if you have hundreds of these to do. Otherwise it will be pretty fast to just do a find next on the paragraph style and paste the (pre-configured) anchored graphic into the first insertion point. It shouldn't take more than a minute to do 50 like this. As @James Gifford—NitroPress said, the paragraph styles may need to do some formatting—it would be good to see a screenshot of your desired result.
- Mark
Edit: Oh! and don't forget to set up an Object Style on the anchored graphic frames.
Copy link to clipboard
Copied
I'm just answering to the op's question [without digression]!
Take care to give the same name to the para styles and the icon applied object styles to target. 😉
Before The Script
After The Script
The op just needs to Select All The Icons On Pasteboard and then play the Script below:
// by FRIdNGE, Michel Allio [01/04/2023]
// Select All The Icons On Pasteboard [Including Corresponding Object Style (same name as para style)]:
var mySel = app.selection;
for ( var s = 0; s < mySel.length ; s++ ) {
app.copy(app.select(mySel[s]));
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyles.item(mySel[s].appliedObjectStyle.name);
app.findGrepPreferences.findWhat = "^~a?(.)";
app.changeGrepPreferences.changeTo = "~c$1";
app.activeDocument.changeGrep();
}
app.findGrepPreferences = app.changeGrepPreferences = null;
app.selection = null;
alert("Done By FRIdNGE! …")
(^/) The Jedi
Copy link to clipboard
Copied
I don't think raising the point that there are three basic ID operations that can do what the OP wants is 'digression.' You have to have an achievable method before it can be scripted. 🙂
Copy link to clipboard
Copied
Jahrod clearly told us what he could simply do with a simple Grep F/R and what he would like to avoid and get!
(^/)
Copy link to clipboard
Copied
If you say so. I find "place an icon at ____" to be an ambiguous operation, and so covered all three technical methods by which it could be achieved. I read nothing in the OP about "what he would like to avoid."
If you're going to Maslow's Hammer a question, at least respect other applicable viewpoints.
Copy link to clipboard
Copied
@FRIdNGE That is EXACTLY what I was after! Amazing. Thank you so much!
At first I had an error when running the script but I realised it was due to my para styles being within a style group. Would it be possible for you to modify the script so that it can find the para styles in a group?
Thank you again. Genius stuff 🙂
Copy link to clipboard
Copied
The place of the relevant Object Styles is without interest. We just need to detect their name (= para style name).
BUT, you're right, you need to clearly indicate where the Para Styles are placed (my original Script: the first level).
Sample (in a third level):
So:
app.findGrepPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyleGroups.item("AAAA").paragraphStyleGroups.item("BBBB").paragraphStyles.item(mySel[s].appliedObjectStyle.name);
Copy link to clipboard
Copied
Marvellous! Thank you again @FRIdNGE 🤩
Copy link to clipboard
Copied
This v.2 plays without needing any reference to "paragraphStyleGroups"!
// v.2 by FRIdNGE, Michel Allio [02/04/2023]
// Select All The Icons On Pasteboard [Including Corresponding Object Style (same name as para style)]:
var myDoc = app.activeDocument,
myParagraphStyles = myDoc.allParagraphStyles;
var mySel = app.selection;
for ( var s = 0; s < mySel.length; s++ ) {
app.copy(app.select(mySel[s]));
app.findGrepPreferences = app.changeGrepPreferences = null;
for ( var p = 0; p < myParagraphStyles.length; p++ ) if ( myParagraphStyles[p].name == mySel[s].appliedObjectStyle.name ) app.findGrepPreferences.appliedParagraphStyle = myParagraphStyles[p];
app.findGrepPreferences.findWhat = "^~a?(.)";
app.changeGrepPreferences.changeTo = "~c$1";
myDoc.changeGrep();
}
app.findGrepPreferences = app.changeGrepPreferences = null;
app.selection = null;
alert("Done By FRIdNGE! …")
(^/)
Copy link to clipboard
Copied
Even better @FRIdNGE ! 🙏
Copy link to clipboard
Copied
I like that approach! Thanks for sharing.
- Mark