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

I want to get all paragraphs of a document

Guest
Dec 03, 2014 Dec 03, 2014

Hi ,

I want to get all paragraphs of a document(where document has table and cell and it contains some para as well)

Here is my script.

var objDoc = app.activeDocument;

var objDocName= objDoc.fullName.toString();

var par=objDoc.stories.everyItem().paragraphs.everyItem().getElements();

var paraLength=par.length;

$.writeln(paraLength);

                              for (j = 0; j < par.length; j++)

                              {

                               

                               

                                  $.writeln(j);

                                    var text =    par.contents;

                                  var endIP = par.insertionPoints.firstItem();

                                    var endTF = endIP.parentTextFrames[0];                           

                                    var endCitationPage = endTF.parentPage;       

                                    var index=endCitationPage.index;

                                    var offset=endCitationPage.documentOffset;

//~                                     $.writeln(text + "  Page : " + endCitationPage.name);

//~                                     $.writeln(index);

                    

                                    }

                                   

This script does not give me the text which is a part of  Cells.

Is there a property where we can get all the para from doc like :

var par=objDoc.paragraphs.everyItem().getElements();

TOPICS
Scripting
1.4K
Translate
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 , Dec 03, 2014 Dec 03, 2014

Try this,

var objDoc = app.activeDocument;

var par=objDoc.stories.everyItem().paragraphs.everyItem().getElements();

var paraLength=par.length;

$.writeln(paraLength);

var b = 0;

for (j = 0;j<par.length; j++)

{

        if(par.tables.length >=1)

        {

                var a = j;

                for(var i=0;i<par.tables.length;i++)

                {

                        var _cells = par.tables.cells;

                        for(var k=0;k<_cells.length;k++)

                        {

           

...
Translate
Enthusiast ,
Dec 03, 2014 Dec 03, 2014

Hi,

var curDoc = app.activeDocument;

// all paras in stories

var allStoryParas = curDoc.stories.everyItem().paragraphs.everyItem().getElements();

// all paras in tables

var allTableParas = curDoc.stories.everyItem().tables.everyItem().cells.everyItem().paragraphs.everyItem().getElements();

Notice, that you get also paras that hold the tables!

– Kai

Translate
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 ,
Dec 03, 2014 Dec 03, 2014

Or in a single line and getting a single array as a result:

var allStoryParas = curDoc.stories.everyItem().paragraphs.everyItem().getElements().concat(curDoc.stories.everyItem().tables.everyItem().cells.everyItem().paragraphs.everyItem().getElements());

(I think Marc or Peter K. suggested this for an extremely similar question.)

This will return all regular text, followed by all paragraphs that are in tables. It will not return text inside footnotes or in tables in tables ... or, for that matter, tables inside footnotes (and tables-in-tables-in-footnotes).

Apart from using Find to literally find all text, I don't know a reliable BUT fast way to get all text. Then again, to make further useful suggestions I think we need to know what the OP is going to do with 'all text'.

Translate
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
Guest
Dec 03, 2014 Dec 03, 2014

Thanks for your help

Translate
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
Guest
Dec 03, 2014 Dec 03, 2014

Thanks

Translate
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 ,
Dec 03, 2014 Dec 03, 2014

Try this,

var objDoc = app.activeDocument;

var par=objDoc.stories.everyItem().paragraphs.everyItem().getElements();

var paraLength=par.length;

$.writeln(paraLength);

var b = 0;

for (j = 0;j<par.length; j++)

{

        if(par.tables.length >=1)

        {

                var a = j;

                for(var i=0;i<par.tables.length;i++)

                {

                        var _cells = par.tables.cells;

                        for(var k=0;k<_cells.length;k++)

                        {

                                if(_cells.contents != "")

                                {

                                        $.writeln(a + k)

                                        b = k + 1;

                                    }

                            }

                    }

            }

        $.writeln(b + j);

        var text =    par.contents;

        var endIP = par.insertionPoints.firstItem();

        var endTF = endIP.parentTextFrames[0];                        

        var endCitationPage = endTF.parentPage;    

        var index=endCitationPage.index;

        var offset=endCitationPage.documentOffset;

    }

Regards,

Chinna

Translate
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
Guest
Dec 03, 2014 Dec 03, 2014

Thanks

Translate
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
Participant ,
Dec 08, 2014 Dec 08, 2014

Hi Chinnadk,

Could you please help with your solution? It is giving an error not visible for LearnIndesignScripting

Screen Shot 2014-12-08 at 05.09.00.jpg

Translate
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 ,
Dec 08, 2014 Dec 08, 2014

@camilo: Check whether all your text frames are placed in InDesign pages, if the frames are in the pasteboard it will return the index value as null.

You want to ignore the error, use try/catch function.

Vandy

Translate
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
Participant ,
Dec 08, 2014 Dec 08, 2014
LATEST

vandy, yes, after cleaning the pasteboard the script is not giving error although the output... where is placed?

I am assuming this script is intended to collect stories instead of using other traditional threading scripts that don't include cell items.

Thanks.

Translate
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