Why does this zoom function act differently in CS3 than CS4?

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Tom, Kukurykus

ddbell

Why does this zoom function act differently in CS3 than CS4?

Post by ddbell »

This zoom function that I got from Mike Hale works perfectly on CS3 and CS4 for Mac. For PC, its working fine for me on CS4. However, on PC/CS3 it sets the zoom to about about 4X of the function parameter setting.

For example, this code sets the zoom to 104.17% instead of 25% on CS3 on my PC. However its sets it to 25% on my Mac CS3/CS4 as well as my PC on CS4. I tested it using the same image file so its not image dependent.

Does anyone know if there's a global setting somewhere that may affect this? The function works perfectly on my PC/CS3 if I change the formula from 72/(zoom/100) to 300/(zoom/100).

I know that 72 is the value used for the points scaling system. So the zoom factor equation must be tied to that somehow. But why this needs to be set to 300 for my PC in CS3 is puzzling too me.

I would like to use this to set the zoom to 50% at the end of one of my scripts. However, if it sets it to 208% for some users then I can't do that.

Thanks


Code: Select allsetZoom (25);

function setZoom( zoom ) {
   cTID = function(s) { return app.charIDToTypeID(s); };
   var docRes = activeDocument.resolution;
   activeDocument.resizeImage( undefined, undefined, 72/(zoom/100), ResampleMethod.NONE );
   var desc = new ActionDescriptor();
   var ref = new ActionReference();
   ref.putEnumerated( cTID( "Mn  " ), cTID( "MnIt" ), cTID( 'PrnS' ) );
   desc.putReference( cTID( "null" ), ref );
   executeAction( cTID( "slct" ), desc, DialogModes.NO );
   activeDocument.resizeImage( undefined, undefined, docRes, ResampleMethod.NONE );
}

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

ddbell

Why does this zoom function act differently in CS3 than CS4?

Post by ddbell »

OK so I just figured out what is going on........

In edit > preferences >units and rulers >

The screen resolution was 300 pixels/inch for my PC on CS3. If I set it to 72/pixels inch then it works fine. However, if its set to anything other than 72/ppi the zoom function doesn't work correctly.

Does anyone know of another way of creating a zoom function that is not affected by the global screen resolution setting?
Mike Hale

Why does this zoom function act differently in CS3 than CS4?

Post by Mike Hale »

I don't know how to set the zoom any other way. But I also didn't know about it using the screenres preference. Here is a version that takes that preference into account when setting the zoom. It seems to work ok now no matter what the preference is set at.

Code: Select allfunction getScreenRes(){
   var ref = new ActionReference();
   ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
   return executeActionGet(ref).getObjectValue(stringIDToTypeID('unitsPrefs')).getUnitDoubleValue(stringIDToTypeID('newDocPresetScreenResolution'))/72;
}
function setZoom( zoom ) {
   cTID = function(s) { return app.charIDToTypeID(s); };
   var docRes = activeDocument.resolution;
   activeDocument.resizeImage( undefined, undefined, getScreenRes()/(zoom/100), ResampleMethod.NONE );
   var desc = new ActionDescriptor();
   var ref = new ActionReference();
   ref.putEnumerated( cTID( "Mn  " ), cTID( "MnIt" ), cTID( 'PrnS' ) );
   desc.putReference( cTID( "null" ), ref );
   executeAction( cTID( "slct" ), desc, DialogModes.NO );
   activeDocument.resizeImage( undefined, undefined, docRes, ResampleMethod.NONE );
}
setZoom (25);
ddbell

Why does this zoom function act differently in CS3 than CS4?

Post by ddbell »

Great!

This really helps me out. Thanks.
ddbell

Why does this zoom function act differently in CS3 than CS4?

Post by ddbell »

This works great except the zoom is 2.54x when the screen resolution is set to cm.


Here is what I want to do but I can't figure out the code to tell if the units are cm or inches.

I've searched all 3 of the Abode scripting PDF docs but there is nothing on the subject. Is there any documentation other than what Adobe has? How did you know to use newDocPresetScreenResolution to get the screen resolution? I can't find a reference to this anywhere.

Here is the code that I want to try except I need to figure out how to get the screen resolution units.


Code: Select allfunction getScreenRes(){
   var ref = new ActionReference();
   ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
   return executeActionGet(ref).getObjectValue(stringIDToTypeID('unitsPrefs')).getUnitDoubleValue(stringIDToTypeID('newDocPresetScreenResolution'))/72;
}

function getscreenresunits() {code?????????}

function setZoom( zoom ) {
   cTID = function(s) { return app.charIDToTypeID(s); };
   var docRes = activeDocument.resolution;
   activeDocument.resizeImage( undefined, undefined, zoomfactor/(zoom/100), ResampleMethod.NONE );
   var desc = new ActionDescriptor();
   var ref = new ActionReference();
   ref.putEnumerated( cTID( "Mn  " ), cTID( "MnIt" ), cTID( 'PrnS' ) );
   desc.putReference( cTID( "null" ), ref );
   executeAction( cTID( "slct" ), desc, DialogModes.NO );
   activeDocument.resizeImage( undefined, undefined, docRes, ResampleMethod.NONE );
}

zoomfactor = getScreenRes()
if (screenres == 'cm') {zoomfactor = zoomfactor/2.54}
setZoom (25);
Mike Hale

Why does this zoom function act differently in CS3 than CS4?

Post by Mike Hale »

The problem is that using Action Manager this way is not documented anywhere.

Another problem is Adobe still has bugs in some unitValues. At least I think they are bugs.

getUnitDoubleValue should get you the value of a unitValue and getUnitDoubleType should get you the unit. In this case getUnitDoubleValue returns what Adobe calls '#Rlt', which should be relative pixels at 72ppi. However it return the same value for both unitTypes used. For example it returns 7200 if the ScreenResolution is 100px/in or 100px/cm.

getUnitDoubleType returns 'distanceUnit'. So I am not sure how the script can know which unit to use.
ddbell

Why does this zoom function act differently in CS3 than CS4?

Post by ddbell »

Thanks for your reply.

Another option that may work for what I need is setting the zoom to "best fit". Is there a scripting command for the keyboard shortcut control+0 (command+0 on Mac)?
ddbell

Why does this zoom function act differently in CS3 than CS4?

Post by ddbell »

We'll, I just found this script from a 2006 posting on this site.

This works perfectly regardless of the screen resolution settings as long as you just need a standard zoom factor (25%,33%,50%,etc.). This should work out just fine for my needs.

Code: Select allfunction runMenuItem(item){
cTID = function(s) { return app.charIDToTypeID(s); };
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( cTID( "Mn  " ), cTID( "MnIt" ), cTID( item ) );
desc.putReference( cTID( "null" ), ref );
executeAction( cTID( "slct" ), desc, DialogModes.NO );
}
runMenuItem("ActP");//actual size 100%
runMenuItem("ZmOt");// zoom out
runMenuItem("ZmOt");
runMenuItem("ZmOt");