Javascript Layer translate units bug on CS2

Discussion of actual or possible Photoshop scripting bugs, anomalies and documentation errors

Moderator: PS-Moderators

Javascript Layer translate units bug on CS2

Postby Michael » Sat Oct 01, 2005 12:22 pm

I just upgraded to CS2 from PS7 yesterday. I have a number of scripts that I use for automating the image editing process I use on my digital camera photos in preparation for uploading them to my website for use in stories.

Two of those script failed to work in CS2, both of them make use of a layer translate to move a pasted-in watermark layer into position.

The PS7 script made use of pixels as units, because frankly, no other unit makes sense to me. It soon became obvious that CS2 was not using pixels for the translate, though, as all of the translates had the layer moving much farther than it should have.

I save/set/reset the units preferences, so I couldn't figure what the problem was. An alert(docRef.height-75) would always give me the appropriate answer (eg. "375 px"), but using that same value in the translate method for the layer never gave me the right response.

In any event, it appears that CS2 will only use "points" in translates now for some reason. I don't know exactly what a point is, but I have calculated it to be 4.86127 pixels in my photographs.

Once I applied this number to the math in the script, and did everything in points, I had no problem.

So, two things:

1) Is there a way to get translate() to use pixels for units?

2) What the heck is a point, and what problems am I potentially going to run into using this 4.86127 number in my calculations. Is the definition of points tied to DPI or something that can potentially change?


Code: Select all
if ( documents.length > 0 )
      This function adds the MobileBurn watermark to the bottom of the current document. 
      It loads the watermark PSD, copies it, closes it, pastes it into the target document, moves it 2px left, and 75px from the bottom

   var docRef = app.activeDocument;
   var docName =;
   if (    docRef.bitsPerChannel == BitsPerChannelType.EIGHT &&
         (   docRef.mode == DocumentMode.CMYK   ||
            docRef.mode == DocumentMode.RGB      ||
            docRef.mode == DocumentMode.LAB ) )
      var startRulerUnits = app.preferences.rulerUnits
      var startTypeUnits = app.preferences.typeUnits

      app.preferences.rulerUnits = Units.POINTS      // must be in points to get around CS2 unit bug
      app.preferences.typeUnits = TypeUnits.PIXELS      

      var watermarkFile = new File("c:\\htdocs\\mobile\\PSD Files\\watermark-red_text_fade-big.psd");
      var watermarkRef =;
      var watermarkLayer=docRef.paste();
//      watermarkLayer.translate(-2,docRef.height-75);      // This is what worked in PS7 using pixels
      watermarkLayer.translate(-.41,docRef.height-15.428);   // 15.428 equates to 75 pixels, the height of the watermark

      app.preferences.rulerUnits = startRulerUnits
      app.preferences.typeUnits = startTypeUnits
      alert( "This function only operates on 8 bit RGB, CMYK or Lab documents." );
   alert( "You must have a document open!" );
Posts: 3
Joined: Sat Oct 01, 2005 12:07 pm
Location: Philadelphia, PA USA

Postby Larry Ligon » Sat Oct 01, 2005 12:59 pm

Here is a trick that should work. Change the image to a resolution of 72.

Code: Select all
var originalResolution = activeDocument.resolution;
var resampleMethod = ResampleMethod.NONE;
activeDocument.resizeImage(null,null,72,resampleMethod );

At the end of your process change the resolution back to the original resolution:

Code: Select all
activeDocument.resizeImage(null,null,originalResolution ,resampleMethod );

This does not resample the image.

Larry Ligon
Posts: 241
Joined: Thu May 19, 2005 2:59 pm
Location: Nashville TN USA

Postby Michael » Sat Oct 01, 2005 1:09 pm

Ah, so it is tied to the screen resolution or something.

Thanks, that will make things much easier for me in the future. Much appreciated.
Posts: 3
Joined: Sat Oct 01, 2005 12:07 pm
Location: Philadelphia, PA USA

Postby Mike Hale » Sun Oct 02, 2005 5:26 pm

Picas and point are used in printing. Newspaper, Mags, that kind of thing. Points are also used with fonts.

There are 72 points in an iinch so when you set the dpi to 72, points = inches.

Even though fonts use points, 72 points give you inch high type no matter what dpi.

Mike Hale
Site Admin
Posts: 4318
Joined: Fri Sep 30, 2005 10:52 pm
Location: USA

Postby Michael » Sun Oct 02, 2005 8:16 pm

Much appreciated, thanks for the explanation.
Posts: 3
Joined: Sat Oct 01, 2005 12:07 pm
Location: Philadelphia, PA USA

Postby jasonhendriks » Thu Oct 20, 2005 2:31 pm

I just upgraded from CS to CS2 and I'm having a similar problem, but with resizeImage. No matter what resolution I set, it seems to be defaulting to 72.

In CS this was no problem:
app.preferences.rulerUnits = Units.INCHES;

In CS2 my target resolution is always ignored and I have to do the math myself. The script becomes:
app.preferences.rulerUnits = Units.POINTS;
app.preferences.rulerUnits = Units.INCHES;

Must I now convert and specify all my resolutions in POINTS? If so, what the h3!! for??

Last edited by jasonhendriks on Thu Oct 20, 2005 3:04 pm, edited 1 time in total.
Posts: 1
Joined: Thu Oct 20, 2005 2:20 pm
Location: Toronto, Canada

Postby xbytor » Thu Oct 20, 2005 2:50 pm

This is a known bug. It has come up a couple of times on the Adobe forum and probably here as well. Lots of detail if you're interested.
Site Admin
Posts: 2264
Joined: Thu May 19, 2005 12:11 pm
Location: In Limbo

Return to Photoshop Scripting Bugs and Anomalies

Who is online

Users browsing this forum: No registered users and 0 guests