Skip to main content
K.Daube
Community Expert
Community Expert
May 4, 2022
Answered

Why is a text selection not an object?

  • May 4, 2022
  • 2 replies
  • 305 views

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?

This topic has been closed for replies.
Correct answer frameexpert

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.");
    }
}

 

2 replies

JonBe
Inspiring
May 9, 2022

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

frameexpert
Community Expert
frameexpertCommunity ExpertCorrect answer
Community Expert
May 9, 2022

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.");
    }
}

 

frameexpert
Community Expert
Community Expert
May 4, 2022

Hi Klaus, it is a Javascript Object, but not a FrameMaker Object. -Rick