General XMetaL Discussion

  • C4

    strElementName

    Participants 2
    Replies 3
    Last Activity 5 years, 2 months ago

    Hi,

    We are using XMetal Author Essential 11.

    I'm trying to write a macro to find an element using:

    // XMetaL Script Language JSCRIPT:
    var rng=ActiveDocument.Range;
    rng.MoveToElement(“P”,false);
    // make the range visible
    rng.Select();

    Is there any way to move to the end of the element rather than the beginning of the element?

    Thanks.

    Reply

    tonys

    Reply to: strElementName

    To move the cursor before the end tag:

    rng.MoveToElement(“P”);
    rng.SelectContainerContents();
    rng.Collapse(0);

    To move after the end tag:

    rng.MoveToElement(“P”);
    rng.SelectAfterContainer();

    Reply

    C4

    Reply to: strElementName

    Thanks

    I tried both of those and it took me to the beginning of the element.

    I've changed my code to this and it seems to work.

    var rng=ActiveDocument.Range;
    rng.MoveToElement(“P”,true);
    rng.Select();
    Selection.SelectAfterNode(Selection.ContainerNode);

    Reply

    tonys

    Reply to: strElementName

    Maybe because you didn't call rng.Select()?

    For efficiency, you should do everything with the Range object, then call the Select() method at the end.

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support