Quitter
  • Communauté internationale
    • Langue:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티

apply master page after page size change

Engagé ,
Jul 19, 2016 Jul 19, 2016

I'm having trouble. I am changing the page size to crop then exporting to jpeg. Then I change the page size back works great but the master page becomes disconnected. I can't figure out how to apply it again.

I am trying something like this

var myDocument=app.activeDocument;

var curPage = myDocument.pages[1];

X=curPage.appliedMaster;

This does nothing.

A point in the right direction would help alot thanks.

Brett G

SUJETS
Scripting
4.7K
Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines

correct answers 1 bonne réponse

Guide , Jul 28, 2016 Jul 28, 2016

Hi colleagues,

OK, my two pennies on this topic.

Reframing pages is always a dangerous sport, especially in a facing-page document. Indeed, since those facing pages are not supposed to undergo any 'move' along the X-axis, each time a reframe occurs that involves changing X coordinates, many unexpected things may happen behind the scene. The page geometry is modified, its translation attributes are readjusted in its transformation matrix, the relationship with the master spread may be somehow alter

...
Traduire
Engagé ,
Jul 27, 2016 Jul 27, 2016

So even though I say

measure=app.scriptPreferences.measurementUnit = MeasurementUnits.PICAS;

reframe reads it in points.

and even though I say

document.viewPreferences.rulerOrigin = RulerOrigin.SPINE_ORIGIN;

it reads as a spread.

That "54" you see up there on the ruler that's the end of my document when my document is showing from the spine.

But the bounds is reading in Picas by the way the whole damn spread.

But reframe is going to use points. Can anyone explain this???

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
Jul 27, 2016 Jul 27, 2016

All transform functions work with Points only.
Or nearly all? I have to check that…

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Engagé ,
Jul 27, 2016 Jul 27, 2016

So I was using bounds as a basis for my reframe. However bounds can be any measurement and be measured from Spine, Page, or Spread. So if you are using reframe make sure that your measurements are in points either in the script or change preferences to points. Then also set Ruler per Spread. This was accounting for the shift in the applied master page.

document.viewPreferences.rulerOrigin =RulerOrigin.SPREAD_ORIGIN

measure=app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
Jul 27, 2016 Jul 27, 2016
Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Engagé ,
Jul 28, 2016 Jul 28, 2016

well today is a new day. Nothing has changed except I feel like i am back to square one because its not working again.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Engagé ,
Jul 28, 2016 Jul 28, 2016

No one wants to be done with this more than me. This is a long post. So I really thought I solved the problem switching to points and changing to read from spread, so smart. Not really. I've done this so many times I had changed the file. Giving me a false positive. So the script changes the page by using reframe. When it finishes the right side of the master gets applied to the left. Then if I apply master to each page individually then reapply the master as a spread. And I have that as my starting point. I can run the same script every time and it will apply the master just fine. The problem is I have no idea why this happens. Does anyone have experience reframing pages? I kind of hate the idea of having to loop back around twice.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Enthousiaste ,
Jul 28, 2016 Jul 28, 2016

Just to say it again: Why do you ignore my comment a week ago? In my opinion there is really no need to do all this stuff...

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Engagé ,
Jul 28, 2016 Jul 28, 2016

I am doing this to crop. If the items hang outside and i group what will the bounds be?

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Enthousiaste ,
Jul 28, 2016 Jul 28, 2016

What do you mean with 'outside'? If you group your elements you can then just export the selection.

If you need also elements from a masterpage, you could separate elements from the master.

If all this stuff does not work, you could save your doc, did your masterpage thing and close the document without saving.

So: Provide a example before/after (not only screenshots) and don’t make things so complicated 😉

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Guide ,
Jul 28, 2016 Jul 28, 2016

Hi colleagues,

OK, my two pennies on this topic.

Reframing pages is always a dangerous sport, especially in a facing-page document. Indeed, since those facing pages are not supposed to undergo any 'move' along the X-axis, each time a reframe occurs that involves changing X coordinates, many unexpected things may happen behind the scene. The page geometry is modified, its translation attributes are readjusted in its transformation matrix, the relationship with the master spread may be somehow altered, and as discussed in other threads bugs or issues with the masterPageTransform property may occur, weird shifts that seem unrepairable, not to mention the options related to layout rules, and so on.

So it's hard to design a script that works in all environments, all versions, all configurations. There is always an obscure preference that someone has activated, or disabled, which interacts with the whole system and ruins all our effort.

There is at least one law that we have learned from experience: DO NEVER TRUST the page.bounds property. If you attempt to reframe pages, assuming that no better solution has been found, try to work with properly resolved coordinates—myPage.resolve(…)—and stick to the tools that coordinate spaces and transformation provide. Here is an attempt to fix your problem on this basis.

Try this:

// YOUR SETTINGS

// =====================================

