An interesting challenge — a mix of Proper User Interface, Ease of Use, Adjustability, and a side dish of How Does This Xml Stuff Actually Works.
Try this script. You must fill in the tag name of your figures in the first variable, and fill the list ‘labels’ with the attribute names you want to add/change.
The forum converts straight single and double quotes to curly ones, and you’ll have to change them back to straight before it can work. If you use the ESTK Editor to edit your scripts, you will see properly quoted text strings marked with a color, that might help.
— 8< —- script follows below
// xmlElementName contains your base XML tag
xmlElementName = “Figure”;
// attribute labels; add at will
var labels = [
“href”,
“width”,
“height”,
“label3”,
“etcetera”
];
var values = new Array(labels.length);
if (app.documents.length == 0)
alert (“uh you didn’t open any document”);
else if (!app.activeDocument.xmlTags.item(xmlElementName).isValid)
alert (‘oh there seems to be no tag named “‘+xmlElementName+'”‘);
else if (app.selection.length == 0)
alert (“ah you forgot to select anything”);
else if (app.selection.length > 1)
alert (“please one at a time only!”);
else if (app.selection[0].associatedXMLElement == null)
alert (“yeah this object has no tag to begin with”);
else if (app.selection[0].associatedXMLElement.markupTag.name != xmlElementName)
alert (‘this object is tagged but with “‘+app.selection[0].associatedXMLElement.markupTag.name+'”, not with “‘+xmlElementName+'”‘);
else
{
var obj = app.selection[0];
var w = new Window(“dialog”, “Result”);
for (i=0; i<labels.length; i++)
{
with (w.add(“group”))
{
add (“statictext”, undefined, labels[i]);
values[i] = add (“edittext”, undefined, “”); values[i].characters = 30;
prevVal = obj.associatedXMLElement.xmlAttributes.item(labels[i]);
if (prevVal.isValid)
values[i].text = obj.associatedXMLElement.xmlAttributes.item(labels[i]).value;
}
}
with (w.add(“group”))
{
orientation = “row”;
add (“button”, undefined, “OK”);
add (“button”, undefined, “Cancel”);
}
if (w.show()==1)
{
for (i=0; i<labels.length; i++)
{
prevVal = obj.associatedXMLElement.xmlAttributes.item(labels[i]);
if (prevVal.isValid)
obj.associatedXMLElement.xmlAttributes.item(labels[i]).value = values[i].text;
else
obj.associatedXMLElement.xmlAttributes.add(labels[i], values[i].text);
}
}
}