Canvas size

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

mead
Posts: 20
Joined: Sat Jul 23, 2022 12:28 am

Canvas size

Post by mead »

Code: Select all

        var d = new ActionDescriptor();
        d.putUnitDouble(stringIDToTypeID("width"), stringIDToTypeID("distanceUnit"), 200);//I want to change for mm
        d.putUnitDouble(stringIDToTypeID("height"), stringIDToTypeID("distanceUnit"), 200);//I want to change for mm
        d.putEnumerated(stringIDToTypeID("horizontal"), stringIDToTypeID("horizontalLocation"), stringIDToTypeID("left"));
        d.putEnumerated(stringIDToTypeID("vertical"), stringIDToTypeID("verticalLocation"), stringIDToTypeID("top"));
        executeAction(stringIDToTypeID("canvasSize"), d, DialogModes.NO);
How to set to 200 mm unit
Of course can also be a cm
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Canvas size

Post by Kukurykus »

Code: Select all

UnitValue('200 mm').as('px') / 72 * activeDocument.resolution / 4.16723116003387

Code: Select all

stringIDToTypeID('pixelsUnit'), UnitValue(200, 'mm').as('px') / 72 * activeDocument.resolution
mead
Posts: 20
Joined: Sat Jul 23, 2022 12:28 am

Re: Canvas size

Post by mead »

Thank you, but why have no effect?

Edit: Thank you, already can run
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Canvas size

Post by Kukurykus »

Code: Select all

rsltn = activeDocument.resolution
sTT = stringIDToTypeID, dsc = new ActionDescriptor()
wah = {width: ['pixels', UnitValue('200 mm').as('px') / 72 * rsltn],
	height: ['distance', UnitValue(200, 'mm').as('px') / 72 * rsltn / 4.1672]}
for(key in wah) dsc.putUnitDouble(sTT(key), sTT(wah[key][0] + 'Unit'), wah[key][1])
hav = {horizontal: 'left', vertical: 'top'}; for(key in hav) dsc.putEnumerated(sTT(key),
sTT(key + 'Location'), sTT(hav[key])); executeAction(sTT('canvasSize'), dsc)