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.
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
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
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
Copy link to clipboard
Copied
Yes, you can do what you want. But your sample has a couple of problems:
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:
Hope this helps.
Dave
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
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
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
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
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
Copy link to clipboard
Copied
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();
}