Hi All.
I've read two solutions for zoom.
First is here and other is here
I want to my code is working like setZoom. But this function is making history. Because It's call to resizeImage as you know. How can I zoom without history?? I've written code below that.
Code: Select allvar cTID = function(s) { return app.charIDToTypeID(s); };
var desc = new ActionDescriptor();
desc.putUnitDouble( cTID("Zm "), cTID("#Prc"), %value% );
executeAction( cTID("null"), desc, DialogModes.NO );
Sure! It doesn't work. Do you have any idea? Please let me know. Thank you.
How to zoom without resizeImage???
-
pfaffenbichler
How to zoom without resizeImage???
You could wrap the whole thing up in a function and use
Document.suspendHistory (historyString: string , javaScriptString: string )
to run the process with one History entry – not sure if that is much help to you.
Document.suspendHistory (historyString: string , javaScriptString: string )
to run the process with one History entry – not sure if that is much help to you.
-
undavide
How to zoom without resizeImage???
I was looking to zooming solutions too, and I've run into this topic.
Strangely enough the reported code:
Code: Select allvar cTID = function(s) { return app.charIDToTypeID(s); };
var desc = new ActionDescriptor();
desc.putUnitDouble( cTID("Zm "), cTID("#Prc"), %value% );
executeAction( cTID("null"), desc, DialogModes.NO );
it doesn't operate zoom, instead it opens Image Processor to me (CS6, OSX). I'm wondering... why on earth?!
As a side note, I've seen also this one:
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
I'm aware of X getter, but I was wondering how to use it to retrieve all the charID of menu items (I know "ZmOt", "ActP", etc, but how could I list them all?)
Thanks
Davide
Strangely enough the reported code:
Code: Select allvar cTID = function(s) { return app.charIDToTypeID(s); };
var desc = new ActionDescriptor();
desc.putUnitDouble( cTID("Zm "), cTID("#Prc"), %value% );
executeAction( cTID("null"), desc, DialogModes.NO );
it doesn't operate zoom, instead it opens Image Processor to me (CS6, OSX). I'm wondering... why on earth?!
As a side note, I've seen also this one:
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
I'm aware of X getter, but I was wondering how to use it to retrieve all the charID of menu items (I know "ZmOt", "ActP", etc, but how could I list them all?)
Thanks
Davide
-
Mike Hale
How to zoom without resizeImage???
undavide, here is a list of ID related to the screen menu.
"FtOn"
"ActP"
"ZmIn"
"ZmOt"
"screenModeFullScreen"
"screenModeStandard"
"screenModeFullScreenWithMenubar"
sewonist, the document descriptor does have a key that holds the current zoom percentage of the document but I have not been able to come up with a way to set that key. If you are willing to use standard screen zoom levels I guess you could get the current zoom then loop a zoom in or zoom out until you get the zoom level you want.
Something like this:
Code: Select allfunction getActiveDocumentZoom(){
var ref;
ref = new ActionReference();
ref.putProperty( charIDToTypeID( "Prpr" ),charIDToTypeID('Zm '));
ref.putEnumerated(charIDToTypeID('Dcmn'), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
return (executeActionGet(ref).getUnitDoubleValue (charIDToTypeID('Zm ')))*100;
};
function setZoomToNearestStandardZoom( zoomPercent ){
var currentZoom;
currentZoom = getActiveDocumentZoom();
while( currentZoom > zoomPercent ){
app.runMenuItem(charIDToTypeID('ZmOt'));
currentZoom = getActiveDocumentZoom();
}
while( currentZoom < zoomPercent ){
app.runMenuItem(charIDToTypeID('ZmIn'));
currentZoom = getActiveDocumentZoom();
}
}
setZoomToNearestStandardZoom(50);
"FtOn"
"ActP"
"ZmIn"
"ZmOt"
"screenModeFullScreen"
"screenModeStandard"
"screenModeFullScreenWithMenubar"
sewonist, the document descriptor does have a key that holds the current zoom percentage of the document but I have not been able to come up with a way to set that key. If you are willing to use standard screen zoom levels I guess you could get the current zoom then loop a zoom in or zoom out until you get the zoom level you want.
Something like this:
Code: Select allfunction getActiveDocumentZoom(){
var ref;
ref = new ActionReference();
ref.putProperty( charIDToTypeID( "Prpr" ),charIDToTypeID('Zm '));
ref.putEnumerated(charIDToTypeID('Dcmn'), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
return (executeActionGet(ref).getUnitDoubleValue (charIDToTypeID('Zm ')))*100;
};
function setZoomToNearestStandardZoom( zoomPercent ){
var currentZoom;
currentZoom = getActiveDocumentZoom();
while( currentZoom > zoomPercent ){
app.runMenuItem(charIDToTypeID('ZmOt'));
currentZoom = getActiveDocumentZoom();
}
while( currentZoom < zoomPercent ){
app.runMenuItem(charIDToTypeID('ZmIn'));
currentZoom = getActiveDocumentZoom();
}
}
setZoomToNearestStandardZoom(50);
-
undavide
How to zoom without resizeImage???
Hi Mike,
thanks for your list - can I ask you how did you come up with it (I did found them in previous topics as well, but I'm interested in extracting them via getters and ActionManager code)?
Does anyone else have the same issue with the code (opening Image Processor instead of zooming)?
Many questions as usual
Thank you!
Davide
thanks for your list - can I ask you how did you come up with it (I did found them in previous topics as well, but I'm interested in extracting them via getters and ActionManager code)?
Does anyone else have the same issue with the code (opening Image Processor instead of zooming)?
Many questions as usual
Thank you!
Davide
-
Mike Hale
How to zoom without resizeImage???
For menu items that scriptlistener doesn't record like the zoom and screenModes, I record a one step action using the flyout menu item 'Insert Menu Item...' in the actions panel. Then I save the action and either look at it with an hex editor or use Xbytor's action to xml or action to javascript scripts depending on what I am trying to do.
I don't know of anyway to get these kinds of IDs using getter.
I don't know of anyway to get these kinds of IDs using getter.
-
undavide
How to zoom without resizeImage???
Mike Hale wrote:For menu items that scriptlistener doesn't record like the zoom and screenModes, I record a one step action using the flyout menu item 'Insert Menu Item...' in the actions panel. Then I save the action and either look at it with an hex editor or use Xbytor's action to xml or action to javascript scripts depending on what I am trying to do.
Neat idea, thanks Mike!
Davide
Neat idea, thanks Mike!
Davide
-
kostyanet
How to zoom without resizeImage???
My old rough script. Linked to open command via Script Event Manager.
Code: Select all
zoomout(3);
function zoomout(zoom) {
if (app.documents.length < 1) return;
var doc = app.activeDocument;
var w = doc.width;
var h = doc.height;
var max = (w > h)?w:h;
max.baseUnit = UnitValue(1/doc.resolution, 'in');
if(max.as('px') < 300) return;
var k1 = w.value / h.value;
var k2 = 1/k1;
switch(true){
case (k1 > 2 || k2 > 2): zoom = 1; break;
case (k1 > 1.5 || k2 > 1.5): zoom = 2; break;
}
var kbdz = app.preferences.keyboardZoomResizesWindows;
app.preferences.keyboardZoomResizesWindows = true;
for(i = 0; i < zoom; i++) imageView(1517113204); // zoom out
app.preferences.keyboardZoomResizesWindows = kbdz;
//imageView('FtOn'); // equivalent to Ctrl0 = 1182027630
//imageView('ZmIn'); // zoom in = 1517111662
//imageView('ZmOt'); // zoom out = 1517113204
// "slct" = 1936483188
// "MnIt" = 1299073396
// "Mn " = 1299062816
// "null" = 1853189228
function imageView (view) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( 1299062816, 1299073396, view );
desc.putReference( 1853189228, ref );
executeAction( 1936483188, desc, DialogModes.NO );
}
}
Code: Select all
zoomout(3);
function zoomout(zoom) {
if (app.documents.length < 1) return;
var doc = app.activeDocument;
var w = doc.width;
var h = doc.height;
var max = (w > h)?w:h;
max.baseUnit = UnitValue(1/doc.resolution, 'in');
if(max.as('px') < 300) return;
var k1 = w.value / h.value;
var k2 = 1/k1;
switch(true){
case (k1 > 2 || k2 > 2): zoom = 1; break;
case (k1 > 1.5 || k2 > 1.5): zoom = 2; break;
}
var kbdz = app.preferences.keyboardZoomResizesWindows;
app.preferences.keyboardZoomResizesWindows = true;
for(i = 0; i < zoom; i++) imageView(1517113204); // zoom out
app.preferences.keyboardZoomResizesWindows = kbdz;
//imageView('FtOn'); // equivalent to Ctrl0 = 1182027630
//imageView('ZmIn'); // zoom in = 1517111662
//imageView('ZmOt'); // zoom out = 1517113204
// "slct" = 1936483188
// "MnIt" = 1299073396
// "Mn " = 1299062816
// "null" = 1853189228
function imageView (view) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( 1299062816, 1299073396, view );
desc.putReference( 1853189228, ref );
executeAction( 1936483188, desc, DialogModes.NO );
}
}