Copy link to clipboard
Copied
I wanted to check whether a text selection exists or not
var oDoc = app.ActiveDoc;
var oTsel = oDoc.TextSelection;
if (oTsel.ObjectValid()) {
alert ("we got it");
}
This creates an error during paring. I need to write
if (oTsel.beg.obj.ObjectValid()) {
Why is the selection itself is not considered an object - although is noticed as such in the data browser?
By default, a document will have an insertion point when it is first opened, but it is also possible to have a graphic selected, or to click in the margin and have no selection in a document. You can test for selections like this:
var doc;
// Testing with the active document.
doc = app.ActiveDoc;
if (doc.ObjectValid () === 1) {
if (doc.TextSelection.beg.obj.ObjectValid () === 1) {
alert ("There is an insertion point or text selected in the document.");
}
else if (doc.FirstSel
...
Copy link to clipboard
Copied
Hi Klaus, it is a Javascript Object, but not a FrameMaker Object. -Rick
Copy link to clipboard
Copied
Hi Klaus,
You could test the begining and ending text locations, object property, if you are wanting to test validity. If you do not mind what is the reason you are looking at doing this? AFAIK, having an active document means the insertion point has to be somewhere, so TextSelection will always have a value. It is the begining and ending text locations, their object values, and the offsets that I would normally be testing.
Jon
Copy link to clipboard
Copied
By default, a document will have an insertion point when it is first opened, but it is also possible to have a graphic selected, or to click in the margin and have no selection in a document. You can test for selections like this:
var doc;
// Testing with the active document.
doc = app.ActiveDoc;
if (doc.ObjectValid () === 1) {
if (doc.TextSelection.beg.obj.ObjectValid () === 1) {
alert ("There is an insertion point or text selected in the document.");
}
else if (doc.FirstSelectedGraphicInDoc.ObjectValid () === 1) {
alert ("There is at least one graphic selected.");
}
else {
alert ("Nothing is selected in the document.");
}
}