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

Apply conditions to text

Engaged ,
Apr 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

Hi everybody.

I have to change the design AND the content of some tables. The necessary part is done and works perfectly. Now I need two different conditions on parts of the content. In a cell there should come an URL with two endings. lets say: www.something.deat . Each of the endings needs its own condition.

That´s the code:

 

app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = "(?<=Druck- und Nebenkosten sowie weitere Farben: www.something\\.)de(?=at)";
app.changeGrepPreferences.appliedConditions = ["DE"]; 
app.changeGrep();
            
app.findGrepPreferences = NothingEnum.nothing; // Suchfeld leeren    
app.changeGrepPreferences = NothingEnum.nothing; // Ersetzen-Feld leeren     

app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = "(?<=Druck- und Nebenkosten sowie weitere Farben: www.something\\.de)at$";
app.changeGrepPreferences.appliedConditions = ["AT"]; 
app.changeGrep();

 

But this change all the endings in the entire document. How can I apply it only on the content of the selected text frame (containing a table)?

 

TOPICS
Scripting

Views

934

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 4 Correct answers

Community Expert , Apr 07, 2021 Apr 07, 2021

To answer to your first question, you would change "app.changeGrep()" to "app.selection[0].parentStory.changeGrep()" assuming a text frame is selected. 

Votes

Translate

Translate
Community Expert , Apr 07, 2021 Apr 07, 2021

"But this change all the endings in the entire document."

No. It will do the changes in all open documents!

 

With a selected text frame this could work; depending on its contents it could also throw an error:

app.selection[0].texts[0].changeGrep();

Would that cover the texts of all text cells of a given table in that selected text frame?

Just test it. Would it work in the GUI? No? Then select the table cells before running the GREP.

 

Better show a screenshot of your case where a text frame, a

...

Votes

Translate

Translate
Community Expert , Apr 10, 2021 Apr 10, 2021

To apply no conditions, use

app.changeGrepPreferences.appliedConditions = [];

 

Votes

Translate

Translate
Community Expert , Apr 10, 2021 Apr 10, 2021

An another strange thing is, that I can´t use variables for the conditions

 

Yes, you can:

app.changeGrepPreferences.appliedConditions = [myConditionDE, myConditionAT];

 

Votes

Translate

Translate
Engaged ,
Apr 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

The simple question is: how can these conditions be applied to part of a text? Text is written into a variable / constant, or it comes from it. How can you capture the endings and convert them into conditional text?

 

 

here the entire script:

 

 

var myDoc = app.documents[0]; 
var myPage = myDoc.pages[0]; 
 
var allSelection = myDoc.selection;
var mySelection = allSelection[0];
var numSelection = allSelection.length;
var arrayPageItems = app.activeDocument.pageItems.everyItem().getElements();

var PStyleGroup = myDoc.paragraphStyleGroups.itemByName('SF_Artikel_Tabellen');
var PStyleMenge = PStyleGroup.paragraphStyles.itemByName('SF_Tabellen_Menge');
var PStyleFuss = PStyleGroup.paragraphStyles.itemByName('SF_Tabellen_linkeSpalte');
var Fusszeile = "Druck- und Nebenkosten sowie weitere Farben: www.xxxxx.deat"

var CStyle = myDoc.cellStyles.itemByName('SF_Tabelle_Standard_Koerper');

auswahlCheck ();

