Quantcast
Channel: Adobe Community : Popular Discussions - Adobe FrameMaker
Viewing all articles
Browse latest Browse all 23442

Use of ElementDef.WrapElement() to create a specific parent element

$
0
0

I have a "lettuce" element that is not wrapped by a "bread" element.  The task is given the selected "lettuce" element to wrap it in a "bread" element.

 

Documentation has that the ElementDef.WrapElement() returns void.  When I wrap the "lettuce" element, the resulting parent element is also "lettuce".  The "lettuce" element is now wrapped by a "lettuce" element.

 

Thoughts on how to impose a "bread" element that wraps around the "lettuce" element?

 

var doc = app.ActiveDoc;

var elementRange = doc.ElementSelection;

var elementLoc = elementRange.beg;

var parentElement = elementLoc.parent;  // not "bread" element

var childElement = elementLoc.child;  // "lettuce" element

PreChecksAndProceed(parentElement, childElement);

 

function PreChecksAndProceed(parentElement, childElement) {
    var elemDef, name;
   
    if (!childElement.ObjectValid())
    {
        alert ("AciveDoc has no ElementSelection");
        return;
    }

    elemDef = childElement.ElementDef;
    if (!elemDef.ObjectValid())
    {
        alert ("Selected element's (elemDef.ObjectValid() == false)");
        return;
    }
   
    name = elemDef.Name;
    if (name != "Lettuce")
    {
        alert ("Selected element is not Lettuce.");
        return;
    }

    if (!parentElement.ObjectValid())
    {
        alert ("Selected element's (parentElement.ObjectValid() == false)");
        return;
    }

    elemDef = parentElement.ElementDef;
    if (!elemDef.ObjectValid())
    {
        alert ("Parent element's (elemDef.ObjectValid() == false)");
        return;
    }
   
    name = elemDef.Name;
    if (name == "Bread")
    {
        alert ("Selected Lettuce element is already wrapped by a Bread element.");
        return;
    }

 

    Wrap_Element(childElement);
    return;
};

function Wrap_Element(elementToWrap) {
    var elemDef = childElement.ElementDef;
    if (!elemDef.ObjectValid())
    {
        alert ("Selected element's (elemDef.ObjectValid() == false)");
        return;
    }
   
    elemDef.WrapElement();


    // todo the selected element is "Lettuce" that wraps the initial "Lettuce" element.
    return;
};


Viewing all articles
Browse latest Browse all 23442

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>