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

Create New Parent Element of tag

Contributor ,
Jan 14, 2019 Jan 14, 2019

Copy link to clipboard

Copied

Hi...

     I want to create new parent element of tag through scripting just like we do manully in indesign.

new.png

Thank you.......

TOPICS
Scripting

Views

590

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

Advocate , Jan 15, 2019 Jan 15, 2019

Hello payalm,

Try this below code for your reference,

var myDoc = app.documents[0]

var myCurrentNode = app.selection[0];

var parentNode = myCurrentNode.parent.xmlElements.add('TestNode');

parentNode = parentNode.move(LocationOptions.BEFORE,myCurrentNode);

myDoc.recompose();

myCurrentNode = myCurrentNode.move(LocationOptions.AT_BEGINNING,parentNode);

Votes

Translate

Translate
Advocate ,
Jan 15, 2019 Jan 15, 2019

Copy link to clipboard

Copied

Hello payalm,

Try this below code for your reference,

var myDoc = app.documents[0]

var myCurrentNode = app.selection[0];

var parentNode = myCurrentNode.parent.xmlElements.add('TestNode');

parentNode = parentNode.move(LocationOptions.BEFORE,myCurrentNode);

myDoc.recompose();

myCurrentNode = myCurrentNode.move(LocationOptions.AT_BEGINNING,parentNode);

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
Contributor ,
Jan 15, 2019 Jan 15, 2019

Copy link to clipboard

Copied

What is node?

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
Advocate ,
Jan 15, 2019 Jan 15, 2019

Copy link to clipboard

Copied

I already found that exception and edited that answer as well.

Try it now.

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
Explorer ,
Nov 01, 2023 Nov 01, 2023

Copy link to clipboard

Copied

LATEST

This way, we will lose some style formatting. The better way is to use "Side Menu \ New Parent Element". But how to trigger this side menu option through scripting? Any idea?

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