Wednesday, January 11, 2012

Rearranging the Tree of Elements

You can use the Cut, Copy, Paste methods to move selected elements around in the tree. There are, however, some special cases where you can take advantage of built-in tree manipulation functions.
  • Use the document method PromoteElement() to make the selected element the sibling of its former parent.
  • Use the document method DemoteElement() to make the selected element the child of its preceding sibling.

The following simple script promotes the selected element. You could easily modify it to demote an element.

var doc;

doc = app.ActiveDoc;
doc.PromoteElement();
if (FA_errno !== 0) {
    Alert(FA_errno + '');
}

The script checks for an error code:
  • Constants.FE_WrongProduct (-60) signifies that the product interface is not set to Structured FrameMaker .
  • Constants.FE_BadDocId (-2) indicates a problem with the document identifier.
  • Constants.FE_BadSelectionForOperation (-59) indicates that the action requested could not be taken on the selected element. For example, you cannot promote the root element or its children.

Here is the before and after that results from promoting the p element.
Before element promotion
After element promotion
This promote operation happens to make the structure tree invalid but the operation itself is sound.

Attempting to promote the root element produces the following error code message Constants.FE_BadSelectionForOperation (-59) as displayed by the script.


No comments:

Post a Comment