While some think of copying and pasting text, I prefer to write formatted text to an Adobe InDesign Tagged Text file and then read the file back at the desired location. I won't go into the reasonings behind this, but despite what you might think, it is very fast to do.
Below is a generic function to place a tagged text file at a location (such as a selection).
//
function placeTaggedText ( location , fileRef ) {
//-------------------------------------------------------------------------
//-- P L A C E T A G G E D T E X T
//-------------------------------------------------------------------------
//-- Generic: Yes. For both InCopy and Adobe InDesign.
//-- Tested with CS3, but should work with CS2 and newer
//-------------------------------------------------------------------------
//-- Purpose: To import the passed Tagged Text at the passed location.
//-------------------------------------------------------------------------
//-- Parameters: 2
//-- location: The location to place the file. Can accept anything
//-- that InDesign and InCopy will accept for the place function
//-- and it works in the same fashion as place.
//-- fileRef: A file object to the tagged text file to import.
//-------------------------------------------------------------------------
//-- Calls: Nothing.
//-------------------------------------------------------------------------
//-- Returns: true if the function was successful, or false if it was not.
//-------------------------------------------------------------------------
//-- Sample Use: Too many options to document.
//-------------------------------------------------------------------------
//-- Notes: In reality, this function will place ANY file. It doesn't
//-- test for tagged text files. But it does hard code some Tagged
//-- text import preferences.
//-------------------------------------------------------------------------
//-- Written: 2009.07.28 by Jon S. Winters of electronic publishing support
//-- eps@electronicpublishingsupport.com
//-------------------------------------------------------------------------
//-- Revised: 2009.09.13 for version 2.60 in New Orleans, LA to allow
//-- the placement to happen even if there is a dialog displayed.
//-- The problem was that the tagged text file can have missing fonts,
//-- and that really stops the script and throws a javascript error.
//-- Wrap the function in a try. The parameters can be setup incorrectly
//-- which will cause problems
try {
//-- Setup the Import Preferences for Tagged Text files
app.taggedTextImportPreferences.removeTextFormatting = false ;
app.taggedTextImportPreferences.styleConflict = StyleConflict.PUBLICATION_DEFINITION ;
//~ app.taggedTextImportPreferences.styleConflict = StyleConflict.TAG_FILE_DEFINITION ;
app.taggedTextImportPreferences.useTypographersQuotes = false ;
//-- Version 2.60 2009.09.13 prevent any user interaction.
var oaspuil = app.scriptPreferences.userInteractionLevel ;
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT ;
//-- Now place the file -- simple. As a Text File that is marked as a
//-- tagged text file, it will just work.
var placeResults = location.place ( fileRef, false )
//-- Version 2.6 2009.09.13 return the user interaction levels
app.scriptPreferences.userInteractionLevel = oaspuil ;
//-- Check that the file was imported. This won't work when the wrong
//-- location is sent.
if ( placeResults == undefined ) { return false ; }
//-- implied else
return true ;
}
catch (err) {
return false ;
}
}
//
Hey Jon,
ReplyDeletethanks for sharing. You saved me a lot of trouble.