Sunday, September 09, 2007


Placing Snippets Inline/Anchored

I've found InDesign's snippets feature to be a constant source of frustration because you simply can't place them as inline or anchored objects. So much of my work involves inline/anchored objects that this makes snippets just about useless. But the alternative of using library items isn't that great either. Library panels take up space on screen and they clutter up the the Open Recent menu. Also, in the past, they've been a source of frustration when crashes occur and they have to be recovered. Untitled assets seem to pop into existence in a recovered library, or worse yet, a previously named asset suddenly loses its name.

Snippets do not take up space on screen, are impervious to crash/recovery issues, and they do not appear on the Open Recent menu. So, how to work around the inability to place them inline? Whats more, how to do it without using the clipboard which might or might not have important information on it at any point in time.

I came up with the idea of using a temporary library. Even on a G4, creating a library, putting something into it, pulling it back out again and deleting the library is pretty swift, while on a MacIntel it positively flies. So, I wrote this function to do the work:
function placeSnipInline( mySnipFile, text ) {
var myDoc = app.documents.add(false);
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
myLib = app.libraries.add(File("~/Desktop/templib.indl"));[0]);
One odd thing here might leap out at you. Why did I not take advantage of the returned object from the place() call to get a reference to the placed object rather than rely on myDoc.pageItems[0] in the store call? The reason is that I have just this morning discovered that if you place a snippet that consists of just a text frame, what's returned by place() is the story, not the text frame.

To turn the above function into a complete script I added this front-end:
//DESCRIPTION: Place Snippet Inline/Anchored

if (app.documents.length > 0 &&
app.selection.length > 0 &&
app.selection[0].hasOwnProperty("baseline")) {
} else {
alert("There must be a text selection to run this script");

function placeSnippet(sel) {
if (File.fs == "Windows") {
var Filter = "Snippet files: *.inds";
} else {
var xmlFilter = function(file) {
file = file.resolve();
if (file == null) return false;
if (file instanceof Folder) return true;
return (".")).toLowerCase() == ".inds");
var Filter = xmlFilter
var myFile = File.openDialog("Choose a snippet file", Filter);
if (myFile == null) { return }
placeSnipInline(myFile, app.selection[0]);

Great post! This solves a lot of problems. Quick question, I'm trying to make this work such that I 'placeAsset' on a labeled TextFrame. I've tried getting the parentStory's text object and it doesn't work. What am I missing?

Sorry to take so long to reply. I had foolishly switched on comment moderation without notification. Aargh!

If you want to place an asset from the library into text, then: you must use placeAsset with text referenced. Here's a quick example:

myAsset = app.libraries[0].assets[3];
myText = app.documents[0].stories[0].insertionPoints[0];

Hello Dave,

speaking of Anchored Objects, have you found any workaround for linking inline text frames with overset text?



There is not easy workaround. The only thing you can do is create new objects, put them where you need them, and then manage the "text flow" by literally moving the overset text from the first anchored frame to the start of the next.

Forcing breaks to occur only at paragraph breaks makes managing this easier. But it's a tough job. I don't have general code that will do it.

Hi Dave,

I am a new Indesign Script Developer from India. Your posts are very useful for me.

Can you help me to get current page number of active document?

Thank you in advance.

With Regards,

This topic has been covered many times in the Adobe U2U forum on InDesign Scripting. Go there are do a search on findPage.

You might even try searching this blog on the same thing, although there have been recent developments so the U2U forum is more current.
I have a datamerge, merging from a CSV. The CSV comes from a google doc form submission. I've then downloaded the .csv file. I've been successful in merging the data. my question is how to format the data after it's merged, or before its placed into its text box.

Basically, I have 15 options for a user to choose. So lets say the google form field options would be (option 1, option 2, option 3, etc.)

What I want to do is import a snippet according to which option they select.

so when the user selects "option 2" the script would compare against option 2 and would pull in Snippet2.idms.

I am wanting this to use javascript.
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?