Copy link to clipboard
Copied
Hello everyone,
I am desperate and need help, I want to place a smart object via script, but this should not be adapted to the workspace but always keep the original size.
If I load the smart object into a workspace with a width of 40cm but my image is 60cm wide, the image is scaled to the 40cm width when it is placed and the smart object is set to 100%.
I am looking for a way to place the image so that it retains the print size and is rather cut off or partially outside the workspace.
function placeImage(imageFile) {
var desc = new ActionDescriptor();
desc.putPath(cTID('null'), imageFile);
desc.putEnumerated(cTID('FTcs'), cTID('QCSt'), cTID('Qcsa'));
var desc2 = new ActionDescriptor();
desc2.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 0.000000);
desc2.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 0.000000);
desc.putObject(cTID('Ofst'), cTID('Ofst'), desc2);
desc.putBoolean(sTID('autoSelectLayer'), false);
executeAction(cTID('Plc '), desc, DialogModes.NO);
return activeDocument.activeLayer;
}
function cTID(s) {
return app.charIDToTypeID(s);
}
function sTID(s) {
return app.stringIDToTypeID(s);
}
many thanks in advance🙏
1 Correct answer
I thought that the screenshot would clear things up, but it didn't! :]
app.runMenuItem(stringIDToTypeID('freeTransform'));
Or perhaps:
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
var reference = new ActionReference();
reference.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "targetEnum" ));
descriptor.putReference( s2t( "null" ), reference );
descriptor.putEnumerated( s2t( "freeTrans
...
Explore related tutorials & articles
Copy link to clipboard
Copied
You can look at various methods here:
Copy link to clipboard
Copied
thank you very much!
I have now solved it a little differently and I am doing a transformation reset of the smart object
//Reset Transformation
var idplacedLayerResetTransforms = stringIDToTypeID("placedLayerResetTransforms");
executeAction(idplacedLayerResetTransforms, undefined, DialogModes.ALL);
Then the smart object has reference to the original size again and I only have to bring it to 100%, but since I couldn't write a working script for this I solved it with an action that I load via script and call the free transform, here I have to enter the 100% manually but then it fits perfectly 🙂
If someone has a tip for the transformation to 100% of the original size without an action I would also be grateful 👍.
Copy link to clipboard
Copied
Post a screenshot of the action with the transformation step expanded and the panel wide enough to view all content.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
it is for my own Contact Sheet II like Workflow helper but where I can place images in print size 😅
Copy link to clipboard
Copied
I thought that the screenshot would clear things up, but it didn't! :]
app.runMenuItem(stringIDToTypeID('freeTransform'));
Or perhaps:
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
var reference = new ActionReference();
reference.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "targetEnum" ));
descriptor.putReference( s2t( "null" ), reference );
descriptor.putEnumerated( s2t( "freeTransformCenterState" ), s2t( "quadCenterState" ), s2t( "QCSAverage" ));
descriptor2.putUnitDouble( s2t( "horizontal" ), s2t( "pixelsUnit" ), 0.000000 );
descriptor2.putUnitDouble( s2t( "vertical" ), s2t( "pixelsUnit" ), 0.000000 );
descriptor.putObject( s2t( "offset" ), s2t( "offset" ), descriptor2 );
descriptor.putUnitDouble( s2t( "width" ), s2t( "percentUnit" ), 200.000000 );
descriptor.putUnitDouble( s2t( "height" ), s2t( "percentUnit" ), 200.000000 );
descriptor.putEnumerated( s2t( "interfaceIconFrameDimmed" ), s2t( "interpolationType" ), s2t( "bicubicSmoother" ));
executeAction( s2t( "transform" ), descriptor, DialogModes.NO );
You would change the width and height from 200% as required or make the code interactive by changing DialogModes.NO to DialogModes.ALL
Copy link to clipboard
Copied
Thank you so much 🙏
"runMenuItem" Works very well and with the correct % values, but it must remain interactive here.
With the actiondescriptor code I have the problem that the % values are not correct. If I use DialogModes.ALL I see the image with the size of 200% but the values in the size are set to 100% although the real size is the 200%, so of course the print size is not correct otherwise DialogModes.NO would be very useful.
But I am very happy that everything still works so far 🙂

