【问题标题】:Script to Change selected item to a Swatch Color将所选项目更改为色板颜色的脚本
【发布时间】:2023-01-30 16:47:48
【问题描述】:

我有一个基本的 JavaScript,它应该将所选项目从 CMYK 黑色更改为名为 Bronze 的色板颜色,但它不起作用。关于代码应该看起来有什么建议吗?

// Get the active document
var doc = app.activeDocument;

// Check if there is a selection
if (doc.selection.length > 0) {
  // Get the first selected object
  var obj = doc.selection[0];

  // Check if the object has a fill
  if (obj.fillColor > 0) {
    // Set the object's fill color to the "Bronze" swatch
    obj.fillColor = 5;
  }
}

【问题讨论】:

  • 请替换 5,使该行显示为 obj.fillColor = "Bronze";

标签: javascript-objects extendscript


【解决方案1】:

将您的代码更改为此,这有效,我已经测试过了。

// Get the active document
var doc = app.activeDocument;

// Check if there is a selection
if (doc.selection.length > 0) {
  // Get the first selected object
  var obj = doc.selection[0];

    //change your code to lines below ---v
  
 if (obj.filled) 
   obj.fillColor = activeDocument.swatches["Bronze"].color  
 
}

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加更多详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写出好的答案的信息in the help center
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-10
相关资源
最近更新 更多