figma / plugin-typings

Typings for the Figma Plugin API
MIT License
195 stars 45 forks source link

Cannot set property fillGeometry of [object Object] which has only a getter #117

Closed tomasdev closed 10 months ago

tomasdev commented 2 years ago

From plugin-api.d.ts, fillGeometry is not marked as readonly. I assumed I could edit the array but the Figma Developer VM threw this error: Cannot set property fillGeometry of [object Object] which has only a getter

const newVector = figma.createVector();
newVector.fillGeometry = [
  {windingRule: 'NONE', data: 'M 0 0 L 48 0 L 48 48 L 0 48 L 0 0 Z'},

All I'm trying to do is ensure the fills are kept after flattening, which is not deterministic at the moment (different FIgma clients have different results)

tomasdev commented 2 years ago

Similarly, using multiple vector paths cannot be colorized separately? (and that is why I tried using fillGeometry)

newVector.vectorPaths = [
  {windingRule: 'NONE', data: 'M 0 0 L 48 0 L 48 48 L 0 48 L 0 0 Z'},
  someOtherVectorPath,
];
newVector.fills = [
  RED,
  GREEN,
];
// painted both vector paths the last color
glebsexy commented 2 years ago

Multi-colored vectors aren't yet available in the API.

johndoherty commented 2 years ago

We recently added the ability to specify fills on VectorNetwork regions. That may help here.

You can do something like:

const regions = newVector.vectorNetwork.regions;
regions[0].fills = [RED]
region[1].fills = [GREEN]
jefflee-figma commented 10 months ago

Closing this issue; the lack of readonly annotation was a bug, which has been resolved with #268.