• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

does ESTK doc.UnWrapElement() really work?

Community Beginner ,
Apr 25, 2020 Apr 25, 2020

Copy link to clipboard

Copied

I'm using FM 2017 with ESTK 4.5.5.

I've been having issues trying to unwrap an element via scripting. I can do it manually using the Element->Unrwap menu which tells me the structured document is OK. 

Here's the code

 

 

#target framemaker

var flow, root;
doc = app.ActiveDoc;
 
flow = doc.MainFlowInDoc;
root = flow.HighestLevelElement;

var eRange = new ElementRange;
var th1st = root.FirstChildElement;// thead
var th2nd = th1st.NextSiblingElement; // next thead
var charFmt2 = th2nd.FirstChildElement;
        
eRange.beg.parent = charFmt2;
eRange.beg.child = charFmt2.FirstChildElement;
eRange.beg.offset = 0;
eRange.end.parent = charFmt2.FirstChildElement;
eRange.end.child = charFmt2.NextSiblingElement;
eRange.end.offset = 0;
doc.ElementSelection = eRange;  
doc.UnWrapElement();

 

 

As the snapshot shows, the code above successfully selects the element I want to unwrap, but doc.UnWrapElement() does not have any effect when it's called.

 

 

unrwap_snapshot.PNG

Any thoughts on what might be going wrong here?

Thanks.

TOPICS
Scripting , Structured

Views

824

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Apr 28, 2020 Apr 28, 2020

Hi,

 

It should work. Without studying your script too closely (and it is hard to follow your variable name conventions 🙂  I do not see any obvious problem. And, if it is selecting the element correctly, it should work. One thing does stand out from the screenshot... it really looks like you are trying to unwrap a table element, which is not permitted. The UI should reject that action too.

 

Here is the function I use to unwrap elements, maybe it will help some if the table element is not the issue

...

Votes

Translate

Translate
Mentor ,
Apr 28, 2020 Apr 28, 2020

Copy link to clipboard

Copied

Hi,

 

It should work. Without studying your script too closely (and it is hard to follow your variable name conventions 🙂  I do not see any obvious problem. And, if it is selecting the element correctly, it should work. One thing does stand out from the screenshot... it really looks like you are trying to unwrap a table element, which is not permitted. The UI should reject that action too.

 

Here is the function I use to unwrap elements, maybe it will help some if the table element is not the issue:

 

function UnwrapElement(doc, elem)
{
    if(elem == null || !doc.ObjectValid() || !elem.ObjectValid()) return;
    
    var er = new ElementRange;
                
    er.beg.parent = er.end.parent = elem.ParentElement; 
    er.beg.child = elem;
    er.end.child = elem.NextSiblingElement;
    er.beg.offset = er.end.offset = 0;
    
    doc.ElementSelection = er;
    
    doc.UnWrapElement();
};

 

Russ

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 28, 2020 Apr 28, 2020

Copy link to clipboard

Copied

LATEST

Hi Russ,

 

Yes, my range was picking up the BODY  element. My original code (not posted here) had that bug.

Thanks. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines