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

extract paragraph style name with formating

Contributor ,
Apr 08, 2014 Apr 08, 2014

Copy link to clipboard

Copied

All

kindly help me How to extract ParagraphStyle name with formating to Sample.txt:

EG:

Style Name: "Body"

Font = "15"

leading = '"18"

Aligh = "Left"

etc...

Regards

Hurix

Edit by Dave Saunders: Something is preventing the Reply button from working. I'm hoping this edit will reactivate it.

TOPICS
Scripting

Views

1.9K

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

Guru , Apr 23, 2014 Apr 23, 2014

Hi Hurix,

Welcome back.

Please mark the the question as answered

Add the properties you need as instructed in the 3rd line.

Trevor

// Export Specified Details of Documents ParagraphStyles By Trevor

// http://forums.adobe.com/thread/1445961?tstart=0

exportParagraphStyleDetails ("appliedFont pointSize spaceAfter spaceBefore"); // add property names separated by a space - The Style Name is included automatically

// see http://jongware.mit.edu/idcs6js/pc_ParagraphStyle.html for a list of properties you can

...

Votes

Translate

Translate
Advocate ,
Apr 08, 2014 Apr 08, 2014

Copy link to clipboard

Copied

OK, that worked.

Hurix,

Can you say a little more: which scripting language do you use? How experienced are you?

When you say "How to extract ParagraphStyle name" what do you mean? Extract from where? I'm guessing the selected text.

Where do you want Sample.txt to be? On your desktop? In the same folder as your document? What if the document is unsaved?

Dave

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
Contributor ,
Apr 09, 2014 Apr 09, 2014

Copy link to clipboard

Copied

Hi Dave

I am using JavaScript.

And my Script is in Below:

var myDoc = app.activeDocument;

var myStyle = myDoc.paragraphStyles.everyItem().name.join("\n");

//fso = new ActiveXObject("Scripting.FileSystemObject");

for(var i= myStyle;i<myStyle.length;i++);

var filePath = "/Users/hpt/Desktop/In/style.txt";

var logFile = new File(filePath);

Paragraph Style Naming Like: "Body text, BL, NL, CT, CN, etc...." I will get separate text file.

Now am looking for get including with Formatting:

Eg: Body Text, Font:Minion, Face:Bold, Size:15, Leading:18, etc...

it is possible,

Just like export snippets.

Hurix

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
Advocate ,
Apr 10, 2014 Apr 10, 2014

Copy link to clipboard

Copied

Yes, you can do what you want. But your sample has a couple of problems:

  1. Because you joined all the paragraph styles together into a single string, you can use its length to control the for loop. The length of a string is the number of characters in the string.
  2. You only need to create the file once, so do it before the for-loop.
  3. You need to enclose the content of the for-loop in braces.

I have the impression you want to work this out for your self rather than just have someone write a script for you, so here's how I'd go about it:

  1. I'd make use of JavaScript's toSource() feature to get the values into a string for writing to the file.
  2. But, myParagraphStyle.toSource() produces too much information.
  3. So, I'd create a new object with just the properties of interest and populate that from each paragraph style then use toSource to write that to the file.

Hope this helps.

Dave

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
Contributor ,
Apr 10, 2014 Apr 10, 2014

Copy link to clipboard

Copied

Thank you Dave

As per your above guidance i make an effort in my Javscript File. But it shows undefine is not an object.

"if(myStyle.properties.toSource()){

for loop

...

}

can you please suggest me

hurix

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
Advocate ,
Apr 10, 2014 Apr 10, 2014

Copy link to clipboard

Copied

I have appointments for the rest of the morning so I won't be able to help until this afternoon at the earliest (I'm in New Jersey).

Dave

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
Guru ,
Apr 10, 2014 Apr 10, 2014

Copy link to clipboard

Copied

Hi all,

This is something I threw together

doc = app.activeDocument,

ps = doc.paragraphStyles.everyItem().getElements().slice(0),

l = ps.length,

paraStyles = [],

c = 0;

while (l--) {

    var styleDetails = [], n = 0, s, x, p, q;

    s = ps.properties;

    for (x in s) {

        p = (s && s.hasOwnProperty ("name")) ? s.name : s; // change according to requirements.

        if (p && p.constructor.name == "String") p = '"' + p +'"'; // ok if the sctring doesn't contain a " mark

        else if (x == "tabList") p = getTabList (s);

        else if (p instanceof Object && p.constructor.name != "Enumerator") {

            var objProps = [], z = 0;

            for (q in p) objProps[z++] = q + ": " + p

            p = x + " {" + objProps.join(", ") + "}";

        }

        styleDetails[n++] = x + ": " + p;

    }

    paraStyles[c++] = "{" + styleDetails.join(", ") + "}";

}

temp = new File (Folder (Folder.temp) + "/" + doc.name + " Paragraph Style Properties  " + ("" + new Date).replace(/:/g,"\xB7").replace(/\s\S+$/,"")+ ".txt");

temp.encoding = "UTF-8";

temp.lineFeed = ($.os[0]=="M") ? "Macintosh" :" Windows";

temp.open('w');

temp.write("\uFEFF" + paraStyles.join("\r"));

temp.close();

$.sleep(300);

temp.execute(true);

function getTabList (t) {

    var tl = t.length, n, pTabList = [];

    for (n = 0; n < tl; n++) { // if the leader etc. contains a " then you have to use ' instead of "

        pTabList = "({alignment: " + t.alignment + ', alignmentCharacter: "' + t.alignmentCharacter + '", leader: "' +t.leader +  '", position: ' + t.position + "})";

    }

    return "[" + pTabList.join(", ") + "]";

}

function getGrepList (g) { // nestedGrepStyles

    return // couldn't be bothered to do this one, sorry

    var tl = g.length, n, pnestedGrepList = [];

    for (n = 0; n < tl; n++) { // if the leader etc. contains a " then you have to use ' instead of "

        // pTabList = figure for yourself

    }

    return "[" + pTabList.join(", ") + "]";

}

You can then recreate the styles by splitting the string by "\r" and using doScript or Eval.

Might be better to produce a tagged doc with <alignment> foo </alignment> type structure to get around quotation porblems

However for a simple import export snippet wouldn't this be better?

var doc = app.activeDocument,

      newDoc = app.documents.add(),

      fp;

     

// if you need to add function to remove app.styles that are automatically added to the new document

fp = new File (Folder.temp + "/" + +new Date + ".indd")

doc.saveACopy (fp);

$.sleep (500);

newDoc.importStyles (ImportFormat.TEXT_STYLES_FORMAT, fp); // can add all sorts of things to import or load

fp.remove();

// You now have a clean new Document to load the styles from using importStyles

Trevor

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
Guru ,
Apr 10, 2014 Apr 10, 2014

Copy link to clipboard

Copied

Another possibility generate a tagged txt file.

Probably the best and easiest method.  The styles will be ready to regenerate when needed.

app.doScript("exportParaStyleData ()", ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "exportParaStyleData");

function exportParaStyleData() {

        var doc = app.activeDocument,

          newPage = doc.pages.add(),

          paraStyles = doc.paragraphStyles.everyItem().getElements().slice(0),

          l = paraStyles.length,

          tf = newPage.textFrames.add({geometricBounds: newPage.bounds, contents: new Array(l+1).join("\r")}),

          f = new File (Folder.temp + "/" + +new Date + ".txt") /*change as needed*/;

    while (l--) tf.characters.appliedParagraphStyle = paraStyles;

    app.taggedTextExportPreferences.properties = {characterSet: TagTextExportCharacterSet.ASCII /*change as needed*/, tagForm: TagTextForm.VERBOSE};

    tf.texts[0].exportFile (ExportFormat.TAGGED_TEXT, f, false);

    newPage.remove();

    f.execute();

}