// Values required IN POINTS (negative numbers allowed, for increasing the area.)

// ---

const CROP_SIDE   = 12.225/*pt*/,

      CROP_TOP    = 12.225/*pt*/,

      CROP_BOTTOM = 100/*pt*/;

// Export options, etc.

// ---

const DOC_NAME_MAX_SIZE = 12,

      OUT_PATH = "/Volumes/Testing/binuscan Test/BookViewerTest/";

const JPG_EXPORT_PREFS = {

    jpegQuality:      +JPEGOptionsQuality.high,

    exportResolution: 170,

    jpegExportRange:  +ExportRangeOrAllPages.exportRange,

    };

(function exportPageAreas()

// =====================================

// Should support the tricky 'facing-page' case, including when

// pages have different sizes, and whatever the rulerOrigin mode.

{

    // Boring constants.

    // ---

    const CS_INNER = +CoordinateSpaces.INNER_COORDINATES,

          CS_SPREAD = +CoordinateSpaces.SPREAD_COORDINATES,

          TL = +AnchorPoint.TOP_LEFT_ANCHOR,

          BR = +AnchorPoint.BOTTOM_RIGHT_ANCHOR;

    const LEFT_HAND = +PageSideOptions.LEFT_HAND;

    // Context validation.

    // ---

    var doc = app.properties.activeDocument;

    if( !doc ){ alert( "No document!" ); return; }

    // Export prefs.

    // ---

    const EXP_JPG = +ExportFormat.JPG,

          JEP = app.jpegExportPreferences,

          filePrefix = OUT_PATH + doc.properties.name.substr(-DOC_NAME_MAX_SIZE);

    JEP.properties = JPG_EXPORT_PREFS;

    // Last variables.

    // ---

    var pages = doc.pages.everyItem().getElements(),

        pg, pgName,

        dxLeft, dxRight,

        xyTL, xyBR;

    // Loop.

    // ---

    while( pg=pages.pop() )

    {

        // Page corners coords in the parent space.

        // (Note: Do Never Trust page.bounds!)

        // ---

        xyTL = pg.resolve(TL, CS_SPREAD)[0];

        xyBR = pg.resolve(BR, CS_SPREAD)[0];

        // Opposite corners => reframe.

        // ---

        dxLeft  = LEFT_HAND == +pg.side ? CROP_SIDE : 0;

        dxRight = dxLeft ? 0 : CROP_SIDE;

        pg.reframe( CS_SPREAD,

        [

            [ xyTL[0]+dxLeft,  xyTL[1]+CROP_TOP ],

            [ xyBR[0]-dxRight, xyBR[1]-CROP_BOTTOM ]

        ]);

        // Export.

        // ---

        JEP.pageString = pgName = pg.name;

        doc.exportFile(EXP_JPG, new File(filePrefix+('00'+pgName).substr(-3)+'.jpg'));

        // Restore page. Here we can't safely re-use [xyTL,xyBR] as it is,

        // because the spread space origin *may* have moved during reframe.

        // Therefore we need to formally reverse the calculation.

        // ---

        xyTL = pg.resolve(TL, CS_SPREAD)[0];

        xyBR = pg.resolve(BR, CS_SPREAD)[0];

        pg.reframe( CS_SPREAD,

        [

            [ xyTL[0]-dxLeft,  xyTL[1]-CROP_TOP ],

            [ xyBR[0]+dxRight, xyBR[1]+CROP_BOTTOM ]

        ]);

    }

   

    alert( 'Page areas have been successfully exported.' );

})();

May work or may fail… Who knows?

@+

Marc

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Engagé ,
Jul 29, 2016 Jul 29, 2016

I am amazed! Marc you are a genius. It looks at first glance to me that my problem may have been with bounds. I saw resolve in the sdk but had no idea how to use it. Everyone who sees this can crop away with ease.

Thank you.

Brett Gonterman

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Engagé ,
Dec 16, 2016 Dec 16, 2016
LA PLUS RÉCENTE

Cropping away with ease is not entirely true. There have been some bobbles. I am not sure why but there are files that crop up that have individual pages with some objects that still move. The problems that Marc talks about are real.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
Jul 28, 2016 Jul 28, 2016

Gonterman1201 wrote:

… Does anyone have experience reframing pages? I kind of hate the idea of having to loop back around twice.

Hi Brett,

if and only if you have a solution for reframing pages successfully and your real problems are the fact, that you cannot get back the original sizes and positions of the pages, why don't you simply:

1. Reframe the pages

2. Export to JPEG

3. Close doc without saving.

4. Open doc again

var myDocument = app.documents[0];

var fileOfDocument = File(myDocument.fullName);

myDocument.save();

/*

Do your stuff here.

*/

myDocument.close(SaveOptions.NO);

app.open(fileOfDocument);

I know, this sounds like cheating, but if it will help … ?! So what.

Best,
Uwe

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines