Skip to main content
Inspiring
December 16, 2019
Answered

Automate view

  • December 16, 2019
  • 3 replies
  • 1065 views

Does anyone know of a way to automate switching to a particular page, at a particular zoom, at a particular location. I have thousands of similar documents and sometimes it would be nice to be able to just hit a keystroke that opened at a particular view of, for example, the index at a particular zoom and place (always p.3 for many of my docs).

 

 

This topic has been closed for replies.
Correct answer Laubender

Hi zimbop,

let's tackle the particular location issue for the zoom.

 

My idea is to use a unique object in the document, e.g. a rectangle with a unique name, that a script can select and zoom to. Let's say the name of that zoom item should be ZoomCenter.

 

Best draw out a rectangle on the page you want to zoom to. Could be any size.

Rename the rectangle in the Layers panel to ZoomCenter.

 

The script code below will identify it by its name, selects it and zooms to it. Then it will be deselected.

 

Suggestion: You could put the zoom item named ZoomCenter to an extra layer.

Even if you lock the layer the zoom item can be selected by the script.

Even if you set the layer to invisible the zoom item can be selected by the script.

Even if you lock the zoom item the script will work.

Even if you make the item invisible the script will work.

 

The code below is written in ExtendScript ( JavaScript ) and should work with all versions of InDesign after CS4.

To change the zoom percentage value just edit the number in the line:

var zoomToPercentage = 200 ;

 

If you want to use a different name for your zoom item, rename the object in the Layers panel and use exactly the same name in the code where it says:

var zoomItemName = "ZoomCenter";

 

 

How to work with ExtendScript code see e.g. here:

http://www.indiscripts.com/pages/help#hd0sb2

 

/**
* @@@BUILDINFO@@@ ZoomToSelectedObjectOnPage-using-activeSpread.jsx !Version! Tue Dec 17 2019 15:34:39 GMT+0100
*/

/*
	Written by Uwe Laubender
	Posted at Adobe InDesign Forum at:
	
	Automate view
	zimbop, Dec 16, 2019
	https://community.adobe.com/t5/indesign/automate-view/td-p/10805230
	
	What does the script do?
	It zooms to an object in the INDD document that has a unique name.
	
	The object could be anything that could be named in the Layers panel.
	A graphic frame, a text frame, a graphic line etc. pp.
	
	The object should not be grouped, anchored or nested otherwise.
	Script works with InDesign CS5 version 7 and above.
	
*/

( function()
{
	// TYPE A DIFFERENT VALUE OF ZOOM BELOW:
	var zoomToPercentage = 200 ;
	
	// IF YOU WANT TO CHANGE THE NAME OF THE OBJECT DO IT ALSO HERE:
	var zoomItemName = "ZoomCenter";
	
	
	
	// BEST DO NOT EDIT CODE BELOW.
	
	var min = 5 ;
	
	// Because of a bug we cannot zoom by script to maximum 4000%
	var max = 2000 ; 
	
	// If zoom percentage is out of range, do nothing:
	if( zoomToPercentage < min || zoomToPercentage > max ){ return };
	
	// If no document is open, do nothing:
	if( app.documents.length == 0 ){ return };
	
	var targetDoc = app.documents[0];
	var zoomItem = targetDoc.pageItems.itemByName( zoomItemName );
	
	// If there is no zoom item found, do nothing:
	if( !zoomItem.isValid ){ return };
	
	var zoomItemLockedState = zoomItem.locked ;
	var zoomItemVisibleState = zoomItem.visible ;

	var targetSpread = zoomItem.parent;

	// Make the spread of the target page the active spread:
	targetDoc.layoutWindows[0].activeSpread = targetSpread ;
	
	zoomItem.locked = false ;
	zoomItem.visible = true ;
	
	// Select the zoom item by script:
	// NOTE: Possible even if the layer of the item is locked!
	// NOTE: Possible even if the layer of the item is set to invisible!
	targetDoc.select( zoomItem );

	// Apply the zoom value:
	targetDoc.layoutWindows[0].zoomPercentage = zoomToPercentage ;
	
	// Deselect everything:
	targetDoc.select( null );
	
	// Reset the values for locked and visible to the item:
	zoomItem.locked = zoomItemLockedState ;
	zoomItem.visible = zoomItemVisibleState ;

}() )

 

Regards,
Uwe Laubender

( ACP )

3 replies

Community Expert
December 17, 2019

Hi zimbop,

of course one could add functionality to this script.

But this would require some time and effort.

A GUI and a preferences file etc. etc. And a way to record where you were coming from before executing the zoom script so that you can easily toggle.

 

For now you could do a very small rectangle as zoom item so if InDesign zooms to the center of the selection you could nearly pinpoint the center of the zoom if you like.

 

Oh. And if your screen estates allows you can open a second layout window of the same document and zoom to your favored  spot so that you have both views side by side. All without using a script at all.

 

