2009-11-12

Delete Empty Assignments

Part of a Document Cleanup Routine

I've been working with Adobe InCopy Assignments again.
When users delete frames that used to have assigned stories, the assignment remains with the Adobe InDesign document. If the assignment manages to get updated (it can happen easily) then the assignment file will contain no Adobe InCopy stories. What will happen if the user opens the Adobe InCopy story is they will get an ugly message when opening the story and they will see the page where the assigned stories used to be, but they can't edit it.
To put things back, the story needs to get reassigned and re-saved.
But if the original Adobe InDesign document still has the assignment is saved _last_ then the user sees the original page.
This function does nothing other than delete the empty assignments. To fix all ills, you could also delete the assignment file from the file server -- but the better solution is to save the page where the assignment currently exists.


//
function deleteEmptyAssignments ( docRef ) {
//-------------------------------------------------------------------------
//-- D E L E T E E M P T Y A S S I G N M E N T S
//-------------------------------------------------------------------------
//-- Generic: Yes
//-------------------------------------------------------------------------
//-- Purpose: To delete all assignments with no assignedStories
//-------------------------------------------------------------------------
//-- Arguments: docRef: a reference to the document to be processed
//-------------------------------------------------------------------------
//-- Calls: Nothing.
//-------------------------------------------------------------------------
//-- Returns: Boolean true if successful. Boolean false if an error occured
//-------------------------------------------------------------------------
//-- Sample Use: deleteEmptyAssignments ( app.documents[0] )
//-------------------------------------------------------------------------
//-- Notes: Part of a larger function.
//-------------------------------------------------------------------------
//-- Written: 2009.11.12 by Jon S. Winters of electronic publishing support
//-- at the Hilton Universal City, Los Angeles, CA
//-- eps@electronicpublishingsupport.com
//-------------------------------------------------------------------------

try {
//-- Loop through every assignment.
var allAssignments = docRef.assignments ;
for ( var aai = allAssignments.length - 1 ; aai >= 0 ; aai-- ) {
//-- if the assignment isn't the special 'Unassigned' assignmetn and if
//-- the assignment has no assigned stories, then remove it.
if ( ( allAssignments[aai].assignedStories.length == 0 ) && ( allAssignments[aai].name != 'Unassigned InCopy Content' ) ) {
allAssignments[aai].remove() ;
}
}
return true ;
}
catch ( failSilently ) {
var errorObject = failSilently ;
return false ;
}
}

No comments:

Post a Comment