Sample Result, quite neat

<ASCII-WIN>

<Version:9.2><FeatureSet:InDesign-R2L><ColorTable:=<Black:COLOR:CMYK:Process:0,0,0,1><C\=15 M\=100 Y\=100 K\=0:COLOR:CMYK:Process:0.15,1,1,0>>

<DefineCharStyle:Character Style 1=<Nextstyle:Character Style 1><cTypeface:Regular><cFont:Action Jackson>>

<DefineParaStyle:NormalParagraphStyle=<Nextstyle:NormalParagraphStyle>>

<DefineParaStyle:Page Numbers=<Nextstyle:Page Numbers><cSize:6.500000><pTextComposer:HL Single><pLeftIndent:5.112000><pRightIndent:5.112000><cLeading:7.475000><pBreakBefore:Column><pTextAlignment:Center><bnColor:None><numFont:\<TextFont\>><cHindiDigits:Arabic>>

<DefineParaStyle:fred=<Nextstyle:fred><cLanguage:English\: UK><pTabRuler:52\,Center\,.\,0\,3\;112\,Center\,.\,0\,\;190\,Left\,.\,0\,\;><cFont:Minion Pro><pRunInGrepStyles:Character Style 1\,\\d\+\"\[\"\]\;><bnListType:Bullet>>

<DefineParaStyle:Paragraph Style 1=<BasedOn:fred><Nextstyle:Paragraph Style 1><cColor:C\=15 M\=100 Y\=100 K\=0><cColorTint:100.000000>>

<ParaStyle:>

<ParaStyle:NormalParagraphStyle>

Trevor

P.s. Let us know what you went for, I would go for the tagged one

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
Contributor ,
Apr 20, 2014 Apr 20, 2014

Copy link to clipboard

Copied

Thanks for your reply

It Works, But i need to generate selected elements only,

Like: Style Name, Font, size, Space Before and After, etc.

Hurix

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
Guru ,
Apr 23, 2014 Apr 23, 2014

Copy link to clipboard

Copied

LATEST

Hi Hurix,

Welcome back.

Please mark the the question as answered

Add the properties you need as instructed in the 3rd line.

Trevor

// Export Specified Details of Documents ParagraphStyles By Trevor

// http://forums.adobe.com/thread/1445961?tstart=0

exportParagraphStyleDetails ("appliedFont pointSize spaceAfter spaceBefore"); // add property names separated by a space - The Style Name is included automatically

// see http://jongware.mit.edu/idcs6js/pc_ParagraphStyle.html for a list of properties you can add

function exportParagraphStyleDetails (props /* A string list of the desired properties */) {

    doc = app.activeDocument,

    ps = doc.paragraphStyles.everyItem().getElements().slice(0),

    l = ps.length,

    c = 0;

    props = props.replace(/\s+/g, " ").split(" ");

    pl = props.length;

        var styleDetails = [];

    while (l--) {

        var  myStyle = ps;

        styleDetails[c++] = "******************************************************************\rParagraph Style Name: " + myStyle.name + "\r******************************************************************"

        for (var n = 0; n < pl; n++) {

            styleDetails = props + ": " + myStyle[props].toString();

            if (myStyle[props].hasOwnProperty ("name")) styleDetails = styleDetails.replace (/:.+/, ".name: " + myStyle[props].name);

            c++;

        }

    styleDetails[c++] = "\r";

    }

    temp = new File (Folder (Folder.temp) + "/" + doc.name + " Paragraph Style Properties " + ("" + new Date).replace(/:/g,"\xB7").replace(/G\S+$/,"")+ ".txt");

    temp.encoding = "UTF-8";

    temp.lineFeed = ($.os[0]=="M") ? "Macintosh" :" Windows";

    temp.open('w');

    temp.write("\uFEFF" + styleDetails.join("\r"));

    temp.close();

    $.sleep(300);

    temp.execute();

}

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