ドキュメントの全段落スタイルから正規表現スタイルを書き出す
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var doc = app.activeDocument; | |
var pst = doc.allParagraphStyles; | |
var len = pst.length; | |
var tgtFolder = Folder.selectDialog("書き出し先のフォルダを選択"); | |
for (var i=1; i<len; i++) { | |
if (pst[i].parent.constructor.name === "ParagraphStyleGroup") { | |
exportTxtFile(pst[i].parent.name+" >>> "+pst[i].name, getNestedStylesExp(pst[i])); | |
} else { | |
exportTxtFile(pst[i].name, getNestedStylesExp(pst[i])); | |
} | |
} | |
alert("done"); | |
function getNestedStylesExp(paraStyle) { | |
var res = []; | |
var nts = paraStyle.nestedGrepStyles; | |
for(var i=0; i<nts.length; i++) { | |
res.push(i+":\t"+nts[i].appliedCharacterStyle.name + "\t" + nts[i].grepExpression); | |
} | |
return res.join("\r"); | |
}; | |
function exportTxtFile(fileName, contents) { | |
var path = tgtFolder.fullName+"/"+fileName+".txt"; | |
var tgtFile = new File(path); | |
try { | |
tgtFile.open("w"); | |
tgtFile.encoding = "UTF-8"; | |
tgtFile.write(contents); | |
} catch(e) { | |
alert(e); | |
} finally { | |
tgtFile.close(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment