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

Find string of paragraph numbering

Explorer ,
Sep 21, 2018 Sep 21, 2018

Copy link to clipboard

Copied

So I've made a script to change data in multiple tables. I want to target each table by looking for an index-number. This index-number is generated with a Paragraph Style Bullets & numberings (then using just a space to print that) inside a table cell. I wonder, is there anyway to actually target that value?

Here's a rough example:

Table oneindex_0
Value 1value 2
Value 3Value 4

Table Twoindex_1
Value 1value 2
Value 3Value 4

Here's my code that works with normal text in a cell:

app.findGrepPreferences.findWhat = "index_0"; // Find table with index 

TOPICS
Scripting

Views

939

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

Explorer , Sep 24, 2018 Sep 24, 2018

Here's a full example of my code (more items in wee though, just left two in there, will that help?

var week_2020_1 = {

    index: "item_0",

week: "Vecka 1",

    month: "December",

    year: "2020",

    monday: {

        date: "31",

        spec: "NyÃ¥rsafton",

        name: "Sylvester",

        holiday: true

    },

    tuesday: {

        date: "01",

        spec: "NyÃ¥rsdagen",

        name: "",

        holiday: true

    },

    wednesday: {

        date: "02",

        spec: "",

        name: "Svea",

        holiday: f

...

Votes

Translate

Translate
Guide ,
Sep 21, 2018 Sep 21, 2018

Copy link to clipboard

Copied

Hi,

… For doing what after? …

Best,

Michel, for 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
Explorer ,
Sep 23, 2018 Sep 23, 2018

Copy link to clipboard

Copied

Well, it doesn't really matter for the question in hand, but to match tables with an array of variables and then inserting them as data in the tables.

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 ,
Sep 24, 2018 Sep 24, 2018

Copy link to clipboard

Copied

Carl,

Give a sample with screenshots!! Thanks! …

Best,

Michel

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 ,
Sep 24, 2018 Sep 24, 2018

Copy link to clipboard

Copied

Here's a full example of my code (more items in wee though, just left two in there, will that help?

var week_2020_1 = {

    index: "item_0",

week: "Vecka 1",

    month: "December",

    year: "2020",

    monday: {

        date: "31",

        spec: "NyÃ¥rsafton",

        name: "Sylvester",

        holiday: true

    },

    tuesday: {

        date: "01",

        spec: "NyÃ¥rsdagen",

        name: "",

        holiday: true

    },

    wednesday: {

        date: "02",

        spec: "",

        name: "Svea",

        holiday: false

    },

    thursday: {

        date: "03",

        spec: "",

        name: "Alfred, Alfrida",

        holiday: false

    },

    friday: {

        date: "04",

        spec: "",

        name: "Rut",

        holiday: false

    },

    saturday: {

        date: "05",

        spec: "",

        name: "Hanna, Hannele",

        holiday: false

    },

    sunday: {

        date: "06",

        spec: "",

        name: "Kasper, Melker, Baltsar",

        holiday: true

    }

}

var week_2020_2 = {

    index: "item_1",

week: "Vecka 2",

    month: "Januari",

    year: "2020",

    monday: {

        date: "07",

        spec: "",

        name: "August, Augusta",

        holiday: false

    },

    tuesday: {

        date: "08",

        spec: "",

        name: "Erland",

        holiday: false

    },

    wednesday: {

        date: "09",

        spec: "",

        name: "Gunnar, Gunder",

        holiday: false

    },

    thursday: {

        date: "10",

        spec: "",

        name: "Sigurd, Sigbritt",

        holiday: false

    },

    friday: {

        date: "11",

        spec: "",

        name: "Jan, Jannike",

        holiday: false

    },

    saturday: {

        date: "12",

        spec: "",

        name: "Frideborg, Fridolf",

        holiday: false

    },

    sunday: {

        date: "13",

        spec: "",

        name: "Knut",

        holiday: true

    }

}

var weeks = {

    item_0: week_2020_1,

    item_1: week_2020_2,

}

for (var item in weeks) {

//alert(weeks[item]['week']);

//updateWeekTablesData(weeks[item]);

insertWeekTablesData(weeks[item]);

}

/* UPDATE WEEK TABLES */

function updateWeekTablesData(itemData) {

app.findGrepPreferences = app.changeGrepPreferences =null;

app.findGrepPreferences.findWhat = itemData["index"]; // Find table with index    

var found = app.documents[0].findGrep();

for(i=0; i<found.length; i++)

{

    if(found.contents)

    {

  

    found.select();

    alert(found.contents);

    replaceData();

    }  

}

app.findGrepPreferences = app.changeGrepPreferences =null;

  

  

function replaceData() {

    var source = app.selection[0].parent.parentColumn;

    var table = source.parent; //Target table of selection

function newMonthData(newMonth, newYear) {

//ri = row index

//ci = column index

var tableCell = {

    month : table.rows[1].cells[10],

    year : table.rows[1].cells[11],

    }

    tableCell["month"].texts[0].contents = newMonth;

tableCell["year"].texts[0].contents = newYear;

    return newMonthData;

}

var monthyear = newMonthData(itemData["month"], itemData["year"]);

function newDayData(ri, ci, newDate, newSpec, newName, holiday) {

//ri = row index

//ci = column index

var tableCell = {

    date : table.rows[0 + ri].cells[0 + ci],

    day : table.rows[1 + ri].cells[0 + ci],

spec : table.rows[0 + ri].cells[1 + ci],

name : table.rows[1 + ri].cells[1 + ci]

    }

    tableCell["date"].texts[0].contents = newDate;

tableCell["spec"].texts[0].contents = newSpec;

tableCell["name"].texts[0].contents = newName;

if (holiday == true) {

tableCell["date"].appliedCellStyle = "date-holiday";

tableCell["day"].appliedCellStyle = "day-holiday";

} else {

tableCell["date"].appliedCellStyle = "date";

tableCell["day"].appliedCellStyle = "day";

}

if (newDate == itemData["sunday"]["date"] || newDate == itemData["saturday"]["date"]) {

tableCell["spec"].texts[0].contents = newName;

tableCell["name"].texts[0].contents = newSpec;

}

    return newDayData;

}

var monday = newDayData(0, 0, itemData["monday"]["date"], itemData["monday"]["spec"], itemData["monday"]["name"], itemData["monday"]["holiday"]);

var tuesday = newDayData(0, 2, itemData["tuesday"]["date"], itemData["tuesday"]["spec"], itemData["tuesday"]["name"], itemData["tuesday"]["holiday"]);

var wednesday = newDayData(0, 4, itemData["wednesday"]["date"], itemData["wednesday"]["spec"], itemData["wednesday"]["name"], itemData["wednesday"]["holiday"]);

var thursday = newDayData(0, 6, itemData["thursday"]["date"], itemData["thursday"]["spec"], itemData["thursday"]["name"],itemData["thursday"]["holiday"]);

var friday = newDayData(0, 8, itemData["friday"]["date"], itemData["friday"]["spec"], itemData["friday"]["name"], itemData["friday"]["holiday"]);

var saturday = newDayData(2, 0, itemData["saturday"]["date"], itemData["saturday"]["spec"], itemData["saturday"]["name"], itemData["saturday"]["holiday"]);

var sunday = newDayData(4, 0, itemData["sunday"]["date"], itemData["sunday"]["spec"], itemData["sunday"]["name"], itemData["sunday"]["holiday"]);

}

}

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 ,
Sep 24, 2018 Sep 24, 2018

Copy link to clipboard

Copied

The first step in your script would be to replace the automatic paragraph numbers with literal text. Something like this (Select the frame that contains the table):

cells = app.selection[0].tables[0].cells.everyItem().getElements();

for (i = 0; i < cells.length; i++) {

  if (cells.paragraphs[0].bulletsAndNumberingListType == ListType.NUMBERED_LIST) {

    cells.paragraphs[0].contents = cells.paragraphs[0].bulletsAndNumberingResultText;

  }

}

Then disable automatic paragraph numbering in the paragraph style. Maybe another approach is more efficient, depends on what your table looks like.

P.

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 ,
Oct 02, 2018 Oct 02, 2018

Copy link to clipboard

Copied

So, there's no way to actually search the output of a numbered list without converting it?
I'll try this and see if it works alright

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 ,
Oct 02, 2018 Oct 02, 2018

Copy link to clipboard

Copied

LATEST

I don't understand how your marked self-answer answers the question. To check, I attempted to run your script but I don't see what it should be run on.

What does "search the output of a numbered list without converting it" mean? If you have a numbered list "1, 2, 3" and you want to search for "2", yeah, that won't work. But you can iterate over the list and inspect their "bulletsAndNumberingResultText". Basically, what Peter said two weeks ago.

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 ,
Sep 21, 2018 Sep 21, 2018

Copy link to clipboard

Copied

Use the paragraph's bulletsAndNumberingResultText property.

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 ,
Sep 23, 2018 Sep 23, 2018

Copy link to clipboard

Copied

Sorry, pretty new to inDesign-scripting could you give a code example please?

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 ,
Oct 02, 2018 Oct 02, 2018

Copy link to clipboard

Copied

I used code above, but used a GREP-search instead:

f

unction convertIndexToString () {

app.findGrepPreferences = app.changeGrepPreferences = null;

app.findGrepPreferences.findWhat = "\\b\\w+?\\b";

app.findGrepPreferences.appliedParagraphStyle = "vecka.index";

indexFound = app.activeDocument.findGrep();

if (indexFound) {

for (f = 0; f < indexFound.length; f++ ) {

          thisItem = indexFound;

               if (thisItem.paragraphs[0].bulletsAndNumberingListType == ListType.NUMBERED_LIST) {

                   thisItem.paragraphs[0].contents = thisItem.paragraphs[0].bulletsAndNumberingResultText;

              }

           }

     }

}

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