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

Auto-size not refreshing after GREP

Contributor ,
Jun 06, 2016 Jun 06, 2016

Copy link to clipboard

Copied

I have a script where I have text blocks that are populated by data and then those text blocks are distributed vertically. However I have run into an issue where the text blocks are not auto-resizing before the distribution is performed.

To replicate this issue:

  • Create a new document
  • Draw a text box
  • Enable auto-size on it (height only)
  • Put at least two lines of text in it

Now run this script:

var removeBlankParagraphs = function(p_item) {

  app.findGrepPreferences = NothingEnum.nothing;

  app.changeGrepPreferences = NothingEnum.nothing;

  app.findGrepPreferences.findWhat = '(?-m)\\r+$';

  app.changeGrepPreferences.changeTo = '';

  p_item.changeGrep();

};

var document = app.activeDocument,

  template = document.pageItems[0],

  pageItem,

  pageItems = [],

  character;

for (var i = 0; i < 4; i++) {

  pageItem = template.duplicate();

  pageItems.push(pageItem);

  pageItem.lines.lastItem().remove();

  removeBlankParagraphs(pageItem);

}

template.remove();

document.distribute(pageItems, DistributeOptions.VERTICAL_SPACE, undefined, true, 5, pageItems[0]);

So what is meant to happen here is:

  • The text box is duplicated 4 times
  • The last paragraph is deleted on each duplicate
  • The duplicates are distributed by 5 ruler units

However if you measure the distance between them they are not 5 ruler units. What seems to be happening here is that the text boxes are not auto-sizing right after the last paragraph is removed... It resizes after the distribute function.

How do I fix this?

TOPICS
Scripting

Views

582

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
Guru ,
Jun 06, 2016 Jun 06, 2016

Copy link to clipboard

Copied

Hi

Try adding  document.recompose () before the distribution

HTH

Trevor

P.s. not tested

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
Community Expert ,
Jun 06, 2016 Jun 06, 2016

Copy link to clipboard

Copied

Hi Trevor,

another trick is to move a path point of a text frame back and forth.

That should trigger an implicit recompose().

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 ,
Jun 06, 2016 Jun 06, 2016

Copy link to clipboard

Copied

I had not heard of this function. Thank you for brining it to my attention. I will test it today and see how it goes. This may also fix another bug I am experiencing where on odd occasions PDFs are exporting without images.

Why does InDesign need this function. Is it just the application just not keeping up with the engine?

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
Guru ,
Jun 08, 2016 Jun 08, 2016

Copy link to clipboard

Copied

LATEST

Recomposing is very resource intensive and it would really slow things down if after every little scripting tweak the document was recomposed but sometimes it's needed and hence the command.

Please mark the question as answered, Thanks

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
People's Champ ,
Jun 06, 2016 Jun 06, 2016

Copy link to clipboard

Copied

In the past, I've found that just doing myDoc.recompose() doesn't work so well.

Instead, you can try, after a little pause, invoking the menu item, which seems to work better:

$.sleep(1000);

app.menuActions.itemByName("$ID/Recompose all stories").invoke();

Ariel

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
Guru ,
Jun 06, 2016 Jun 06, 2016

Copy link to clipboard

Copied

Hi Ariel

Interesting to note. Are there times when the menu action hasn't worked for you?

I wonder if Uwe's method is failsafe?

Have you tried calling  myDoc.recompose() twice?  sometimes double calling helps.

Trevor

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