I first though you might have an issue using itemByName as XMLElements has no itemByName methods but it looks like the script engine can deal with it. I did a quick try here and it works fine.
You should investigate the _toptitleFrame prior and after the fit operation to get for example its bounds. Did they change in the script scope ?
I changed line 4 to:
_toptitleFrame.contents = "test";
and it works perfectly.
But as I said: In the UI everything works fine ...
I used itemByName quite naturally and never thought about if it is available or not, but it works. Very interesting ...
So my workaround is finally this:
_toptitleFrame.contents = _theNode.xmlElements.itemByName("label").contents; _toptitleFrame.fit(FitOptions.FRAME_TO_CONTENT); _toptitleFrame.move([(213-(_toptitleFrame.geometricBounds-_toptitleFrame.geometricBounds)), 12.7]); // move to right bleed _toptitleFrame.contents = ""; _theNode.xmlElements.itemByName("label").placeXML(_toptitleFrame); // place XML to frame
It’s a bit dirty, but works ... Any further suggestions are very welcome!
@Tobias – yes, but also a "dirty" trick.
Select the text frame with app.select() //EDIT: or app.documents.select(myTextFrame) and invoke the approriate menuAction to fit the frame.
It's name would be: "$ID/Fit Frame to Content".