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

Tagging italics question

Community Beginner ,
Mar 14, 2014 Mar 14, 2014

Copy link to clipboard

Copied

I've created two grep queries that I use to tag the italics of placed text. Then I manually apply the Basic Paragraph clear overides style. Then I run another Grep querry that takes the words and sentences that have the tags and applies an italic style that I created in the Character style pallet. Here is my Grep Querry for find and Tag italics.

Find What:

(.+)

Change to:

$1

Find Format:

+Italic

Here is My Querry for appling italic character style to tagged text.

Find What:

(\[\i\])(.+?)(\[/\i\])

Change to:

$2

What I'm wondering is if this all could be run from a javascript including applying the Basic Paragraph clear overrides part. I'm not sure where to even begin as I'm new to scripting. Any help would be very appriciated. Thanks.

TOPICS
Scripting

Views

1.1K

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

Enthusiast , Apr 17, 2014 Apr 17, 2014

I trying to learn scripting for indesign

me too

First of all, it is always a good idea, to know, what a script does. Second, it is a good idea, to have a good workflow. I’m not sure, if I would do it in your way, but let us find a solution for the first one:

The script does, what you have ordered: At first it stores your selection. Then it check, if the paragraph style and the character style is available. If not, the script will create them.

Here comes the problem: It does not matter, if the para

...

Votes

Translate

Translate
Enthusiast ,
Mar 14, 2014 Mar 14, 2014

Copy link to clipboard

Copied

Hi,

I did not understand, why you tag your italics first, then apply a paragraph style, remove the overrides and then search for tags and apply your character style.

If you do this in the interface, the first step would be search for italics, apply a character style, then apply your pStyle and remove only the local overrides.

Select a frame and try the following lines:

var curSel = app.selection[0];

app.findGrepPreferences = app.changeGrepPreferences = null;

app.findGrepPreferences.fontStyle = "Italic";

app.changeGrepPreferences.appliedCharacterStyle = "italic";

curSel.changeGrep();

curSel.paragraphs.everyItem().appliedParagraphStyle = "myPStyle";

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 Beginner ,
Mar 14, 2014 Mar 14, 2014

Copy link to clipboard

Copied

Pasting word files into InDesign on a Mac sometimes causes strange font issues so tagging the italics allows me to wipe out all formatting on the text. Then I can process the text without losing the location of the italics. 

Thanks for this. I'll test it out.

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 Beginner ,
Mar 14, 2014 Mar 14, 2014

Copy link to clipboard

Copied

So this seems to be working. Now would it be possible to automaticly create the two styles "italics in character styles and "Body" in Paragraph styles?

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 Beginner ,
Mar 14, 2014 Mar 14, 2014

Copy link to clipboard

Copied

ok. So I'm able to create the styles and I'm getting close to what I need. One last thing. How can I check to see if the character and Body styles exist allready. If they do move on to appling the styles if not create them. Here is the script, anyone out there know how to do this? I'm thinking its try{} but I'm not having any luck. Thanks.

pStyle = app.activeDocument.paragraphStyles .add({name:"Body"})

app.activeDocument.characterStyles.add({name:"italics"});

var curSel = app.selection[0];

app.findGrepPreferences = app.changeGrepPreferences = null;

app.findGrepPreferences.fontStyle = "Italic";

app.changeGrepPreferences.appliedCharacterStyle = "italics";

curSel.changeGrep();

curSel.paragraphs.everyItem().appliedParagraphStyle = "Body";

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
Mentor ,
Mar 14, 2014 Mar 14, 2014

Copy link to clipboard

Copied

Hi,

Check if mentioned style.isValid before define it:

if ( !app.activeDocument.paragraphStyle.item("Body").isValid )

          app.activeDocument.paragraphStyles .add({name:"Body"});

if ( !app.activeDocument.characterStyles.item("italics").isValid )

          app.activeDocument.characterStyles.add({name:"italics"});

//...

Jarek

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
Enthusiast ,
Mar 14, 2014 Mar 14, 2014

Copy link to clipboard

Copied

David, if your styles are not valid, you must provide also some font-information.

var curDoc = app.activeDocument;

var curSel = app.selection[0];

if (!curDoc.characterStyles.item("italic").isValid) {

    var cStyle = curDoc.characterStyles.add({name: "italic"});

}

else {

    var cStyle = curDoc.characterStyles.item("italic");

}

cStyle.fontStyle = "Italic";

app.findGrepPreferences = app.changeGrepPreferences = null;

app.findGrepPreferences.fontStyle = "Italic";

app.changeGrepPreferences.appliedCharacterStyle = cStyle;

curSel.changeGrep();

if (!curDoc.paragraphStyles.item("body").isValid) {

    var pStyle = curDoc.paragraphStyles.add({name: "body"});

}

