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

Write Para and character styles in txt file

Community Beginner ,
Apr 18, 2016 Apr 18, 2016

Hi All,

I am very beginner in inDesign scripting and i just practicing the basic scripts.

i use the below code for collecting all the paragraph and character styling.

is this correct and secured way to collect all styles? can any one suggest me.

app.activeDocument.paragraphStyles.name;

app.activeDocument.characterStyles.name;

----

My Full script

var doc=app.activeDocument;

var docPath = doc.filePath.fsName;

var paraCount=doc.paragraphStyles.length;

var charcount=doc.characterStyles.length;

writeFile ();

function writeFile(){

var fh=File(docPath+"\\StyleList.txt");

fh.open("w");

if(fh!=-1){

//Paragraph style list Append

    var strgP="";

    for(var i=0; i < paraCount; i++){

        var k=i+1;

        var styleName = doc.paragraphStyles.name;

        strgP += "Para style No " +k +": "+styleName + "\n";

    }

//character style list append

    var strgC="";

    for(var i=0; i < charcount; i++){

        var k=i+1;

        var styleName = doc.characterStyles.name;

        strgC += "Char style No " +k +": "+styleName + "\n";

    }

    fh.write(strgP +"\n\n"+ strgC);

    fh.close();

    }

else{

    alert("Style file not created ...");

   }

}

Thanks in Advance,

Arasu

TOPICS
Scripting
564
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
Contributor ,
Apr 18, 2016 Apr 18, 2016

HI

Try this

var doc = app.activeDocument,

    Pstyles = doc.allParagraphStyles,

    report = "";

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

{

        report += Pstyles.name + "\r ";

    }

var file = new File(doc.fullName.toString().replace(".indd",".txt"));

file.open('w');

file.write(report);

file.close()

alert("Process Done");

/////////////////////////////

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
Guide ,
Apr 19, 2016 Apr 19, 2016

Hi Arasu,

Yes you are in the right track..

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 Beginner ,
Apr 19, 2016 Apr 19, 2016

Thank you so much tpk and Karthick...

Arasu

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
Advisor ,
Apr 19, 2016 Apr 19, 2016

Hi Arasu,

One approach is to use the doc.paragraphStyles

doc.paragraphStyles will return a collection of paragraph styles, so you can do fun things like:

var listOfNames=doc.paragraphStyles.everyItem().name.join('\n')

It does have one major disadvantage however: it will only return the root paragraph styles, and not the ones inside style groups.

The other approach is to use the doc.allParagraphStyles. This  will return all the paragraph styles in the document, regardless of their nesting, but has the disadvantage of being a plain array, so to do anything with it you will need to iterate through it (and since ExtendScript is based on JavaScript 1.5 you can't even use array.forEach).

The best approach depends on what exactly you need.

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 Beginner ,
Apr 19, 2016 Apr 19, 2016
LATEST

Thank you so much Vamitul .

Thanks,

Arasu

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