Copy link to clipboard
Copied
hieght=9.25;
width=12.125/2;
sPn=.375;
spineText="3/8\"";
templateMarks(hieght,width,sPn,spineText)
function templateMarks(hieght,width,spineWidth,spineText){
app.activeDocument.zeroPoint = [12,7.75];
myDocument=app.activeDocument
var mark1=app.activeDocument.pageItems.item("topLeftTicMark");
var mark2=app.activeDocument.pageItems.item("bottomLeftTicMark");
var mark3=app.activeDocument.pageItems.item("topOutsideSpine");
var mark4=app.activeDocument.pageItems.item("bottomOutsideSpine");
var mark5=app.activeDocument.pageItems.item("topRightTicMark");
var mark6=app.activeDocument.pageItems.item("bottomRightTicMark");
var mark7=app.activeDocument.pageItems.item("topInsideSpine");
var mark8=app.activeDocument.pageItems.item("bottomInsideSpine");
var mark9=app.activeDocument.pageItems.item("SpineSzText");
var templateItemsArray=[mark1,mark2,mark3,mark4,mark5,mark6,mark7,mark8,mark9];
//spineCenter=mark3.visibleBounds[1]-mark3.visibleBounds[3];
spineCenter=mark3.geometricBounds[1]-mark3.geometricBounds[3];
spineCenterInside=mark7.visibleBounds[1]-mark7.visibleBounds[3];
spineMarkHeight=mark4.visibleBounds[0]-mark4.visibleBounds[2];
spineTextWidth=mark9.visibleBounds[1]-mark9.visibleBounds[3];
spineTextHieght=mark9.visibleBounds[0]-mark9.visibleBounds[2];
horizontalGuides=[];
verticalGuides=[];
var templatePieces={
topLeftTicMark:{
item: mark1,
movement: [-width,-hieght/2]
},
bottomLeftTicMark:{
item: mark2,
movement: [-width,hieght/2]
},
topRightTicMark:{
item: mark3,
movement: [width,-hieght/2]
},
bottomRightTicMark:{
item: mark4,
movement: [width,hieght/2]
},
topOutsideSpine:{
item: mark5,
movement: [spineCenter/2,-hieght/2-spineMarkHeight]
},
bottomOutsideSpine:{
item: mark6,
movement: [spineCenter/2,hieght/2-spineMarkHeight+.75]
},
topInsideSpine:{
item: mark7,
movement: [spineCenterInside/2,-hieght/2-spineMarkHeight]
},
bottomInsideSpine:{
item: mark8,
movement: [spineCenterInside/2,hieght/2-spineMarkHeight+.75]
},
SpineSzText:{
item: mark9,
movement: [spineTextWidth/2,hieght/2-spineTextHieght+.75]
}
}
if(spineWidth<=.75){
templateItemsArray.splice(6,2);
mark7.remove()
mark8.remove()
}
countInside=0;
for (var i = 0; i < templateItemsArray.length; i++) {
try{
templateItemsArray.move(undefined,templatePieces[templateItemsArray.label.toString()]["movement"]);
if(templateItemsArray.label.toString().indexOf("OutsideSpine")!=-1){
var spineBounds=templateItemsArray.geometricBounds;
///after the spine marks are moved change the spine size
templateItemsArray.geometricBounds=[spineBounds[0],mark1.geometricBounds[3]+width-spineWidth/2,spineBounds[2],mark1.geometricBounds[3]+width+spineWidth/2];
}
if(templateItemsArray.label.toString().indexOf("InsideSpine")!=-1&&spineWidth>.75){
countInside++
var spineBounds=templateItemsArray.geometricBounds;
///after the spine marks are moved change the inside spine marks
templateItemsArray.geometricBounds=[spineBounds[0],mark1.geometricBounds[3]+width-spineWidth/2+.375,spineBounds[2],mark1.geometricBounds[3]+width+spineWidth/2-.375];///change size
if(countInside==1){
myDocument.guides.add(myDocument.layers[0],{orientation:HorizontalOrVertical.vertical, location:(templateItemsArray.geometricBounds[1])});
}
else{
myDocument.guides.add(myDocument.layers[0],{orientation:HorizontalOrVertical.vertical, location:(templateItemsArray.geometricBounds[3])});
}
}
}
catch(err){
$.writeln(err)
}
}
myDocument.guides.add(myDocument.layers[0],{orientation:HorizontalOrVertical.vertical, location:(0)});///Set vertical center of spine guide
myDocument.guides.add(myDocument.layers[0],{orientation:HorizontalOrVertical.vertical, location:(mark1.geometricBounds[3])});
myDocument.guides.add(myDocument.layers[0],{orientation:HorizontalOrVertical.horizontal, location:(mark1.geometricBounds[2])});
myDocument.guides.add(myDocument.layers[0],{orientation:HorizontalOrVertical.vertical, location:(mark1.geometricBounds[3]-.75)});
myDocument.guides.add(myDocument.layers[0],{orientation:HorizontalOrVertical.horizontal, location:(mark1.geometricBounds[2]-.75)});
myDocument.guides.add(myDocument.layers[0],{orientation:HorizontalOrVertical.vertical, location:(mark6.geometricBounds[1])});
myDocument.guides.add(myDocument.layers[0],{orientation:HorizontalOrVertical.horizontal, location:(mark6.geometricBounds[0])});
myDocument.guides.add(myDocument.layers[0],{orientation:HorizontalOrVertical.vertical, location:(mark6.geometricBounds[1]+.75)});
myDocument.guides.add(myDocument.layers[0],{orientation:HorizontalOrVertical.horizontal, location:(mark6.geometricBounds[0]+.75)});
myDocument.guides.add(myDocument.layers[0],{orientation:HorizontalOrVertical.vertical, location:(mark3.geometricBounds[1])});
myDocument.guides.add(myDocument.layers[0],{orientation:HorizontalOrVertical.vertical, location:(mark3.geometricBounds[3])});
///fill the spine text with the xml data about the spine size in fraction form///
mark9.contents=spineText+"\nSpine Size";
}
T
This works when run from the toolkit but it errors saying that the object spineCenter is not valid. I have not been able to figure out why the difference.
Copy link to clipboard
Copied
So the current solution is to add
app.scriptPreferences.version = "6.0"
I am wondering is there another way to do this?
is pageItems.item not acceptable?
Why did it work in the sdk the first time?
Copy link to clipboard
Copied
Can't answer too much here but...
Whoever said the rule "i before e except after c" was a liar.
The word is "height" and not "hieght"
Try the following.
After each of these lines
(Ignore the line numbering here) add $.writeln('mark1: ' + mark1.isValid)
i.e. mark1, marc2 etc.
One of them most likely is false, more likely all of them are false.
Then change on each like .item to .itemByName
See if that helps
Copy link to clipboard
Copied
You are correct in regards to spelling. However whether item or itemByName, neither works unless I use app.scriptPreferences.version="6.0"
Copy link to clipboard
Copied
Well 1 out of 2 is not bad 😉
What does isValid return?
Do you have a minimal test document with the named objects in it?
Copy link to clipboard
Copied
bagonterman wrote
You are correct in regards to spelling. However whether item or itemByName, neither works unless I use app.scriptPreferences.version="6.0"
Ok. That's InDesign CS4. And that's a good indication what perhaps is going wrong.
Fundamental things changed with InDesign CS5 version "7.0".
You perhaps used property label with the page items and not name.
Don't know if you hope to recieve an array or a collection of page items using pageItems.item("something"). In case you don't and there are several items labeled the same you have to deal with a collection of items that are returned with pageItems.item("something").
With CS4 there is no name property for a page item. There's just a label property you could access using the UI doing a Script Label.
Or by script doing it with pageItem.label = "something".
Then pageItems.item("something") or pageItems.itemByName("something") would catch all instances of the same labeled items in a given scope: document.pageItems or page.pageItems etc.pp.
FWIW:
With CS5 and above you could name an item with the Pages panel using InDesign's UI. Not possible with CS4.
Or you do this with a script that assigns a value to pageItem.name. Like pageItem.name = "something". But item("something") or itemByName("something") in CS5 or above will never return more than one item, always the first one that is named with "something" the script will find. Also note: In CS5 and above item("something") and itemByName("something") will never return the value of pageItem.label .
Regards,
Uwe
Find more inspiration, events, and resources on the new Adobe Community
Explore Now