else {

    var pStyle = curDoc.paragraphStyles.item("body");

}

with (pStyle) {

    appliedFont = "Myriad Pro\tRegular";

    pointSize = 11.5;

    fillColor = "Black";

}

curSel.paragraphs.everyItem().appliedParagraphStyle = pStyle;

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 Beginner ,
Apr 16, 2014 Apr 16, 2014

Copy link to clipboard

Copied

This script is excellent but it does one thing that I do not want. When its used multiple times in the same doc and changes have been made to the italics it overrides them and sets it back to italics. For example: if the italics character fontStyle is changed to oblique because that what the font has it sets it back to italic. Would there be a way to set it so that if the italics does exist in the character pallet then do not change it, else...?

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
Enthusiast ,
Apr 16, 2014 Apr 16, 2014

Copy link to clipboard

Copied

David, did not understand, what is your goal! Maybe it is to early in the morning or more information is needed 😉

If you make some changes to a part with a italic character style, you make some local overrides. If you run the script again, those characters will not be found anymore, because the fontstyle is not "italics" anymore.

But: If your apply your paragraph style, all overrides will be removed, and you get in the endresult: italics!

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 Beginner ,
Apr 17, 2014 Apr 17, 2014

Copy link to clipboard

Copied

Sorry for the confusion, thanks for replying back! I trying to learn scripting for indesign and its a steep curve, so thanks for any help.

Basically the issue is when a font typeface uses a different naming convention like, oblique, or 57 oblique instead of italics. After I run the script once and it creates the body paragraph style and the italics character style, I usually go into the paragraph style and change it to the font I need, if that font uses oblique instead of italics I have to go into the italics character style and change it to oblique. Now when I get some new text in, I select it and run the script, instead of just seeing that the italics style already exists and apply it, it sets it back to fontStyle italics and overrides the oblique change I made to the italics character style. I was just wondering if there is some way to keep my local oblique change to the italics character style when I process new text?

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
Enthusiast ,
Apr 17, 2014 Apr 17, 2014

Copy link to clipboard

Copied

I trying to learn scripting for indesign

me too

First of all, it is always a good idea, to know, what a script does. Second, it is a good idea, to have a good workflow. I’m not sure, if I would do it in your way, but let us find a solution for the first one:

The script does, what you have ordered: At first it stores your selection. Then it check, if the paragraph style and the character style is available. If not, the script will create them.

Here comes the problem: It does not matter, if the para- or characterStyle is in the document, in every case the font information is set to new values. So a solution might be to set the new values only if the styles are not in the document.

btw to your workflow: Instead of changing you styles by hand in the ui, you could also set those parameters in the script.

The following version will not set the attributes back, if you edit them once.

var curDoc = app.activeDocument;

var curSel = app.selection[0];

if (!curDoc.characterStyles.item("italic").isValid) {

    var cStyle = curDoc.characterStyles.add({name: "italic"});

    cStyle.fontStyle = "Italic";

}

else {

    var cStyle = curDoc.characterStyles.item("italic");

}

 

app.findGrepPreferences = app.changeGrepPreferences = null;

app.findGrepPreferences.fontStyle = "Italic";

app.changeGrepPreferences.appliedCharacterStyle = cStyle;

curSel.changeGrep();

if (!curDoc.paragraphStyles.item("body").isValid) {

    var pStyle = curDoc.paragraphStyles.add({name: "body"});

    with (pStyle) {

        appliedFont = "Myriad Pro\tRegular";

        pointSize = 11.5;

        fillColor = "Black";

    }

}

else {

    var pStyle = curDoc.paragraphStyles.item("body");

}

curSel.paragraphs.everyItem().appliedParagraphStyle = pStyle;

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 Beginner ,
Apr 17, 2014 Apr 17, 2014

Copy link to clipboard

Copied

So it works. So what you did was pull the style changes up into the if condition and that sets those parameter only if it doesn't exist?

You mention in your last post that you wouldn't do it this way, what changes would you make? I'm just curious to get a perspective on this.

Thanks again.

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
Enthusiast ,
Apr 17, 2014 Apr 17, 2014

Copy link to clipboard

Copied

LATEST

yes! If the style does not exist, create it and set the properties, else if the style exists simply use it.

To your second question: That depends really on your workflow: I would think that you have a template with your p and c styles and simply call them in the script. If you can define rules for your paragraphs and characters, you can apply more than "body" and "italic", for example headings, subheadings, headings between, bold, underline …

On the other hand: You could also define your styles in the script as shown in the part that begins with "with".

Whatever your solution is: I would never run a script and then change the attributes of paragraph and character styles later by hand. It should match either previously or the script should do that work.

best

Kai

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