- 精华
- 活跃值
-
- 积分
- 232
- 违规
-
- 印币
-
- 鲜花值
-
- 在线时间
- 小时
累计签到:11 天 连续签到:1 天
|
- //0ne or two level TOC contents CharacterStyle.js
- //one level: only need select *[None]* CharacterStyle in the 2nd dialogs.
- myDocument = app.documents[0];
- myAllCharaStyleNames = myDocument.characterStyles.everyItem().name;
- //Create 1st dialog.
- var myDialog = app.dialogs.add({name:"TOC 1st Level CharacterStyle",canCancel:true});
- with(myDialog){
- with(dialogColumns.add()){
- staticTexts.add({staticLabel:"TOC 1st Level CharacterStyle"});
- staticTexts.add({staticLabel:"Select OneOfAll"});
- my1stCharaStyleDropdown = dropdowns.add({stringList:myAllCharaStyleNames, selectedIndex:1, minWidth:150});
- }
- }
- if(myDialog.show() == true){
- my1stCharaStyle = myAllCharaStyleNames[my1stCharaStyleDropdown.selectedIndex];
- for(s =0; s<=myDocument.stories.length-1; s++){
- myStory = myDocument.stories[s];
- if(myStory.characters.length !=0){
- myStory.insertionPoints[-1].contents = SpecialCharacters.emSpace; //" "
- myStory.characters[-1].appliedCharacterStyle = myDocument.characterStyles.item(my1stCharaStyle);
- }
- }
- app.findPreferences = NothingEnum.nothing;
- app.changePreferences = NothingEnum.nothing;
- app.findPreferences.appliedCharacterStyle = myDocument.characterStyles.item(my1stCharaStyle);
- myCharaFound = myDocument.search("", false, false,undefined);
- ////Create 2nd dialog.
- try{
- myDocument.characterStyles.item("[None]").name;
- }
- catch(e){
- myNoneCharaStyle = myDocument.characterStyles.add({name:"[None]"});
- }
- myAllCharaStyleNames = myDocument.characterStyles.everyItem().name;
- //myNoneCharaStyle.name = "[None]";
- var myDialog1 = app.dialogs.add({name:"TOC 2nd Level CharacterStyle",canCancel:true});
- with(myDialog1){
- with(dialogColumns.add()){
- staticTexts.add({staticLabel:"TOC 2nd Level CharacterStyle"});
- staticTexts.add({staticLabel:"Select OneOfAll"});
- my2ndCharaStyleDropdown = dropdowns.add({stringList:myAllCharaStyleNames, selectedIndex:1, minWidth:150});
- }
- }
- if(myDialog1.show() == true){
- my2ndCharaStyle = myAllCharaStyleNames[my2ndCharaStyleDropdown.selectedIndex];
- app.findPreferences = NothingEnum.nothing;
- app.changePreferences = NothingEnum.nothing;
- app.findPreferences.appliedCharacterStyle = myDocument.characterStyles.item(my2ndCharaStyle);
- }
- else{
- myDialog1.destroy();
- }
- //
- myTocLine = new Array;
- myTocLine_ = new Array;
- myParseInt = new Array;
- var myCharaContent, myCharaPageNumber, myLine;
- for(chara=myCharaFound.length-1; chara>=0; chara--){
- myChara = myCharaFound[chara];
- myCharaContentX = myChara.contents;
- try{
- A = /\r/gm;
- myCharaContent = myCharaContentX.replace(A, "");
- }
- catch(e){}
- try{
- myCharaPageNumber = getPageFromAnyObject(myChara.parentTextFrame).name;//.parent.name;
- }
- catch(e){}
- try{
- var myCharaContent_, myCharaPageNumber_, myLine_, myStart, myEnd, myText, myCharaFound_;
- myStart = myCharaFound[chara].index - 1;
- myEnd = myCharaFound[chara-1].index + myCharaFound[chara-1].length;
- myText = myChara.parent.characters.itemByRange(myStart, myEnd);
- //alert(myText.contents);
- myCharaFound_ = myText.search("", false, false,undefined);
- var myCharaContent_, myCharaPageNumber_, myLine_;
- for(chara_=myCharaFound_.length-1; chara_>=0; chara_--){
- myChara_ = myCharaFound_[chara_]
- myCharaContentX_ = myChara_.contents;
- try{
- A_ = /\r/gm;
- myCharaContent_ = myCharaContentX_.replace(A_, "");
- }
- catch(e){}
- try{
- myCharaPageNumber_ = getPageFromAnyObject(myChara_.parentTextFrame).name;//.parent.name;
- }
- catch(e){}
- if(myCharaContent_ != undefined){
- myLine_ = " " + myCharaContent_ + "\t"+ myCharaPageNumber_;
- myParseInt.push(chara);
- myTocLine_.push(myLine_);
- }
- }
- myLine = myCharaContent + "\t"+ myCharaPageNumber;
- myTocLine.push(myLine);
- }
- catch(e){
- myLine = myCharaContent + "\t"+ myCharaPageNumber;
- myTocLine.push(myLine);
- }
- }
- myTocLine.shift();
- myTocLine.reverse();
- try{
- for(mysplice = 0; mysplice<=myParseInt.length-1; mysplice++){
- myTocLine.splice(myParseInt[mysplice], 0, myTocLine_[mysplice]);
- }
- myToc = String(myTocLine).split(",").join("\r");
- }
- catch(e){
- myToc = String(myTocLine).split(",").join("\r");
- }
- //
- myDocument.characterStyles.item("[None]").remove();
- //
- for(d=myDocument.stories.length-1; d>=0; d--){
- myStory = myDocument.stories[d];
- try{
- if((myStory.characters[-1].contents == String(SpecialCharacters.emSpace))&&(myStory.characters[-1].appliedCharacterStyle == myDocument.characterStyles.item(my1stCharaStyle))){ //" "
- myStory.characters[-1].remove();
- }
- }
- catch(e){}
- }
- //
- myTocDocument = app.documents.add();
- myTocPage = myTocDocument.pages[0];
- myTocTextFrame = myTocPage.textFrames.add();
- myTocTextFrame.geometricBounds = myGetBounds(myTocDocument, myTocPage);
- myTocTextFrame.contents = myToc;
- }
- else{
- myDialog.destroy();
- }
- //--------------------------------------------------------------------------------------
- function getPageFromAnyObject(myPageObject){
- var myPage;
- if(myPageObject.constructor.name == "Page"){
- myPage = myPageObject;
- }
- else{
- myPage = getPageFromAnyObject(myPageObject.parent);
- }
- return(myPage);
- }
- //Utility function for getting the bounds of the "live area" of a page.
- function myGetBounds(myDocument, myPage){
- with(myDocument.documentPreferences){
- var myPageHeight = pageHeight;
- var myPageWidth = pageWidth;
- }
- with(myPage.marginPreferences){
- var myTop = top;
- var myLeft = left;
- var myRight = right;
- var myBottom = bottom;
- }
- myRight = myPageWidth - myRight;
- myBottom = myPageHeight- myBottom;
- return [myTop, myLeft, myBottom, myRight];
- }
复制代码
上面的代码是可以在InDesign CS3中执行的,但现在普遍更新了新的版本,所以在高版本ID里执行会报错。
不知道有大神会不会修改这个脚本,感觉很有用的样子。
|
|