function auswahlCheck () {
    if(allSelection.length == "0") {
        alert("Es wurde keine Auswahl getroffen!");
        exit(); //Abbruch
        } 
    
    for (var i=0; i < numSelection; i++) {
        if (!allSelection[i] instanceof TextFrame) {
            alert("Bitte wähle einen Textrahmen aus! " + allSelection[i] + " ist KEIN Textrahmen!");
            exit(); //Abbruch
            }
        else if (allSelection[i].tables.length < 1) {
            alert("Der Textrahmen beinhaltet keine Tabelle!");
            exit(); //Abbruch
            }
        }
    runAll();

function runAll() {
    for (var i=0; i < numSelection; i++) {
        myTable = allSelection[i].tables[0];
        clearOverrides();
        tableStyles();
    
     enableTextFrameAutoSizingOptions: true;
     allSelection[i].textFramePreferences.useNoLineBreaksForAutoSizing = true;
     allSelection[i].textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_ONLY;
     allSelection[i].textFramePreferences.autoSizingReferencePoint = AutoSizingReferenceEnum.TOP_CENTER_POINT;    }    
}

function clearOverrides() {
    for (n=0; n < myTable.rows.length; n++) {
        for (i=0; i < myTable.rows[n].cells.length; i++) {
                myTable.rows[n].cells[i].clearCellStyleOverrides(false);//Alle Zellen-Formate löschen
                myTable.rows[n].cells[i].paragraphs.everyItem().clearOverrides(OverrideType.ALL);//Alle Absatz-Formate löschen
                myTable.rows[n].cells[i].texts[0].clearOverrides(OverrideType.ALL);
            }
    }
}

function tableStyles() {
    var TStyle = myDoc.tableStyles.itemByName('SF_Tabelle_Basis');
    myTable.appliedTableStyle = TStyle;
   
   var myFirstRow = myTable.rows[0];  
    var myLastRow = myTable.rows[-1];  

    var meineMenge = myFirstRow.cells.firstItem().paragraphs[0];
        meineMenge.appliedParagraphStyle = PStyleMenge;
     
    if(myFirstRow.rowType != RowTypes.HEADER_ROW){
        myFirstRow.rowType = RowTypes.HEADER_ROW;
        }

if(myLastRow.cells.length > 1){
        myLastRow.cells.everyItem().appliedCellStyle = CStyle;
        myLastRow.cells.firstItem().paragraphs[0].appliedParagraphStyle = PStyleFuss;
       
        }else{
            myLastRow.cells.firstItem().contents = Fusszeile;}
            applyCondition();        
    }

function applyCondition() {
myConditionDE = app.activeDocument.conditions.item("DE");
myConditionAT = app.activeDocument.conditions.item("AT");

if (!myConditionDE.isValid) {
    myConditionDE = app.activeDocument.conditions.add ({name:"DE",
    indicatorMethod:ConditionIndicatorMethod.USE_HIGHLIGHT, indicatorColor:UIColors.BLUE});
}

if (!myConditionAT.isValid) {
    myConditionAT = app.activeDocument.conditions.add ({name:"AT",
    indicatorMethod:ConditionIndicatorMethod.USE_HIGHLIGHT, indicatorColor:UIColors.RED, visible:false});
}

app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = "(?<=Druck- und Nebenkosten sowie weitere Farben: www.xxxxxx\\.)de(?=at)";
app.changeGrepPreferences.appliedConditions = ["DE"]; 
app.changeGrep();
            
app.findGrepPreferences = NothingEnum.nothing; // Suchfeld leeren    
app.changeGrepPreferences = NothingEnum.nothing; // Ersetzen-Feld leeren     

app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = "(?<=Druck- und Nebenkosten sowie weitere Farben: www.xxxxxx\\.de)at$";
app.changeGrepPreferences.appliedConditions = ["AT"]; 
app.changeGrep();

myDoc.conditions.itemByName("DE").visible = false;
myDoc.conditions.itemByName("DE").visible = true;
    }

function objectFormat() {
    myTable.parent.appliedObjectStyle = objForm;
    }
}

 

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
Explorer ,
Apr 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

Hi, cmoke:

 

In the example script "FindChangeByList.jsx" installed with my InDesign CS5.5 I see that the find/replace operation can be restricted to coincidences of CharacterStyles. Maybe you can search throught a specific character style used only in your tables with the property "appliedCharacterStyle", a property of "changeGrepPreferences".

 

This is a bit confusing to me (tables and conditions) so this is an approach according to my level.

 

Good luck!

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
Engaged ,
Apr 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

maybe that could be a way to the solution. But I need only two characters (or: two times two characters)  to apply the condition.

thanks anyway

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 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

To answer to your first question, you would change "app.changeGrep()" to "app.selection[0].parentStory.changeGrep()" assuming a text frame is selected. 

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
Engaged ,
Apr 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

Okay, it seems to be what I imagined. But how do you get just the characters you need ("de" and "at")? They are part of the content of my footer: www.xxxxxxxxx.deat

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 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

"But this change all the endings in the entire document."

No. It will do the changes in all open documents!

 

With a selected text frame this could work; depending on its contents it could also throw an error:

app.selection[0].texts[0].changeGrep();

Would that cover the texts of all text cells of a given table in that selected text frame?

Just test it. Would it work in the GUI? No? Then select the table cells before running the GREP.

 

Better show a screenshot of your case where a text frame, a text or table cells are selected.

And if a table is involved please indicate if the table rows are running through different text frames.

 

Thanks,
Uwe Laubender

( ACP )

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
Engaged ,
Apr 09, 2021 Apr 09, 2021

Copy link to clipboard

Copied

Hello guys.

 

and thank you for the paticipation and the answers.

Sorry for being abcent for a while. The issue is still current. But now I have an other problem with my scripts. More urgent. I work on two platforms:  in the office with Mac, at homeoffice on Windows. Now I have the problem, that the script I made in the office and worked well, now it doesn´t work on my Windows-PC.

This one will be continued after the new one is solved.

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
Engaged ,
Apr 10, 2021 Apr 10, 2021

Copy link to clipboard

Copied

Okay, I´ve got it:

 

        app.findGrepPreferences = NothingEnum.nothing;
        app.changeGrepPreferences = NothingEnum.nothing;
        app.findGrepPreferences.findWhat = "^.+$";
        app.changeGrepPreferences.appliedConditions = ["[Ohne Bedingung]"]; 
        app.selection[i].tables[0].rows[-1].changeGrep();
                     
        app.findGrepPreferences = NothingEnum.nothing; // Suchfeld leeren    
        app.changeGrepPreferences = NothingEnum.nothing; // Ersetzen-Feld leeren            
                    
        app.findGrepPreferences = NothingEnum.nothing; // Suchfeld leeren    
        app.changeGrepPreferences = NothingEnum.nothing; // Ersetzen-Feld leeren    
        app.findGrepPreferences = NothingEnum.nothing;
        app.changeGrepPreferences = NothingEnum.nothing;
        app.findGrepPreferences.findWhat = "(?<=www.xxxxx.)de";
        app.changeGrepPreferences.appliedConditions = ["DE"]; 
        app.selection[i].tables[0].rows[-1].changeGrep();
                    
        app.findGrepPreferences = NothingEnum.nothing; // Suchfeld leeren    
        app.changeGrepPreferences = NothingEnum.nothing; // Ersetzen-Feld leeren     
        
        
        app.findGrepPreferences = NothingEnum.nothing;
        app.changeGrepPreferences = NothingEnum.nothing;
        app.findGrepPreferences.findWhat = "(?<=www.xxxx.de)at";
        app.changeGrepPreferences.appliedConditions = ["AT"]; 
        app.selection[i].tables[0].rows[-1].changeGrep();
                    
        app.findGrepPreferences = NothingEnum.nothing; // Suchfeld leeren    
        app.changeGrepPreferences = NothingEnum.nothing; // Ersetzen-Feld leeren  


        myDoc.conditions.itemByName("AT").visible = true;
        myDoc.conditions.itemByName("AT").visible = false;

 

... except to apply "no condition" to a text. In german its name is "Keine Bedingung", but it doesn´t recognize it.

 

An another strange thing is, that I can´t use variables für the conditions name like:

        myConditionDE = app.activeDocument.conditions.item("DE");
        myConditionAT = app.activeDocument.conditions.item("AT");
        myConditionNoCond = app.activeDocument.conditions.item("Ohne Bedingung");

 😞

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 10, 2021 Apr 10, 2021

Copy link to clipboard

Copied

To apply no conditions, use

app.changeGrepPreferences.appliedConditions = [];

 

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 10, 2021 Apr 10, 2021

Copy link to clipboard

Copied

An another strange thing is, that I can´t use variables for the conditions

 

Yes, you can:

app.changeGrepPreferences.appliedConditions = [myConditionDE, myConditionAT];

 

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
Engaged ,
Apr 10, 2021 Apr 10, 2021

Copy link to clipboard

Copied

Thank you Peter.

It's the correct answer, but I can't mark it for the question above. 🙂

 

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 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

LATEST

I did it for you.

 

Best,
Uwe Laubender

( ACP )

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