0

Ok, let's say I have this textFrame selected:

starting point

I want to apply this:

Fit Frame To Content

To get this expected result:

wanted result

With this code it's no problem:

var doc = app.activeDocument;
var target = doc.selection[0];
target.fit(FitOptions.frameToContent);

But as soon as I set the content it goes wrong. Even if the content is the same to what it was.

var doc = app.activeDocument;
var target = doc.selection[0]; 
target.contents = "0209 - Lorem ipsum dolor sit amet consectetur adipiscing elit nam finibus ut justo at fermentum maecenas tincidun libero at aliquet finibus libero sem semper massa.";
target.fit(FitOptions.frameToContent);

Now I get 1 big line!:

unwanted result

Is this a bug, or do I need to trigger an update method or something?

clankill3r
  • 9,146
  • 20
  • 70
  • 126
  • 1
    (Untested) Add `target.recompose()` after setting the contents. Composing (i.e., breaking the text into lines) usually happens in the background; ID just may not have the time between your two function calls to do so. – Jongware Nov 13 '14 at 23:03

1 Answers1

2

Add target.recompose() after setting the contents. Composing (i.e., breaking the text into lines) usually happens in the background; ID just may not have the time between your two function calls to do so.

It's not clear from the documentation when you need to explicitly call recompose, but as a rule of thumb you can assume interacting through a text contents property always needs it. The contents of a native InDesign text are translated from and to a Javascript string object, and thus loose all 'native' formatting, including any and all paragraph composition.

I just tried it with my trusty old CS4 and there it works without recompose as well, although that is not conclusive; InDesign just may have had 'the time' to do it in the background, with no other tasks running. So forcing it may still be a good idea.

Jongware
  • 22,200
  • 8
  • 54
  • 100