Skip to main content
Innotex Nico Tanne
Inspiring
May 11, 2021
Question

Smartobject size to 100%

  • May 11, 2021
  • 3 replies
  • 7904 views

Hello all,

is there a possibility to bring a smartobject to exactly 100% by script. This would help me a lot.

This topic has been closed for replies.

3 replies

JJMack
Community Expert
Community Expert
May 11, 2021

What do you mean by 100%.  and is the smart object a Placed image file. Place scale smart objects,  In fact place may scale a smart object twice.  Once because there are different print resolution  in the Place image File the  document it is placed into a document and second second scaling if the smart object layer does not fit on canvas and your Photoshop preferences is  set to resize during Place. 

 

Script can scale a smart  layer to fill some area and mask  it to the area aspect ratio and shape.  I do that all the time.  Scaling a  smart object layer object transform to 100% may not be the size you are expecting the object  to be because Place may have scaled the object because of different resolution are involve.  Smart object layer implementation is more complex then most users think.

 

New versions of Photoshop have reset place layers transform I do not know if that will reset the PPI scaling Place may as well at place resize and user transform. It may I did not test that though.

 

I just tested reset place layers transform will reset all transforming done to the smart object sizing  and warping but positioning is not changed  so if the  transforming also move the positioning that will not be reset.

JJMack
Innotex Nico Tanne
Inspiring
May 11, 2021

Hello JJMack,

I have a document with a resolution of, for example, 100 dpi and then place images with different resolutions (dpi) as Smart Objects.
In order for the print size to be correct, however, I have to set the smart objects to exactly 100%, so a simple reset of the transformation is unfortunately not possible.

Innotex Nico Tanne
Inspiring
May 15, 2021

No I have never tried to record such an action.  I have only resize the active smart object layer in a script.

activeDocument.activeLayer.resize(100 ,100,AnchorPosition.MIDDLECENTER);

in a  place function.

 

 

function placeImage(file) {
	// =======avoid bug in cs2 and maybe CS4 ==================================
	var idslct = charIDToTypeID( "slct" );
	    var desc5 = new ActionDescriptor();
	    var idnull = charIDToTypeID( "null" );
	        var ref3 = new ActionReference();
	        var idChnl = charIDToTypeID( "Chnl" );
	        var idChnl = charIDToTypeID( "Chnl" );
	        var idRGB = charIDToTypeID( "RGB " );
	        ref3.putEnumerated( idChnl, idChnl, idRGB );
	    desc5.putReference( idnull, ref3 );
	    var idMkVs = charIDToTypeID( "MkVs" );
	    desc5.putBoolean( idMkVs, false );
	executeAction( idslct, desc5, DialogModes.NO );

	// Place in the file
	var idPlc = charIDToTypeID( "Plc " );
	    var desc5 = new ActionDescriptor();
	    var idnull = charIDToTypeID( "null" );
	    desc5.putPath( idnull, new File( file ) );
	    var idFTcs = charIDToTypeID( "FTcs" );
	    var idQCSt = charIDToTypeID( "QCSt" );
	    var idQcsa = charIDToTypeID( "Qcsa" );
	    desc5.putEnumerated( idFTcs, idQCSt, idQcsa );
	    var idOfst = charIDToTypeID( "Ofst" );
	        var desc6 = new ActionDescriptor();
	        var idHrzn = charIDToTypeID( "Hrzn" );
	        var idPxl = charIDToTypeID( "#Pxl" );
	        desc6.putUnitDouble( idHrzn, idPxl, 0.000000 );
	        var idVrtc = charIDToTypeID( "Vrtc" );
	        var idPxl = charIDToTypeID( "#Pxl" );
	        desc6.putUnitDouble( idVrtc, idPxl, 0.000000 );
	    var idOfst = charIDToTypeID( "Ofst" );
	    desc5.putObject( idOfst, idOfst, desc6 );
	executeAction( idPlc, desc5, DialogModes.NO );

	// because can't get the scale of a smart object, reset to 100%
	if (version!="9.0.0") activeDocument.activeLayer.resize(100 ,100,AnchorPosition.MIDDLECENTER);

	return app.activeDocument.activeLayer;
}

 

 

I just tried and transform 100% width and 100% height  however if does not set  the smart correct layer's object  transform to 100% size the smart object layer transform remain the same as it was set..  Transform may require a relative change from what it currently is. In newer  Photoshop version you can record Reset Transformations which will reset  the layer'e transform  scaling and warping. I do not know how to retrieve the smart object layer current scaling to to be able to set a transform change so the result will scale to 100% smart object size.  R-bin you may be able to code Action manager code to do that.  That is above my pay grade.

 


Hello and thank you anyway, I have also tried to record an action, but here it is then always scaled by the % and not to the desired 100% of the smart object. If I have different resolutions for the smart objects it also does me no good to bring the document to the dpi of the smart object. It could be that you know a relatively simple method to set the value of the smart object to 100%. Then I have no choice but to set the value to 100% manually.

Stephen Marsh
Community Expert
Community Expert
May 11, 2021

A fuction call/function that you will find on this forum in multiple scripts, where varSomeFile may be a variable to a single file or multiple files:

 

 

placeFile(varSomeFile, 100);

 

 

 

function placeFile(file, scale) {
    var idPlc = charIDToTypeID("Plc ");
    var desc2 = new ActionDescriptor();
    var idnull = charIDToTypeID("null");
    desc2.putPath(idnull, new File(file));
    var idFTcs = charIDToTypeID("FTcs");
    var idQCSt = charIDToTypeID("QCSt");
    var idQcsa = charIDToTypeID("Qcsa");
    desc2.putEnumerated(idFTcs, idQCSt, idQcsa);
    var idOfst = charIDToTypeID("Ofst");
    var desc3 = new ActionDescriptor();
    var idHrzn = charIDToTypeID("Hrzn");
    var idPxl = charIDToTypeID("#Pxl");
    desc3.putUnitDouble(idHrzn, idPxl, 0.000000);
    var idVrtc = charIDToTypeID("Vrtc");
    var idPxl = charIDToTypeID("#Pxl");
    desc3.putUnitDouble(idVrtc, idPxl, 0.000000);
    var idOfst = charIDToTypeID("Ofst");
    desc2.putObject(idOfst, idOfst, desc3);
    var idWdth = charIDToTypeID("Wdth");
    var idPrc = charIDToTypeID("#Prc");
    desc2.putUnitDouble(idWdth, idPrc, scale);
    var idHght = charIDToTypeID("Hght");
    var idPrc = charIDToTypeID("#Prc");
    desc2.putUnitDouble(idHght, idPrc, scale);
    var idAntA = charIDToTypeID("AntA");
    desc2.putBoolean(idAntA, true);
    executeAction(idPlc, desc2, DialogModes.NO);
}

 

 

 

Kukurykus
Legend
May 11, 2021
runMenuItem(stringIDToTypeID('placedLayerResetTransforms'))
Legend
May 13, 2021
quote
runMenuItem(stringIDToTypeID('placedLayerResetTransforms'))

By @Kukurykus

Interesting. But does not work in 2020.

Kukurykus
Legend
May 13, 2021

I don't know when it was implemented, but probably it's something quite new. Try not by ran item, but traditional way, however I think that will fail too if I guess you don't have it in panel.