I'm in the market for another script, either to create a new anchored object above every occurrence of a particular paragraph style, or, even better, to use the string in that paragraph style -- fig123 for example -- to load fig123.png into the anchored object.
I found a script that creates anchored objects, by Thomas Silkjær, whose site is no longer on line, but it seems not to be CS6 compatible -- see below, perhaps it just needs some minor adjustment...
Or is there some other solution?
AB
/*
Automating anchored object creation
Version: 1.1
Script by Thomas Silkjær
http://indesigning.net/
*/
var the_document = app.documents.item(0);
// Create a list of paragraph styles
var list_of_paragraph_styles = the_document.paragraphStyles.everyItem().name;
// Create a list of character styles
var list_of_character_styles = the_document.characterStyles.everyItem().name;
// Create a list of object styles
var list_of_object_styles = the_document.objectStyles.everyItem().name;
// Make dialog box for selecting the styles
var the_dialog = app.dialogs.add({name:"Create anchored text frames"});
with(the_dialog.dialogColumns.add()){
with(dialogRows.add()){
staticTexts.add({staticLabel:"Make the anchored frames from ..."});
}
with(dialogRows.add()){
staticTexts.add({staticLabel:"This character style:"});
var find_cstyle = dropdowns.add({stringList:list_of_character_styles, selectedIndex:0});
}
with(dialogRows.add()){
staticTexts.add({staticLabel:"Or this paragraph style:"});
var find_pstyle = dropdowns.add({stringList:list_of_paragraph_styles, selectedIndex:0});
}
with(dialogRows.add()){
staticTexts.add({staticLabel:"Leave one dropdown unchanged!"});
}
dialogRows.add();
with(dialogRows.add()){
staticTexts.add({staticLabel:"Delete matches?"});
var delete_refs = dropdowns.add({stringList:["Yes","No"], selectedIndex:0});
}
dialogRows.add();
with(dialogRows.add()){
staticTexts.add({staticLabel:"Anchored text frame settings:"});
}
with(dialogRows.add()){
staticTexts.add({staticLabel:"Object style:"});
var anchor_style = dropdowns.add({stringList:list_of_object_styles, selectedIndex:0});
}
with(dialogRows.add()){
staticTexts.add({staticLabel:"Frame width:"});
var anchor_width = measurementEditboxes.add({editUnits:MeasurementUnits.MILLIMETERS, editValue:72});
}
with(dialogRows.add()){
staticTexts.add({staticLabel:"Frame height:"});
var anchor_height = measurementEditboxes.add({editUnits:MeasurementUnits.MILLIMETERS, editValue:72});
}
}
the_dialog.show();
// Define the selected styles
var real_find_cstyle = the_document.characterStyles.item(find_cstyle.selectedIndex);
var real_find_pstyle = the_document.paragraphStyles.item(find_pstyle.selectedIndex);
var real_anchor_style = the_document.objectStyles.item(anchor_style.selectedIndex);
// Check if a style is selected
if(find_cstyle.selectedIndex != 0 || find_pstyle.selectedIndex != 0) {
// Define whether to search for character styles or paragraph styles
app.findChangeGrepOptions.includeFootnotes = false;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;
if(find_cstyle.selectedIndex != 0) {
app.findGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.appliedCharacterStyle = real_find_cstyle;
} else {
app.findGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.appliedParagraphStyle = real_find_pstyle;
app.findGrepPreferences.findWhat = "^";
}
// Search the document
var found_items = the_document.findGrep();
myCounter = found_items.length-1;
do {
// Select and copy the found text
var current_item = found_items[myCounter];
if(find_pstyle.selectedIndex != 0) {
var found_text = current_item.paragraphs.firstItem();
var insertion_character = (found_text.characters.lastItem().index) + 1;
var check_insertion_character = insertion_character + 1;
var alt_insertion_character = (found_text.characters.firstItem().index) - 1;
var the_story = found_text.parentStory;
app.selection = found_text;
if(delete_refs.selectedIndex == 0) {
app.cut();
} else {
app.copy();
}
} else {
var found_text = current_item;
var insertion_character = (found_text.characters.lastItem().index) + 2;
var check_insertion_character = insertion_character;
var alt_insertion_character = (found_text.characters.firstItem().index) - 1;
var the_story = found_text.parentStory;
app.selection = found_text;
if(delete_refs.selectedIndex == 0) {
app.cut();
} else {
app.copy();
}
}
// Make text frame from selection
try {
app.selection = the_story.insertionPoints[check_insertion_character];
app.selection = the_story.insertionPoints[insertion_character];
} catch(err) {
app.selection = the_story.insertionPoints[alt_insertion_character];
}
var the_anchored_frame = app.selection[0].textFrames.add({geometricBounds:["0","0",anchor_height.editContents,anchor_width.editContents],anchoredObjectSettings:{anchoredPosition: AnchorPosition.ANCHORED}});
app.selection = the_anchored_frame.insertionPoints[0];
app.paste();
// Apply the object style now to "force apply" paragraph style set in the object style
if(anchor_style.selectedIndex != 0) {
the_anchored_frame.appliedObjectStyle = real_anchor_style;
}
myCounter--;
} while (myCounter >= 0);
} else {
alert("No styles selected!");
}