Documents.add(): fillColor not working?

Hi,
is anyone able to use the fillColor prop when creating a new document?
This works like a charm:

const doc = await app.documents.add({
    fill: constants.DocumentFill.BLACK,
});

This, to the best of my knowledge, should work just fine but it doesn’t (at least on a Mac):

const { SolidColor } = require("photoshop").app;
const col = new SolidColor();
col.base.hexValue = "0d3156"; 
// or if you aren't lazy:
col.rgb.red = 21;
col.rgb.green = 49;
col.rgb.blue = 86;

// This will not work (i.e., the document is not created)
const doc = await app.documents.add({
    fillColor: col;
});

// Same using app.createDocument()

console.log(col);
// A properly formed SolidColor Instance
// {
//     "base": {
//         "desc": {
//             "_obj": "RGBColor",
//             "red": 13,
//             "green": 49,
//             "blue": 86
//         }
//     }
// }
// etc...

Any idea why?
Thanks!

Davide

It seems that the background type and color values need to be specified separately.

const { app, core, constants } = require('photoshop') ;
const { SolidColor } = app ;

const main = async () => {
  try {
    await core.executeAsModal(
      async (control) => {
        const backgroundType = constants.DocumentFill.COLOR ;
        const backgroundColor = new SolidColor() ;
        backgroundColor.base.hexValue = '0d3156' ;

        const doc = await app.documents.add({
          fill: backgroundType, 
          fillColor: backgroundColor
        }) ;
      }, 

      {'commandName': 'New Document with Background Color'}
    ) ;
  } catch(e) {
    await app.showAlert(e) ;
  }
} ;

Thank you very much, it does work indeed! I should be a better reader of documentation by now… :joy:

1 Like

You’re welcome.

This might be more helpful if fill is automatically set to DocumentFill.COLOR when fillColor is specified but no fill is specified.

Hmm… I don’t like it. :smiley: There is no need to say what data type you do pass in. Just pass it and JS should figure this out itself. DOM should be improved in the future and one of those two properties deprecated.

1 Like

This bug has been present for a long time. I just did the long walk to find it after an internal inquiry. I also found that we don’t throw on failure which is not helpful.

That’s not the only bit I’m cleaning up since I’m there…

1 Like