2013-07-09 70 views
0

有沒有一種方法可以在樣式(腳本?)中使用變量來共享具有某些變體的樣式,如顏色?InDesign風格變量

例如:我正在編寫一本書,有多章。每章都是InDesign文檔。我想爲本書中的所有文檔使用通用樣式,但它們的顏色會有所不同。所以,而不是有多個對象樣式:RoundedBox紅色,RoundedBox藍色等,我只會有一個樣式,RoundedBox,並只輸入顏色變量的值在某處...

回答

1

你有一個理由,只檢查矩形,橢圓形和多邊形?如果沒有,你可以使用pageItems。溝形狀選擇和切換,並使用:

shapes = myDoc.allPageItems; 
for (var i=0; i<shapes.length; i++) 
{ 
    if (shapes[i].appliedObjectStyle.name === oldStyle.name) 
    { 
     shapes[i].applyObjectStyle(newStyle); 
    } 
} 

既然你有一個單獨的文檔的每個章節,你也可以只改變你的對象風格的定義:

oldStyle.fillColor = newSwatch; 

,所以你不要不必循環實際的物體。沒有測試,但它應該工作。

0

嗯,我發現了。最難的部分是爲Indesign JavaScript腳本API找到一份很好的文檔... Adob​​e的文檔很難找到或缺乏。另外,他們將所有內容都發布爲PDF,恕我直言,這真的很煩人。我發現了一個good online documentation for CS6。我正在研究CC,但我使用的一切似乎都一樣。無論如何,我已經創建了下面的腳本,非常不完整和不完美,但對我的作品......

// Setup the dialog UI 
    var myDialog = app.dialogs.add({ 
     name: "Style Variables", 
     canCancel: true 
    }); 

// I usually never use 'with', but this is how it is done 
// in Adobe's documentation... 
with(myDialog.dialogColumns.add()) { 
    staticTexts.add({staticLabel: "Main Color swatch name:"}); 
    staticTexts.add({staticLabel: "Style to replace:"}); 
    staticTexts.add({staticLabel: "Replace style with:"}); 
    staticTexts.add({staticLabel: "Choose shape type to target:"}); 
} 
with(myDialog.dialogColumns.add()){ 
    var swatchField  = textEditboxes.add({editContents:'', minWidth:180}), 
     oldStyleField = textEditboxes.add({editContents:'', minWidth:180}), 
     newStyleField = textEditboxes.add({editContents:'', minWidth:180}), 
     shapeTypeField = dropdowns.add({stringList:['Rectangles', 'Ovals', 'Polygons']});  // Defaults to rectangles 
} 

// Get the user input and do stuff with it 
var myResult = myDialog.show(); 
if (myResult === true) 
{ 
    var docs  = app.documents, 
     myDoc  = docs[0], 
     allStyles = myDoc.objectStyles, 
     oldStyle = allStyles.itemByName(oldStyleField.editContents), 
     newStyle = allStyles.itemByName(newStyleField.editContents), 
     swatches = app.documents[0].swatches, 
     newSwatch = swatches.itemByName(swatchField.editContents), 
     shapes; 

// Get the shape type we are targetting: 
switch(shapeTypeField.selectedIndex) 
{ 
    case 0: 
     shapes = myDoc.rectanges; 
     break; 
    case 1: 
     shapes = myDoc.ovals; 
    break; 
case 2: 
    shapes = myDoc.polygons; 
    break; 

default: 
    shapes = myDoc.rectangles; 
} 
// Set the base style color to the user chosen swatch: 
newStyle.fillColor = newSwatch; 

    for (var i=0; i<shapes.length; i++) 
    { 
     if (shapes[i].appliedObjectStyle.name === oldStyle.name) 
     { 
      shapes[i].applyObjectStyle(newStyle); 
     } 
    } 
} 
else 
{ 
    alert('Script cancelled, nothing was done.'); 
} 

// Destroy dialog box 
myDialog.destroy();