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
sttk3
July 16, 2023, 3:59am
2
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…
1 Like
sttk3
July 16, 2023, 7:38am
4
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.
Jarda
July 16, 2023, 5:59pm
5
Hmm… I don’t like it. 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