Skip to main content
Innotex Nico Tanne
Inspiring
June 19, 2024
Answered

Smartobjet placement via Script

  • June 19, 2024
  • 1 reply
  • 601 views

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🙏

This topic has been closed for replies.
Correct answer Stephen Marsh


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

1 reply

Stephen Marsh
Community Expert
Community Expert
June 19, 2024
Innotex Nico Tanne
Inspiring
June 19, 2024

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 👍.

 

Stephen Marsh
Community Expert
Community Expert
June 19, 2024

Post a screenshot of the action with the transformation step expanded and the panel wide enough to view all content.