插件ReferenceError:颜色未在

时间:2019-11-19 15:27:09

标签: adobe-xd

第一个带有XD的插件,我似乎无法创建Color类的实例。

他们的文档没有显示任何示例,而我在其他示例中发现的任何示例仅显示了new Color(),而我不必执行任何require

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

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)

我在做什么错了?

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
  }
};

1 个答案:

答案 0 :(得分:0)

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

  const Color = require("scenegraph").Color;
  let color = new Color('#FF00CD');

这恰好与文档中使用Color的示例相矛盾。 是的,写意代码!