• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Place embedded

New Here ,
Nov 14, 2015 Nov 14, 2015

Copy link to clipboard

Copied

Is the command "Place embedded" scriptable with Javascript in order to add a file as smart object to an opened document, without copy&paste? Thank you

TOPICS
Actions and scripting

Views

2.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Nov 14, 2015 Nov 14, 2015

var filePath = new File('~/path/to/image.png');

placeEmbeded(filePath);

function placeEmbeded(filePath) {

    var actDesc = new ActionDescriptor();

    actDesc.putPath(charIDToTypeID('null'), filePath);

    actDesc.putEnumerated(charIDToTypeID('FTcs'), charIDToTypeID('QCSt'), charIDToTypeID('Qcsa'));

    executeAction(charIDToTypeID('Plc '), actDesc, DialogModes.NO);

}

Votes

Translate

Translate
Adobe
Participant ,
Nov 14, 2015 Nov 14, 2015

Copy link to clipboard

Copied

var filePath = new File('~/path/to/image.png');

placeEmbeded(filePath);

function placeEmbeded(filePath) {

    var actDesc = new ActionDescriptor();

    actDesc.putPath(charIDToTypeID('null'), filePath);

    actDesc.putEnumerated(charIDToTypeID('FTcs'), charIDToTypeID('QCSt'), charIDToTypeID('Qcsa'));

    executeAction(charIDToTypeID('Plc '), actDesc, DialogModes.NO);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 14, 2015 Nov 14, 2015

Copy link to clipboard

Copied

Place may or may not scale the smart object layer.  To be able to get the size of the smart object I always scale the layer to 100% size after doing the place.

function placeImage(file) {

  // avoid bug in cs2 and maybe CS4  make sure current layer targer is not the Layer Mask

  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 I can't find a way to get the scale of a smart object layer, reset to 100%

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

  return app.activeDocument.activeLayer;

}

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 15, 2015 Nov 15, 2015

Copy link to clipboard

Copied

Thank you. It works!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 15, 2015 Nov 15, 2015

Copy link to clipboard

Copied

Thank you. It works!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 15, 2023 Apr 15, 2023

Copy link to clipboard

Copied

How do you define the size and position of the image being placed? Your solution works well, putting the image at the layer's center.

Thanks!

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 15, 2023 Apr 15, 2023

Copy link to clipboard

Copied

LATEST
quote

How do you define the size and position of the image being placed? Your solution works well, putting the image at the layer's center.

Thanks!

 


By @mslino65

 

The script will behave the same as any file being placed manually, using the resolution of the placed image to the target image to determine the physical size, unless Preferences > General > Resize Image During Place is active, which will proportionally scale an oversized image to the canvas width or height.

 

You can always change DialogModes.NO to DialogModes.ALL for an interactive place to test what is going on.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines