General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion How to loop through current selection

  • NandoC

    How to loop through current selection

    Participants 1
    Replies 2
    Last Activity 8 years ago

    Hi I just started doing some work with Xmetal 7.0 and I am wondering how i can loop through the current selection and insert an element to each of the nodes that have been selected.

    example:
    fordtoyota has been highlighted

    And let's say we want to underline what was selected to

    fordtoyota

    Thanks

    Reply

    Derek Read

    Reply to: How to loop through current selection

    Here's one possibility among many.

    //XMetaL Script Language JScript:
    var rng = ActiveDocument.Range;
    var targetElem = “car”;
    var insertElem = “u”;
    while(rng.MoveToElement(targetElem)) {
    rng.SelectContainerContents();
    rng.Surround(insertElem);
    }

    Depending on your actual needs, the full content of your documents, and the starting position for the Selection, that code may either be a good or bad way to solve your issue. Without knowing the full details I cannot say. I suspect that you will find it needs to at least be extended to cover cases that you have not anticipated.

    Reply

    NandoC

    Reply to: How to loop through current selection

    Thanks Derek, that worked.

    Reply

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

Lost Your Password?

Products
Downloads
Support