Javascript Layer translate units bug on CS2

Discussion of actual or possible Photoshop Scripting Bugs, Anomalies and Documentation Errors

Moderators: Tom, Kukurykus

Michael

Javascript Layer translate units bug on CS2

Post by Michael »

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?

Thanks.

Code: Select allif ( 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 = docRef.name;
   
   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 = app.open(watermarkFile);
      watermarkRef.artLayers[0].copy();
      watermarkRef.close();
      
      activeDocument=docRef;
      var watermarkLayer=docRef.paste();
      watermarkLayer.moveToBeginning(docRef);
//      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
   }
   else
   {
      alert( "This function only operates on 8 bit RGB, CMYK or Lab documents." );
   }
}
else
{
   alert( "You must have a document open!" );
}
Larry Ligon

Javascript Layer translate units bug on CS2

Post by Larry Ligon »

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

Code: Select allvar 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 allactiveDocument.resizeImage(null,null,originalResolution ,resampleMethod );

This does not resample the image.

Larry
Michael

Javascript Layer translate units bug on CS2

Post by Michael »

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.
Mike Hale

Javascript Layer translate units bug on CS2

Post by Mike Hale »

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
Michael

Javascript Layer translate units bug on CS2

Post by Michael »

Much appreciated, thanks for the explanation.
jasonhendriks

Javascript Layer translate units bug on CS2

Post by jasonhendriks »

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:
var TARGET_RESOLUTION = 300;
app.preferences.rulerUnits = Units.INCHES;
app.activeDocument.resizeImage(4,6,TARGET_RESOLUTION,ResampleMethod.BICUBIC);

In CS2 my target resolution is always ignored and I have to do the math myself. The script becomes:
var TARGET_RESOLUTION = 300;
app.preferences.rulerUnits = Units.POINTS;
app.activeDocument.resizeImage(TARGET_RESOLUTION*4,TARGET_RESOLUTION*6,null,ResampleMethod.BICUBIC);
app.preferences.rulerUnits = Units.INCHES;
app.activeDocument.resizeImage(null,null,TARGET_RESOLUTION,ResampleMethod.NONE);

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

Thanks,
Jason
xbytor

Javascript Layer translate units bug on CS2

Post by xbytor »

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.