Copy link to clipboard
Copied
Hi Everyone,
I want to change tag name after creating tag through scripting.
Thank you.....
1 Correct answer
Ahh, my bad i did not look into it deeply. Well your case would fail if the selection is a textframe as mine would if the selection is a text. So a more appropriate code that handles both the cases would be
...var newItem = app.activeDocument.xmlTags.itemByName("Name")
if(newItem.isValid)
{
var a;
try{
a = app.selection[0].associatedXMLElements[0]
}catch(e){}
try{
if(!a)
a = app.selection[0].associatedXMLElement
}catch(e){}
if(a)
a.mar
Copy link to clipboard
Copied
You could use the following
var newItem = app.activeDocument.xmlTags.itemByName("boxed-text")
if(newItem.isValid)
app.selection[0].associatedXMLElement.markupTag = newItem
Add in the required error checks like the selection is valid or not and so forth.
-Manan
Copy link to clipboard
Copied
Thank you....
It works when app.selection[0].associatedXMLElement.markupTag = newItem change to
app.selection[0].associatedXMLElements[0].markupTag = newItem,
only difference is associatedXMLElements[0].
Copy link to clipboard
Copied
Ahh, my bad i did not look into it deeply. Well your case would fail if the selection is a textframe as mine would if the selection is a text. So a more appropriate code that handles both the cases would be
var newItem = app.activeDocument.xmlTags.itemByName("Name")
if(newItem.isValid)
{
var a;
try{
a = app.selection[0].associatedXMLElements[0]
}catch(e){}
try{
if(!a)
a = app.selection[0].associatedXMLElement
}catch(e){}
if(a)
a.markupTag = newItem
}
The idea is simply to use try catch block to see if the property exists or not, this should also cater to selection not being tagged as well.
-Manan
Copy link to clipboard
Copied
After thought a more clean solution would be to use hasOwnProperty method
var newItem = app.activeDocument.xmlTags.itemByName("Name")
if(newItem.isValid)
{
var a;
if(app.selection[0].hasOwnProperty('associatedXMLElements'))
a = app.selection[0].associatedXMLElements[0]
else if(app.selection[0].hasOwnProperty('associatedXMLElement'))
a = app.selection[0].associatedXMLElement
if(a)
a.markupTag = newItem
}
-Manan
Copy link to clipboard
Copied
my app.selection is text because i am selecting that text before replacing tag name, thats why app.selection[0].associatedXMLElements[0] it works.
Thank you for helping......

