Copy link to clipboard
Copied
Hi All,
I'm extremely new to scripting; I managed to create a script to extend the artboard of my documents (which I was extremely proud of given my inexperience!) and another to align a couple of objects alongside each other, but my attempts to script some new code has met with failure.
Firstly, I need some Illustrator CS4 Javascript code that will create a bounding rectangle for the selected object(s). The selected object(s) will always be rectangular; no irregularly-shaped objects. I know this should be simple, but I can't work out the variables/attributes involved.
Secondly, some code to help selecting the leftmost object in a document. And the equivalent for the rightmost object.
If it makes any difference, I'll be stitching these scripts together with an action to achieve the following workflow.
The reason for this is because we have EPS map files exported from AutoCAD that are left- and right-hand pages. These need to be combined into one file, but when they are brought in they lose their masks as the BBOX element is not recognised by Illustrator. The double-masking in my process above is needed to ensure that content from either map doesn't overlap the other half of the map.
Any assistance would be greatly appreciated, and sorry for the long-winded post!
Thanks,
WayneM@LP
Oooops that's my errror ( overlooked you said CS4 ). Artboards were brought in with CS4 but I may have used options that are CS5+ sorry about that I will have to look it up… I don't have CS4 to check in. Yes script can embed the links… This may depend on where your app co-ord is set… Some users move it… The masks end up below the artboard for me now…?
...#target illustrator
joinEPSLinks();
function joinEPSLinks() {
var doc = app.activeDocument;
doc.defaultFilled = doc.defaultStroked
Copy link to clipboard
Copied
Well my first question is are all your CAD *.eps files the same size bounds…? As I would create one doc, place links, mask, save as… Loop the file list placing R&L linked pairs, save as for each…
Not long-winded at all… Scriptable job yes ( if you have lots to do ) Do you always mask by the same amount too… May have more questions…
Copy link to clipboard
Copied
Hi Muppet Mark; thanks for the reply.
To answer your questions:
However, I was doing some research just now, and I've learned that it's impossible to create an action that calls a script, as the action constantly 'forgets' the script. So my plan might be all for naught unless I can work out a way to put together all my steps into a single action. Blerg.
Thanks,
WayneM@LP
Copy link to clipboard
Copied
Placing pairs in a document is easy enough… Getting the size after importing too… Just resize the artboard to content at end…
The only piece of logic you can't make on-the-fly here is ( single EPS or paired EPS's )…
If they were named up in a logical manner then you should be able to do the lot with script alone one click and no actions…
Eg:
autoCAD_01.eps
autoCAD_02_L.eps
autoCAD_02_R.eps
autoCAD_03.eps
and so on…
The masks are always exactly the same dimensions as the LInked Files… Hum what do they mask then or did you just want a group?
Copy link to clipboard
Copied
The pairs always have -lhs and -rhs in their filename, and it's only the pairs that need to have this joining done. All the files have other changes to be made (removing page references, adding titles, and cosmetic changes such as that), but it's only a way to join up the RHS and LHS pairs that I'm looking for here. Batching a solution to join a mass of files at the same time isn't really the issue here, it's just speeding up the joining of particular pairs one pair at a time, and ensuring it's very precisely done with no human error.
When the maps are dropped in as Linked Files, they appear as if the BBOX is still recognised, and the content outside the page area can't be seen. But when they're embedded (or simply opened in Illustrator), the external content can be seen. So I'd like to bring them in as Linked Files, create rectangles to mask them, and then embed at the end once they're masked in a way that Illustrator recognises.
The final mask around the paired EPS files is needed as sometimes the maps will have keys underneath that need to be masked out after the joining is done. I was looking for a way to add it in exactly snapped to the visible bounds of the individually masked maps so that it was ready to mask out the docked keys if needed.
To be honest, the process I have is simple enough in my opinion. Drag in the linked files, run my script to align then, run another script once for each Linked File to add bounding rectangles, then mask them off individually, then use the same script again to add a top-level bounding rectangle and mask the two together before embedding them. It literally takes me less than a minute to do, but my cartographers were complaining about it. They want to just use totally familiar practises like copying & pasting maps together and aligning them by hand, but the copying/pasting slows their PCs down (these are very complex maps), and I don't want to risk them not snapping the halves together exactly as there are other scripts later for eBook conversion that require precise artboard measurements to be preserved. Also, working with the maps as embedded files until the very end keeps the process quicker.
Thus my desire to find some kind of a one-click script that runs the files through the process I've outlined above.
Here's my plain English version of what I think needs to happen.
Copy link to clipboard
Copied
With 2 placed *.eps files… This should give you then general idea… Untidy yes but works?
#target illustrator
joinEPSLinks();
function joinEPSLinks() {
var doc = app.activeDocument;
doc.defaultFilled = doc.defaultStroked = false;
var epsLeft = doc.placedItems[0];
var epsRight = doc.placedItems[1];
epsRight.top = epsLeft.top;
epsRight.left = epsLeft.visibleBounds[2];
doc.artboards[0].artboardRect = doc.visibleBounds;
app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;
var leftMask = doc.pathItems.rectangle( 0, 0, epsLeft.visibleBounds[2], doc.height );
var rightMask = doc.pathItems.rectangle( 0, epsRight.visibleBounds[0], epsRight.visibleBounds[2]-epsRight.visibleBounds[0], doc.height );
var docMask = doc.pathItems.rectangle( 0, 0, doc.width, doc.height );
var grpLeft = doc.groupItems.add();
epsLeft.move( grpLeft, ElementPlacement.PLACEATBEGINNING );
leftMask.move( grpLeft, ElementPlacement.PLACEATBEGINNING );
grpLeft.pathItems[0].clipping = true;
var grpRight = doc.groupItems.add();
epsRight.move( grpRight, ElementPlacement.PLACEATBEGINNING );
rightMask.move( grpRight, ElementPlacement.PLACEATBEGINNING );
grpRight.pathItems[0].clipping = true;
var grpDoc = doc.groupItems.add();
grpLeft.move( grpDoc, ElementPlacement.PLACEATBEGINNING );
grpRight.move( grpDoc, ElementPlacement.PLACEATBEGINNING );
docMask.move( grpDoc, ElementPlacement.PLACEATBEGINNING );
grpDoc.pathItems[0].clipping = true;
};
Copy link to clipboard
Copied
Wow - that's so close I can almost smell it!
However, when I run it, there's a few problems...
Thanks so much for your help so far!
Copy link to clipboard
Copied
Oooops that's my errror ( overlooked you said CS4 ). Artboards were brought in with CS4 but I may have used options that are CS5+ sorry about that I will have to look it up… I don't have CS4 to check in. Yes script can embed the links… This may depend on where your app co-ord is set… Some users move it… The masks end up below the artboard for me now…?
#target illustrator
joinEPSLinks();
function joinEPSLinks() {
var doc = app.activeDocument;
doc.defaultFilled = doc.defaultStroked = false;
var epsLeft = doc.placedItems[0];
var epsRight = doc.placedItems[1];
epsRight.top = epsLeft.top;
epsRight.left = epsLeft.visibleBounds[2];
doc.artboards[0].artboardRect = doc.visibleBounds;
app.redraw();
doc.rulerOrigin = [ 0, 0 ]; // or try doc.rulerOrigin = [ 0, -doc.height ]
var leftMask = doc.pathItems.rectangle( 0, 0, epsLeft.visibleBounds[2], doc.height );
var rightMask = doc.pathItems.rectangle( 0, epsRight.visibleBounds[0], epsRight.visibleBounds[2]-epsRight.visibleBounds[0], doc.height );
var docMask = doc.pathItems.rectangle( 0, 0, doc.width, doc.height );
var grpLeft = doc.groupItems.add();
epsLeft.move( grpLeft, ElementPlacement.PLACEATBEGINNING );
leftMask.move( grpLeft, ElementPlacement.PLACEATBEGINNING );
grpLeft.pathItems[0].clipping = true;
grpLeft.clipped = true;
var grpRight = doc.groupItems.add();
epsRight.move( grpRight, ElementPlacement.PLACEATBEGINNING );
rightMask.move( grpRight, ElementPlacement.PLACEATBEGINNING );
grpRight.pathItems[0].clipping = true;
grpRight.clipped = true;
var grpDoc = doc.groupItems.add();
grpLeft.move( grpDoc, ElementPlacement.PLACEATBEGINNING );
grpRight.move( grpDoc, ElementPlacement.PLACEATBEGINNING );
docMask.move( grpDoc, ElementPlacement.PLACEATBEGINNING );
grpDoc.pathItems[0].clipping = true;
grpDoc.clipped = true;
doc.groupItems[0].groupItems[0].placedItems[0].embed();
doc.groupItems[0].groupItems[1].placedItems[0].embed();
app.redraw();
};
Copy link to clipboard
Copied
Yes! You're a guru.
Worked perfectly when I changed "doc.rulerOrigin = [ 0, 0 ]" to "doc.ruler.Origin = [" 0, doc.height ]" (because Illustrator counts up from the bottom left-hand corner, presumably?)
Would you mind if I credit you in the comments lines of my new script? Is there a better way to do so other than Muppet Mark @ forums.adobe.com?
Thanks so much for all your help.
Copy link to clipboard
Copied
Wayne, thanks but no need… as long as you mark posts as helpful or correct that will be fine… It's out here for anyone to find…
Find more inspiration, events, and resources on the new Adobe Community
Explore Now