Monday, January 08, 2007

 

Aggregate Pasteboard

For those of you who provided feedback, many thanks. Here's how far I've gotten after a few minutes of scripting. This version does nothing to deal with the issue of facing pages spreads and the possibility that an item that started on the pasteboard will be moved to a page if the source spread has just one page but the target has two (or more).

However, for single-sided documents, it works like a charm (I think -- if anyone wants to give it a spin, let me know if you find anything wrong.

Note the following functional decisions:

1. Use only with single-sided documents (for now).
2. If the active window is a story editor window, the script does nothing.
3. If a pasteboard item is locked, the script leaves it where it is. This allows the user to lock an item to a particular spread, for whatever reason.
4. If a layer is invisible, any pasteboard item on that layer is nonetheless moved to the new pasteboard.

Ooh, I bet there's a bug if the layer is locked. Well, I'll have to fix that the next time around. Here's the current state of the script:
//DESCRIPTION: Moves all Pasteboard Items to Pasteboard of Current Spread

if (app.documents.length == 0) { exit() }
movePBitems(app.documents[0]);

function movePBitems(myDoc) {
  if (app.activeWindow.constructor.name == "StoryWindow") { return }
  myObjs = myDoc.pageItems.everyItem().parent;
  var moveables = new Array();
  for (var j = myObjs.length - 1; j >= 0; j--) {
    if (myObjs[j].constructor.name == "Page") { continue }
    moveables.push(myDoc.pageItems[j].id);
  }
  var mySpread = app.activeWindow.activeSpread;
  for (var j = moveables.length - 1; j >= 0; j--) {
    var myObj = myDoc.pageItems.itemByID(moveables[j]);
    if (myObj.parent == mySpread) { continue }
    var myBounds = myObj.geometricBounds;
    if (myObj.locked) { continue }
    myObj.move(mySpread);
    myObj.move([myBounds[1], myBounds[0]]);
  }
} // end function movePBitems
Enjoy,

Dave

Comments:
Hi Dave,

basing on your interesting script I have followed another approach: storing every pasteboard item into a temporary library. The pasteboard items will keep left where they are.

Please pay attention:
The temorary library is saved in "TempLibrary.indl" in the user's documents folder. Every time the script is executed, the library is cleared (means: the old assets/contents of the library are removed).

[code]
// storePasteboardItems2TempLibrary.jsx

//DESCRIPTION: Stores all Pasteboard Items into a temporary library
// Pay attention: the temorary library is saved in "TempLibrary.indl" in the user's documents folder.
// Every time the script is executed, the library is cleared (means: the old assets (contents) of the library are removed)

if (app.documents.length > 0) {
var myLib = getLib("~/Documents", "TempLibrary.indl");
clearLib(myLib);
store2Lib(app.documents[0], myLib);
}

// remove every asset of the library
function clearLib(theLib) {
if (theLib.assets.length > 0)
theLib.assets.everyItem().remove();
}

// stores pasteboard items to the library
function store2Lib(myDoc) {
if (app.activeWindow.constructor.name != "StoryWindow") {
myObjs = myDoc.pageItems.everyItem().parent;
for (var j = myObjs.length - 1; j >= 0; j--) {
if (myObjs[j].constructor.name != "Page")
myLib.store(myDoc.pageItems[j]);
}
}
}

function getLib(myPathName, myLibName) {
try {
// add (and reset existing library) if it's not open
var myLib = app.libraries.add(File(myPathName + "/" + myLibName));
}
catch (e) {
// get opened library
var myLib = app.libraries.item(myLibName);
}
return myLib;
}
[/code]Martin
 
Interesting. Doesn't that leave you with a lot of unnamed assets in the library? I'm not sure I like the idea of working with unnamed library assets.

Dave
 
> Doesn't that leave you with a lot
> of unnamed assets in the library?

You are right.

That's a problem of assets with text frames, empty rectangles and groups.
But that's no problem (isn't it?) of assets with rectangles with linked images in it (the assets get the name of the linked images).

Martin
 
Post a Comment

<< Home

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