• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Script to place an icon at the beginning of a paragraph

New Here ,
Mar 31, 2023 Mar 31, 2023

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.

TOPICS
Scripting

Views

777

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

correct answers 1 Correct answer

Guide , Apr 01, 2023 Apr 01, 2023

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 ScriptBefore The Script

 

After The ScriptAfter 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++ )
...

Votes

Translate

Translate
Community Expert ,
Mar 31, 2023 Mar 31, 2023

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.

 


╟ Word & InDesign to Kindle & EPUB: a Guide to Pro Results (Amazon) ╢

Votes

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
Community Expert ,
Mar 31, 2023 Mar 31, 2023

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.

Votes

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
Guide ,
Apr 01, 2023 Apr 01, 2023

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 ScriptBefore The Script

 

After The ScriptAfter 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

Votes

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
Community Expert ,
Apr 01, 2023 Apr 01, 2023

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. 🙂

 


╟ Word & InDesign to Kindle & EPUB: a Guide to Pro Results (Amazon) ╢

Votes

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
Guide ,
Apr 01, 2023 Apr 01, 2023

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!

 

(^/)

Votes

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
Community Expert ,
Apr 01, 2023 Apr 01, 2023

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.

 


╟ Word & InDesign to Kindle & EPUB: a Guide to Pro Results (Amazon) ╢

Votes

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 ,
Apr 01, 2023 Apr 01, 2023

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 🙂

Votes

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
Guide ,
Apr 02, 2023 Apr 02, 2023

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):

 

Capture d’écran 2023-04-02 à 11.27.40.png

 

So:

 

app.findGrepPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyleGroups.item("AAAA").paragraphStyleGroups.item("BBBB").paragraphStyles.item(mySel[s].appliedObjectStyle.name);

 

 

Votes

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 ,
Apr 02, 2023 Apr 02, 2023

Copy link to clipboard

Copied

Marvellous! Thank you again @FRIdNGE 🤩

Votes

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
Guide ,
Apr 02, 2023 Apr 02, 2023

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! …")

 

 

 

(^/)

Votes

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 ,
Apr 04, 2023 Apr 04, 2023

Copy link to clipboard

Copied

LATEST

Even better @FRIdNGE ! 🙏

Votes

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
Community Expert ,
Apr 01, 2023 Apr 01, 2023

Copy link to clipboard

Copied

I like that approach! Thanks for sharing.

- Mark

Votes

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