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

Same script different behaviours

New Here ,
Jun 25, 2020 Jun 25, 2020

Copy link to clipboard

Copied

I am pretty new to Photoshop and Photoshop scripting and I had to work for a few weeks on a Photoshop JS script that reads a configuration file and overlays colors, replaces images, replaces texts according to the conf file and exports layers to PNG files.

Everything works fine on my mac but I have several problems trying to execute it on another mac. While all my images are perfectly placed when I execute my script on my mac, on the mac of my coworker (which is the mac where this script is supposed to be used) the images are place below the right place.

What did I miss? Is there some configuration or preferences I have to set for Photoshop to count properly the coordinates?
So you can have some hints I have below the functions I use to replace and move my images (found on the web).

 

// Replace SmartObject Contents
function replaceImage(newFilePath, layer) {
app.activeDocument.activeLayer = layer;
var idplacedLayerReplaceContents = stringIDToTypeID("placedLayerReplaceContents");
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
desc3.putPath(idnull, new File(newFilePath));
var idPgNm = charIDToTypeID("PgNm");
desc3.putInteger(idPgNm, 1);
executeAction(idplacedLayerReplaceContents, desc3, DialogModes.NO);
return app.activeDocument.activeLayer
}
 
//Move specified layer to specified place (absolute coordinates from the up left corner of the layer)
function moveLayerTo(fLayer,fX,fY) {

var Position = fLayer.bounds;
Position[0] = fX - Position[0];
Position[1] = fY - Position[1];
 
fLayer.translate(-Position[0],-Position[1]);
}
TOPICS
Actions and scripting

Views

343

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 ,
Jun 25, 2020 Jun 25, 2020

Copy link to clipboard

Copied

Are you testing with the same documents  files on both machine. Smart Object Replace content has some dependencies. Replacement object need to be exactly the same Aspect Ratio, Size and Resolution as the object in the the template PSD smart object layer. For the Smart Object Lasyer's associated Object Transform is not replace or altered when you use replace content. If the replacement Object is different the transform will not work correctly  and moving the transformed object will not correct the problem.

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 ,
Jun 26, 2020 Jun 26, 2020

Copy link to clipboard

Copied

I used the same template, same configuration file and same images to replace for both of the machines. Also my Photoshop script is launched by an Applescript that makes a copy of my template, runs my Photoshop script on this copy and then uses the generated images with other softwares. So every time the Photoshop script is launched the PSD file is always a copy of the same template file. I tried launching my script manually on Photoshop if it could explain the different behaviours but Applescript does everything correctly.

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 ,
Jun 26, 2020 Jun 26, 2020

Copy link to clipboard

Copied

What are the Ruler Units? 

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 ,
Jun 26, 2020 Jun 26, 2020

Copy link to clipboard

Copied

Are the machine running the same Mac OS and same PS version ? Same Add-ons. What is different? Preferences hardware etc.  There should be something that is different if results differ. 

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 ,
Jun 30, 2020 Jun 30, 2020

Copy link to clipboard

Copied

We both have PS 2020, I have Mac OS 10.14.6 while his mac works on 10.15.2

There's no add-on his instance of PS and I have Script Event Listener, needed it to make some Action Scripts.

Our preferences are similar, the differences are:

-the RAM used by photohop (9905 MB in my mac, 4169 MB in his mac)

-the Cache Tile Size (1024K in my mac, 128K in his mac)

Do you think these differences can change anything? And if you think so what could I do so my script works the same way on any mac?

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 ,
Jun 25, 2020 Jun 25, 2020

Copy link to clipboard

Copied

Does the Script set the Ruler Units? 

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 ,
Jun 29, 2020 Jun 29, 2020

Copy link to clipboard

Copied

In fact you were right I didn't set the Ruler Units in the script, but I thought it wouldn't change anything because we have the same preferences in the Ruler and Units menu.

I can't try it today because I'm not next to the mac where my script should be used, I will try tomorrow and will tell if it worked or not.

So for my test of tomorrow I have these units:

 

app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS
app.preferences.pointSize = PointType.POSTSCRIPT;

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 ,
Jun 30, 2020 Jun 30, 2020

Copy link to clipboard

Copied

I just went back from testing and even after I set the ruler units to what I wrote you in previous message the images are still placed below where it is supposed to be...

Is there any preferences configuration or anything I could have missed?

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 ,
Jun 30, 2020 Jun 30, 2020

Copy link to clipboard

Copied

Try 
app.preferences.rulerUnits = Units.POINTS;

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 ,
Jul 06, 2020 Jul 06, 2020

Copy link to clipboard

Copied

Just tried to change to Units.POINTS, but it didn't change anything...

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 ,
Jul 06, 2020 Jul 06, 2020

Copy link to clipboard

Copied

Are you sure you are replacing the object with object the same aspect ratio size and resolution. If the smart replacement is not the correct size The smart object layer's Object Transform will not transform the object like the original object was transformd.  The translate move of the layer will be different then with the original layer  for the layer's bounds which the move is base off of will be different then the original smart objects layer's pixels bounds.  It not an absolute x y postion move its a calulated x y position relative to the smart object layers bounds position.

 

Position[0] = fX - Position[0];
Position[1] = fY - Position[1];

 

fY and fY are values passed, Position[0]  and Position[1] retrieved from Photoshop the smart object  layer pixels content upper  and lef bounds  which are changes using fX and fY. If ruler units are set to Pixels photoshop should return pixel off set  relative to the document upper left corner position x=0, y=0 for the Layers pixels bounds before factoring in fX and fY.  How fX and fY are set was not shown.

 

The move is in the negive direction of value position[0]  and Position[1]

fLayer.translate(-Position[0],-Position[1]);

Some kind of relative move

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 ,
Jul 07, 2020 Jul 07, 2020

Copy link to clipboard

Copied

LATEST

You may have a point... Some images are more "misplaced" than other and now that you say it the images that are the most reduced are the most misplaced in the final PS file.

I used the Window > Info menu to get info on an image but I don't know if the given dimensions are the dimensions of the image file or the dimensions of the image in the PS file.

I have put my images in masks and my script has an algorythm to resize the images properly so I didn't think about that because my images was always at the right size but you may be right.

I have two questions with what you said in mind:

-Why my script places my images properly on my mac no matter the original size of the image but not on another PS instance?

-Is there a way to place the image, using top left corner of the image as coordinates so that the size does not matter?

 

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