首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Plugin ReferenceError:颜色未在中定义

Plugin ReferenceError:颜色未在中定义
EN

Stack Overflow用户
提问于 2019-11-19 23:27:09
回答 1查看 792关注 0票数 0

第一个使用XD的插件,我似乎不能创建一个Color类的实例。

他们的文档没有显示任何示例,我在其他示例中找到的任何示例都只显示了new Color(),并且我不需要执行任何require

https://adobexdplatform.com/plugin-docs/reference/Color.html

代码语言:javascript
运行
复制
Plugin ReferenceError: Color is not defined
    at exportToBmpFunction (C:\Users\<useR>\AppData\Local\Packages\Adobe.CC.XD_adky2gkssdxte\LocalState\develop\BMP_Export\main.js:21:21)

我做错了什么?

代码语言:javascript
运行
复制
async function exportToBmpFunction(selection) {

  if (selection.items.length == 0) {
    return;
  }

  // Generate PNG rendition of the selected node
  let application = require("application");
  let scenegraph = require("scenegraph");
  let fs = require("uxp").storage.localFileSystem;

  let shape = selection.items[0];
  let file = await fs.getFileForSaving('what.png', { types: ["png"] });
  let renditions = [{
    node: shape,
    outputFile: file,
    type: application.RenditionType.PNG,
    scale: 1,
    background: new Color('#FF00CD', 1)
  }];
  application.createRenditions(renditions).then(function(results) {
    // ...do something with outputFiles on disk...
  });
}

module.exports = {
  commands: {
    exportToBmp: exportToBmpFunction
  }
};
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-21 05:05:22

在深入研究了同一“命名空间”中的其他类之后,发现它们的文档在某些地方是完全错误的。这就是它应该是的。

代码语言:javascript
运行
复制
  const Color = require("scenegraph").Color;
  let color = new Color('#FF00CD');

这恰好与文档中使用Color的示例直接矛盾。太棒了,免费的代码!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58937493

复制
相关文章

相似问题

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