首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >InDesign风格变量

InDesign风格变量
EN

Stack Overflow用户
提问于 2013-07-09 18:01:27
回答 2查看 749关注 0票数 0

是否有方法在样式(脚本)中使用变量?来分享一些不同的风格,比如颜色?

示例:--我正在设计一本有多个章节的书。每一章都是一个InDesign文档。我想对书中的所有文档使用通用的样式,但它们的颜色会有所不同。因此,与其拥有多个对象样式(如: RoundedBox-red、RoundedBox-blue等),我将只有一种样式,即RoundedBox,并且只输入…某个地方的颜色变量的值。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-07-11 23:18:12

你有理由只检查矩形、椭圆和多边形吗?如果没有,可以使用pageItems。丢弃形状选择和开关,并使用:

代码语言:javascript
复制
shapes = myDoc.allPageItems;
for (var i=0; i<shapes.length; i++)
{
    if (shapes[i].appliedObjectStyle.name === oldStyle.name)
    {
        shapes[i].applyObjectStyle( newStyle );
    }
}

由于每个章节都包含在一个单独的文档中,所以还可以更改对象样式的定义:

代码语言:javascript
复制
oldStyle.fillColor = newSwatch;

所以你不需要循环实际的对象。没有测试,但应该能用。

票数 1
EN

Stack Overflow用户

发布于 2013-07-10 19:14:25

我发现了。最困难的部分是为Indesign javascript脚本API找到一个好的文档.Adobe的文档要么很难找到,要么缺乏。此外,他们把所有的东西都作为PDF发布,IMHO真的很烦人。我找到了一个良好的CS6在线文档。我正在做CC的工作,但是我使用的一切看起来都一样。无论如何,我已经创建了以下脚本,非常不完整和不完美,但为我工作.

代码语言:javascript
复制
// 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();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17555109

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档