Regards,
Uwe Laubender

( ACP )

MrZZYAuthor
Inspiring
December 17, 2019

Ah yes, excellent point about the smaller rectangle! Thanks so much. I'd really like to be able to create and extend smaller tasks like this with scripting myself. Very inspirational. Thanks again.

LaubenderCommunity ExpertCorrect answer
Community Expert
December 17, 2019

Hi zimbop,

let's tackle the particular location issue for the zoom.

 

My idea is to use a unique object in the document, e.g. a rectangle with a unique name, that a script can select and zoom to. Let's say the name of that zoom item should be ZoomCenter.

 

Best draw out a rectangle on the page you want to zoom to. Could be any size.

Rename the rectangle in the Layers panel to ZoomCenter.

 

The script code below will identify it by its name, selects it and zooms to it. Then it will be deselected.

 

Suggestion: You could put the zoom item named ZoomCenter to an extra layer.

Even if you lock the layer the zoom item can be selected by the script.

Even if you set the layer to invisible the zoom item can be selected by the script.

Even if you lock the zoom item the script will work.

Even if you make the item invisible the script will work.

 

The code below is written in ExtendScript ( JavaScript ) and should work with all versions of InDesign after CS4.

To change the zoom percentage value just edit the number in the line:

var zoomToPercentage = 200 ;

 

If you want to use a different name for your zoom item, rename the object in the Layers panel and use exactly the same name in the code where it says:

var zoomItemName = "ZoomCenter";

 

 

How to work with ExtendScript code see e.g. here:

http://www.indiscripts.com/pages/help#hd0sb2

 

/**
* @@@BUILDINFO@@@ ZoomToSelectedObjectOnPage-using-activeSpread.jsx !Version! Tue Dec 17 2019 15:34:39 GMT+0100
*/

/*
	Written by Uwe Laubender
	Posted at Adobe InDesign Forum at:
	
	Automate view
	zimbop, Dec 16, 2019
	https://community.adobe.com/t5/indesign/automate-view/td-p/10805230
	
	What does the script do?
	It zooms to an object in the INDD document that has a unique name.
	
	The object could be anything that could be named in the Layers panel.
	A graphic frame, a text frame, a graphic line etc. pp.
	
	The object should not be grouped, anchored or nested otherwise.
	Script works with InDesign CS5 version 7 and above.
	
*/

( function()
{
	// TYPE A DIFFERENT VALUE OF ZOOM BELOW:
	var zoomToPercentage = 200 ;
	
	// IF YOU WANT TO CHANGE THE NAME OF THE OBJECT DO IT ALSO HERE:
	var zoomItemName = "ZoomCenter";
	
	
	
	// BEST DO NOT EDIT CODE BELOW.
	
	var min = 5 ;
	
	// Because of a bug we cannot zoom by script to maximum 4000%
	var max = 2000 ; 
	
	// If zoom percentage is out of range, do nothing:
	if( zoomToPercentage < min || zoomToPercentage > max ){ return };
	
	// If no document is open, do nothing:
	if( app.documents.length == 0 ){ return };
	
	var targetDoc = app.documents[0];
	var zoomItem = targetDoc.pageItems.itemByName( zoomItemName );
	
	// If there is no zoom item found, do nothing:
	if( !zoomItem.isValid ){ return };
	
	var zoomItemLockedState = zoomItem.locked ;
	var zoomItemVisibleState = zoomItem.visible ;

	var targetSpread = zoomItem.parent;

	// Make the spread of the target page the active spread:
	targetDoc.layoutWindows[0].activeSpread = targetSpread ;
	
	zoomItem.locked = false ;
	zoomItem.visible = true ;
	
	// Select the zoom item by script:
	// NOTE: Possible even if the layer of the item is locked!
	// NOTE: Possible even if the layer of the item is set to invisible!
	targetDoc.select( zoomItem );

	// Apply the zoom value:
	targetDoc.layoutWindows[0].zoomPercentage = zoomToPercentage ;
	
	// Deselect everything:
	targetDoc.select( null );
	
	// Reset the values for locked and visible to the item:
	zoomItem.locked = zoomItemLockedState ;
	zoomItem.visible = zoomItemVisibleState ;

}() )

 

Regards,
Uwe Laubender

( ACP )

MrZZYAuthor
Inspiring
December 17, 2019

I'll have a good look at this - thanks Uwe!

Derek Cross
Community Expert
Community Expert
December 16, 2019

What is the output format?

MrZZYAuthor
Inspiring
December 16, 2019

Not output > Screen. Literally, the view. Quickly setting up a bunch of documents that are all set to view at page 4 at a particular zoom in a particular place.

Derek Cross
Community Expert
Community Expert
December 16, 2019

Within InDesign, Command/Control J takes you to the page you select and there are various zoom commands, such as Command/Control 0 to Fit Page to Window.