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:
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:
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?
Copy link to clipboard
Copied
Hi
Try adding document.recompose () before the distribution
HTH
Trevor
P.s. not tested
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
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?
Copy link to clipboard
Copied
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
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
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