Skip to main content
Known Participant
August 3, 2022
Answered

Write the styleExportTagMap to a text file

  • August 3, 2022
  • 1 reply
  • 444 views

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(). 

This topic has been closed for replies.
Correct answer brian_p_dts

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

 

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

 


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!"; } 

1 reply

brian_p_dts
Community Expert
Community Expert
August 3, 2022

Assuming each style has only one tag map: 

file.write(a.name+'\t'+a.styleExportTagMaps[0].class+'\n');
IowaBoy9Author
Known Participant
August 3, 2022

Thanks brianp311

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

 

IowaBoy9Author
Known Participant
August 3, 2022

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

 

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