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

Place Embbeded using script

New Here ,
Apr 29, 2023 Apr 29, 2023

Copy link to clipboard

Copied

Hi everyone!

 

I'm new to PS script and trying to use the code below to place an embedded image from 100 pixels from the bottom of the main image, but it's not working. The embedded image it's placed in the center (vertically and horizontally)

var myDoc = app.activeDocument;
app.preferences.rulerUnits = Units.PIXELS;

var w = myDoc.width.value;
var h = myDoc.height.value;

var fileRef = new File("F:/Logo/logo.png");
var idPlc = charIDToTypeID("Plc ");
var desc = new ActionDescriptor();
var idIdnt = charIDToTypeID("Idnt");
desc.putInteger(idIdnt, 52);
var idnull = charIDToTypeID("null");
desc.putPath(idnull, fileRef);

// Set the placement options
var desc2 = new ActionDescriptor();
var idWdth = charIDToTypeID("Wdth");
var idPxl = charIDToTypeID("#Pxl");
desc2.putUnitDouble(idWdth, idPxl, w); // Width (replace with actual width of your image)
var idHght = charIDToTypeID("Hght");
var idPxl = charIDToTypeID("#Pxl");
desc2.putUnitDouble(idHght, idPxl, h); // Height (replace with actual height of your image)
var idVrtS = charIDToTypeID("VrtS");
var idPxl = charIDToTypeID("#Pxl");
desc2.putUnitDouble(idVrtS, idPxl, -3900); // Vertical offset from document bottom (-3900 = 100 pixels from bottom and centered vertically)
var idHrzS = charIDToTypeID("HrzS");
var idPxl = charIDToTypeID("#Pxl");
desc2.putUnitDouble(idHrzS, idPxl, 0); // Horizontal offset from center

desc.putObject(charIDToTypeID("T   "), charIDToTypeID("Ofst"), desc2);

executeAction(idPlc, desc, DialogModes.NO);

 I could not identify what was wrong nor place the embedded image where I needed it to be (100 pixels from the bottom).

 

Regards.

TOPICS
Actions and scripting , Windows

Views

443

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
Adobe
Community Expert ,
Apr 29, 2023 Apr 29, 2023

Copy link to clipboard

Copied

After placing, I'd use the following code snippet to align the layer horizontally as required, then align vertically so that the bottom edge of the layer is at the bottom of the canvas:

 

https://gist.github.com/MarshySwamp/df372e342ac87854ffe08e79cbdbcbb5

 

Finally, I'd then translate the layer up  the required amount of pixels:

 

https://gist.github.com/MarshySwamp/1ef7448b6bb22865ed7b7e1b8a4f521f

 

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 29, 2023 Apr 29, 2023

Copy link to clipboard

Copied

LATEST

I do the same as Stephan, just use the translate command to move it where it needs to go.

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