Anchored objects script

1,995 views
Skip to first unread message

Andrew Brown

unread,
Mar 11, 2013, 8:06:57 AM3/11/13
to indesi...@googlegroups.com
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!");
}

Boris Kas

unread,
Mar 11, 2013, 9:10:09 AM3/11/13
to indesi...@googlegroups.com
I modified this script. It works in CS5, CS5.5, but CS6 doesn't work (http://adobeindesign.ru/2012/04/11/avtomaticheskoe-sozdanie-privyazannyx-frejmov/). Soon I will force it to ID CS6. Tell me your wishes, pls


2013/3/11 Andrew Brown <li...@c18.net>

--
You received this message because you are subscribed to the Google Groups "InDesign talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to indesign-tal...@googlegroups.com.
To post to this group, send email to indesi...@googlegroups.com.
Visit this group at http://groups.google.com/group/indesign-talk?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.





--
Всего доброго, Борис

Andrew Brown

unread,
Mar 11, 2013, 10:17:46 AM3/11/13
to indesi...@googlegroups.com
On 11 mars 2013, at 14:10, Boris Kas <boriska...@gmail.com> wrote:

I modified this script. It works in CS5, CS5.5, but CS6 doesn't work (http://adobeindesign.ru/2012/04/11/avtomaticheskoe-sozdanie-privyazannyx-frejmov/). Soon I will force it to ID CS6. Tell me your wishes, pls

Well, I just want it to work like the original -- but time is not on my side, I'll have to do this job manually, I fear -- 250 images to place!

A.

Boris Kas

unread,
Mar 11, 2013, 10:31:24 AM3/11/13
to indesi...@googlegroups.com
It is an old trick. Try to place at the beginning of a old script a line app.scriptPreferences.version = 5;

2013/3/11 Andrew Brown <li...@c18.net>

--
You received this message because you are subscribed to the Google Groups "InDesign talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to indesign-tal...@googlegroups.com.
To post to this group, send email to indesi...@googlegroups.com.
Visit this group at http://groups.google.com/group/indesign-talk?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Andrew Brown

unread,
Mar 11, 2013, 11:41:36 AM3/11/13
to indesi...@googlegroups.com
On 11 mars 2013, at 15:31, Boris Kas <boriska...@gmail.com> wrote:

It is an old trick. Try to place at the beginning of a old script a line app.scriptPreferences.version = 5;

No, that does not help, and 6 instead of 5 is no better -- ID objects to that line itself.

Am I right in thinking that the delete frames script does not delete empty text frames?

A.

Kathleen

unread,
Mar 11, 2013, 10:36:01 PM3/11/13
to indesi...@googlegroups.com
Boris, Andrew,

I've seen a way to copy/paste AOs into the beginning of a paragraph with a specific style. You have to set to position before then copy then do a find change paste.

Is this script anything like that? If not or even if so could you explain what this script does. Sounds like it is worth downloading.
Kat
McGraphics Design, Inc.
(626) 799-2195
http://www.mcgraphics.us


Andrew Brown

unread,
Mar 12, 2013, 1:40:21 AM3/12/13
to indesi...@googlegroups.com
That works fine, Kat, thanks! a real time saver.

The only problem is ID's habit of starting searches again from the beginning whenever it gets the chance to do so, it's a horrible habit but it has been with us so long that I guess it's here to stay, part of the fundamental architecture of the thing.

The script probably does something similar, after displaying the various options and allowing the user to select them.

A.

Boris Kas

unread,
Mar 12, 2013, 1:47:33 AM3/12/13
to indesi...@googlegroups.com
Kathleen, I had a script (for CS4 ) where future anchor objects consisted in tags (<...>):
text text text
text text text
<myPict1.jpg>
text text text
text text text
<myPict1.jpg>
text text text
text text text
While the script doesn't work in CS6

2013/3/12 Kathleen <kat...@mindspring.com>
--
You received this message because you are subscribed to the Google Groups "InDesign talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to indesign-tal...@googlegroups.com.
To post to this group, send email to indesi...@googlegroups.com.
Visit this group at http://groups.google.com/group/indesign-talk?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Boris Kas

unread,
Mar 12, 2013, 1:49:47 AM3/12/13
to indesi...@googlegroups.com
I hurried...... sorry
text text text
text text text
<myPict1.jpg>
text text text
text text text
<myPict2.jpg>
text text text
text text text


2013/3/12 Boris Kas <boriska...@gmail.com>

Kathleen

unread,
Mar 12, 2013, 1:50:58 PM3/12/13
to indesi...@googlegroups.com
Anyway to replace the existing AO but leave it's baseline shift?I have a lot of AOs tagged as <Artifact> that may need to be tagged <Figure> and alt text <Handicapped symbol>.

I had planned to do a find/change and replace the anchored object .tif <Artifact> with a <Figure> AO. The problem is that the current AO has different baseline shifts within paragraphs. Last time I tried this replace, the new AO's baseline shift was pasted in and I had to go thru and individually redo baseline shift on each.
Reply all
Reply to author
Forward
0 new messages