Home › Forums › General XMetaL Discussion › Makro Search Entity and Replace it › Reply To: Makro Search Entity and Replace it
Reply to: Makro Search Entity and Replace it
December 20, 2013 at 12:43 amThere is no API dedicated to this type of thing, but I think you can probably do what you want with a combination of other APIs.
With the following document open in XMetaL Author (Enterprise or Essential)…
[code=Journalist demo document]
]>
[/code]
…running the following script will replace all the “old” entity references with references to the “new” entity.
[code=sample script]//XMetaL Script Language JScript:
if((ActiveDocument.ViewType == sqViewNormal)||(ActiveDocument.ViewType == sqViewTagsOn)) {
var entRefToReplace = “old”;
var entRefToInsert = “new”; //this entity ref must be declared
var rng1 = ActiveDocument.Range;
rng1.MoveToDocumentStart();
var rng2 = rng1.Duplicate;
rng1.GotoNext(0);
while(rng2.IsLessThan(rng1)) {
if(rng2.ContainerName == “.ENTREF”) {
if(rng2.ContainerNode.nodeName == entRefToReplace) {
Application.Alert(“found one: ” + rng2.ContainerNode.nodeName);
rng2.SelectElement();
rng2.Delete();
rng2.InsertEntity(entRefToInsert);
}
}
rng2.GotoNext(0);
rng1.GotoNext(0);
}
}[/code]