• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

[JS] How to control the scroll bar of the document?

Contributor ,
Dec 22, 2015 Dec 22, 2015

Copy link to clipboard

Copied

Hi.

I would like to the scroll bar move to a position I want to.

I could not find that I want in the "app.layoutWindow[0]".

Any Ideas?

Thanks.

TOPICS
Scripting

Views

412

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 23, 2015 Dec 23, 2015

Ideas?


This one:

Add a helper element, could be a rectangle, to the center of the window you like to see after scrolling.

Store your current zoom value.

Select the helper element.

Change the zoom value to zoom in.

Change the zoom value to your original value (or your intended value).

Remove the helper element.

Caveats:

Some positions will not work as expected, because of limitations in the size of the pasteboard.

Especially if the center of the resulting "view port" should be on the pasteboard.

Some code;

...

Votes

Translate

Translate
Community Expert ,
Dec 23, 2015 Dec 23, 2015

Copy link to clipboard

Copied

Ideas?


This one:

Add a helper element, could be a rectangle, to the center of the window you like to see after scrolling.

Store your current zoom value.

Select the helper element.

Change the zoom value to zoom in.

Change the zoom value to your original value (or your intended value).

Remove the helper element.

Caveats:

Some positions will not work as expected, because of limitations in the size of the pasteboard.

Especially if the center of the resulting "view port" should be on the pasteboard.

Some code; just an example, that should be adapted to your needs:

var doc = app.documents[0];

var layoutWindow = doc.layoutWindows[0];

// Find a better way to determine the right position.
// For now the helper rectangle will be positioned on that page.

var page = layoutWindow.activePage;

var currentZoomPercentage = layoutWindow.zoomPercentage;

var currentZeroPoint = doc.zeroPoint;

var viewPreferencesOfDoc = doc.viewPreferences.properties;

doc.viewPreferences.properties =

{

    rulerOrigin : RulerOrigin.PAGE_ORIGIN,

    horizontalMeasurementUnits : MeasurementUnits.MILLIMETERS,

    verticalMeasurementUnits : MeasurementUnits.MILLIMETERS

  

};

doc.zeroPoint = [0,0];

// Note: You could work with the bounds of the page to determine a relative position to the page like:

// Center of quadrant 3 of the page etc.pp.

// A square 2 x 2 millimeters is added and selected:

var helperRectangle = page.rectangles.add({geometricBounds : [170,130,172,132]});

doc.select(helperRectangle);

// Changing the zoom percentage will zoom in to the selected object:

// Maybe I found a bug here, the value must not exceed 2000, anything above will throw an error.

// Tested with InDesign CC 2015.2 v11.2.0.99 on Mac OSX (German)

layoutWindow.zoomPercentage = 2000;

// Zoom out again to the original value:

layoutWindow.zoomPercentage = currentZoomPercentage;

// Tidy up a bit:

// Remove the helper:

helperRectangle.remove();

// Reset the view preferences and the zero point:

doc.viewPreferences.properties = viewPreferencesOfDoc;

doc.zeroPoint = currentZeroPoint;

Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 23, 2015 Dec 23, 2015

Copy link to clipboard

Copied

LATEST

It works perfectly.

Thank you very mach.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines