[ExtendScript] TextFrame cannot be selected after creating
In script, after creating a new TextFrame it cannot be selected the first time.
(function () {
if (0 === app.documents.length)
return alert('Please open a document and try again.');
var doc = app.activeDocument,
results = ['Results:'];
// experiment 1
var tf1 = doc.textFrames.add();
tf1.contents = '1. created, selected:';
tf1.selected = true;
results.push(tf1.contents + ' ' + (tf1.selected ? 'PASS' : 'FAIL'));
// experiment 2
var tf2 = doc.textFrames.add();
tf2.contents = '2. created, selected twice:';
tf2.selected = true;
tf2.selected = true;
results.push(tf2.contents + ' ' + (tf2.selected ? 'PASS' : 'FAIL'));
alert(results.join('\n'));
})();
Expected results: both tests would pass.
Actual results: only the second test passes.
See the discussion at this forum post.
Note: this only seems to happen with a TextFrame. PathItems, for example don't show this bug.
-
Ten_A commented
Hi mib,
I understand the purpose of this. I'll up vote it. -
m1b commented
Hi Ten_A, you're right. There are lots of things that make it work. I listed more ways in my code in the forum post. Often I try to avoid app.redraw() because I don't want to spawn another Undo record.
-
Ten_A commented
I think when we create an object and select it, better to execute the redraw method to update document window before selecting it.