Wednesday, November 23, 2011

Working with Selections

My plan is to write a script that determines the page location of the current user selection. This means figuring out what, if anything, in the document of interest is selected.

This script makes use of three document properties:
  • TextSelection returns the text range for the current text selection.
  • SelectedTbl returns the identifier of the selected table.
  • FirstSelectedGraphicInDoc returns the identifier of the first in a list of selected graphics objects. NextSelectedGraphicsInDoc, a property of the first object found, takes you to the next object in the list. 
Some things to note:
  • If there is an insertion point or a selected text range within a table cell, that table is not selected. For a table to be selected, the entire table, the entire table title, or an entire cell within the table must be selected.
  • The list of selected graphics in a document is an unordered list. This means that there is no telling which of a list of selected graphics might be returned by FirstSelectedGraphicInDoc . It might be the one the user selected first but do not count on that fact.
//returns a string indicating the type of object currently selected
function GetSelectedObjectType(doc) {
    var tRange, obj;
    tRange = doc.TextSelection;
    obj = tRange.beg.obj;
    if (obj.ObjectValid()) {
        return "Text Selection";
    }
    obj = doc.SelectedTbl;
    if (obj.ObjectValid()) {
        return "Selected Table";
    }
    obj = doc.FirstSelectedGraphicInDoc;
    if (obj.ObjectValid()) {
        return "Selected Graphic";
    }
    return "No selection";
}

var doc = app.ActiveDoc;
Alert(GetSelectedObjectType(doc), Constants.FF_ALERT_CONTINUE_NOTE);



No comments:

Post a Comment