• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Why is a text selection not an object?

Community Expert ,
May 04, 2022 May 04, 2022

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?

TOPICS
Scripting

Views

123

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 09, 2022 May 09, 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.FirstSel
...

Votes

Translate

Translate
Community Expert ,
May 04, 2022 May 04, 2022

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 08, 2022 May 08, 2022

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 09, 2022 May 09, 2022

Copy link to clipboard

Copied

LATEST

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

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines