Skip to main content
payalm68947498
Inspiring
January 15, 2019
Answered

Create New Parent Element of tag

  • January 15, 2019
  • 1 reply
  • 965 views

Hi...

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

Thank you.......

This topic has been closed for replies.
Correct answer Sunil Yadav

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);

1 reply

Sunil Yadav
Sunil YadavCorrect answer
Legend
January 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);

payalm68947498
Inspiring
January 15, 2019

What is node?

Sunil Yadav
Legend
January 15, 2019

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

Try it now.