Hi Peter,
Thanks for your kindful suggestions and for your support. I have tried but it throws me a error. Because i got confused and i am sure that i did some mistake in calling the library items. Please help me for this. I am still learning and want to learn more things from you. Find the script below,
if(app.documents.length>0)
{
// find options to be set
app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = "\\[P-ICON\\]";
var myFound = app.activeDocument.findGrep (true);
var counter = i+1;
var myDoc=app.activeDocument;
var y=app.libraries[0].assets;
var Lb1=["Pair_Icon"];
var Lb2=["Group_Icon"];
var Chi=Lb1;
var x=y.item(Chi).placeAsset(myDoc);
for (var i = 0; i < myFound.length; i++)
{
switch (myFound.contents[1])
{
case "P": myFound.insertionPoints[0].insert.Lb1;//insert P icon
case "G": myFound.insertionPoints[0].insert.Lb2; //insert G icon
}
}
var Obj=myFound.contents[1];
Obj.anchoredObjectSettings.anchoredPosition = AnchorPosition.anchored;
Obj.anchoredObjectSettings.spineRelative=true;
Obj.anchoredObjectSettings.anchorPoint = AnchorPoint.topLeftAnchor;
Obj.anchoredObjectSettings.horizontalReferencePoint=AnchoredRelativeTo.pageMargins;
Obj.anchoredObjectSettings.anchorXoffset=0;
Obj.anchoredObjectSettings.anchorYoffset=0;
Obj.anchoredObjectSettings.verticalReferencePoint=VerticallyRelativeTo.capheight;
counter++;
}
alert(counter+" DONE");
Thanks in advance
Thiyagu
Here is the full script. It assumes that your library is open, that it contains the two named assets, and that you have an object style named "icon". You may also want to set the find options (include footnotes, locked stories, etc.)
The script does this: find all instances of [P-ICON] and [G-ICON] (which is [[PG]-ICON] in GREP). Cycle through the array of found items (findGrep(true) returns the found items in reverse order), inserting an asset at the last insertion point of each found instance. Each found instance (i.e. each myFound.contents) is the name of an asset.
This marginal stuff is good fun. I've just clobbered together a system for dynamic margin notes (http://www.kahrel.plus.com/indesign/sidenotes.html).
Peter
#target indesign
myDoc = app.documents[0];
myObjectStyle = myDoc.objectStyles.item ("icon");
myLib = app.libraries[0];
app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = "\\[[PG]-ICON\\]";
var myFound = myDoc.findGrep (true);
try
{
for (i = 0; i < myFound.length; i++)
{
myIcon = myLib.assets.item (myFound.contents).placeAsset (myFound.insertionPoints[-1])[0];
myIcon.appliedObjectStyle = myObjectStyle;
myFound.remove ();
}
}
catch (e) {alert (e.message)}