2017-06-20 140 views
0

的Javascript grep的最後一場比賽,我這裏InDesign中的文本:InDesign中:在一個段落

Hello (World), 
this (nonsense) text 
nobody (needs, right?). 

隨着我的JSX腳本我想選擇用括號(needs, right?)最後一場比賽。 但是這個結果是用常規和斜體格式化的(needs是斜體,其餘的是常規的)。但我只想改變常規風格。

在我的劇本的部分看起來像這樣:

function myFindGrep(myObject, mySearchString, mySearchStyle, myStyleGroup, myStyle){ 
    app.changeGrepPreferences = NothingEnum.nothing; 
    app.findGrepPreferences = NothingEnum.nothing; 
    app.findGrepPreferences.findWhat = mySearchString; 
    app.findGrepPreferences.fontStyle = mySearchStyle; 
    app.changeGrepPreferences.appliedCharacterStyle = myDocument.characterStyleGroups.item(myStyleGroup).characterStyles.item(myStyle); 
    var myFoundItems = myObject.changeGrep(); 
    app.changeGrepPreferences = NothingEnum.nothing; 
    app.findGrepPreferences = NothingEnum.nothing; 
} 

myFindGrep(selText.paragraphs.item(x), "\(.+?\)", "Regular", "Meist genutzte", "Zitat Regular"); 

當我申請這一點,改變我的選擇孔除了斜體字...

是有辦法解決這一問題?

+0

你的腳本似乎做什麼我可以觀察的工作。 – Loic

回答

0

我不得不修改我的職責,做了第二次的grep:

function myFindQuote(myObject, mySearchString, mySearchStyle, myStyleGroup, myStyle) { 
    app.changeGrepPreferences = NothingEnum.nothing; 
    app.findGrepPreferences = NothingEnum.nothing; 
    app.findGrepPreferences.findWhat = mySearchString; 
    var myFoundItems = myObject.findGrep(); 

    for (var i = 0; i < myFoundItems.length; i++) { 
     app.changeGrepPreferences = NothingEnum.nothing; 
     app.findGrepPreferences = NothingEnum.nothing; 
     app.findGrepPreferences.fontStyle = mySearchStyle; 
     app.changeGrepPreferences.appliedCharacterStyle = myDocument.characterStyleGroups.item(myStyleGroup).characterStyles.item(myStyle); 
     myFoundItems[i].changeGrep(); 
    } 
}