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

Write the styleExportTagMap to a text file

Community Beginner ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

I am attempting to write the paragraph style name and its class as defined in the styleExportTagMap of all paragraphs in a document. Here is my javascript so far:
var path = '~/00_temp/';
var filename = 'styleMap.txt';

//Create File object
var file = new File(path + filename);
file.encoding = 'UTF-8';
file.open('w');

//gather data and write it to file
var ps = app.documents[0].allParagraphStyles
while(a = ps.pop())
file.write(a.name+'\t'+a.styleExportTagMaps.toSource()+'\n');

file.close();

 

Here is the line for the paragraph style TEXT_First_ParaDropCap

TEXT_First_ParaDropCap resolve("/document[@id=4]//paragraph-style[@id=291]/style-export-tag-map")

 

What I desire is Something like this:

 

TEXT_First_ParaDropCap class: body_dropCap 


I will be up front. I am not sure how to manage toSource(). 

TOPICS
EPUB , Scripting

Views

166

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

Community Expert , Aug 03, 2022 Aug 03, 2022

My bad, yes exportClass. You probably got an Object is Invalid error, which you would see if no export tag/class was applied. 

Wrap it in a try/catch: 

try { file.write(a.name+'\t'+a.styleExportTagMaps[0].exportClass+'\n'); }
catch(e) { file.write(a.name + "\tNo export tag applied!"; } 

Votes

Translate

Translate
Community Expert ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

Assuming each style has only one tag map: 

file.write(a.name+'\t'+a.styleExportTagMaps[0].class+'\n');

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 Beginner ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

Thanks brianp311

I get a error: Object does not support the property or method 'class'. 

 

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 Beginner ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

I tried replacing .class with .exportClass and receive the same error.

 

file.write(a.name+'\t'+a.styleExportTagMaps[0].exportClass+'\n');

 

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 ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

My bad, yes exportClass. You probably got an Object is Invalid error, which you would see if no export tag/class was applied. 

Wrap it in a try/catch: 

try { file.write(a.name+'\t'+a.styleExportTagMaps[0].exportClass+'\n'); }
catch(e) { file.write(a.name + "\tNo export tag applied!"; } 

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 Beginner ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

LATEST

Thanks. That worked. You missed the closing parenthesis in the catch(e). Otherwise. Perfect! Thanks again.

{ file.write(a.name + "\tNo export tag applied!"); } 

 

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