Square area percent of page report
Sure this is not the first time someone has looked for a way to do this, but I can't find a solution.
Script to find the square inch area of the each object in the whole document > make a new layer > place a tag on each object stating that object's square area > also generate the percentage of that object's area compared to the page size.
I'm a novice and have hobbled together a few scripts that I've found but can't connect them up. So far I've adjusted a script to return geometric bounds of a selected object. And I modified another script that generates labels on a separate layer (the labels display various attributes of each object, color space, name, link etc).
It seems that inserting my get geometric bounds script should be inserted into the labels script with the parts concerning object attributes but I can't see how (again major Novice).
Haven't figured out how to get the document bounds (though that seems fairly obvious) and how to translate my geometric bounds into inches and find the % of page. I did find an almost perfect script (at the bottom) but it is for Illustrator and doesn't work off the same structure.
My code below. Anything from a point in the right direction to a rewrite would be amazing! Though I really want to understand how so I can contribute, teaching myself but practical applications is not always the best place to learn.
Script #1: Code for geometric bounds (where can I insert this into script #2 to apply square inches and % of page to picture/text labels)
Object.prototype.height = function() { var bds = this.geometricBounds;
//not using visible bounds, can't see how that would help here but maybe I'm wrong return [ b[3]-b[1] , b[2]-b[0] ]; }
Script #2: Code for labels (need to convert area from points to inches and find % of page)
var myScriptVer = "2.1"; var myInfoTitle = "Image Info"; var myInfoColor = [0,15,100,0]; var yPos = 100; var xPos = 100;
//getting document length and measurements but not sure that is passing anywhere
if(app.documents.length != 0){
var myDocument = app.activeDocument;
var myOrgDocHUnits = myDocument.viewPreferences.horizontalMeasurementUnits;
var myOrgDocVUnits = myDocument.viewPreferences.verticalMeasurementUnits;
var myOrgDocOrigin = myDocument.viewPreferences.rulerOrigin;
myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.millimeters;
myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.millimeters;
myDocument.viewPreferences.rulerOrigin = RulerOrigin.spreadOrigin;
var myLinks = myDocument.links;
if(myLinks.length != 0){
var myDialog = app.dialogs.add({name:"Contact Sheet Labels"+ myScriptVer});
with(myDialog){
with(dialogColumns.add()){
with (dialogRows.add()){
with(borderPanels.add()){
with(dialogColumns.add()){
with (dialogRows.add()){
staticTexts.add({staticLabel:"Loose Proof Label Displays:"});
}
with(borderPanels.add()){
with(dialogColumns.add()){
with (dialogRows.add()){
staticTexts.add({staticLabel:"Link Info:\t"});
}
}
with(dialogColumns.add()){
with (dialogRows.add()){
var myNameOpt = checkboxControls.add({staticLabel:"File Name\t", checkedState:true});
}
with (dialogRows.add()){
var myPathOpt = checkboxControls.add({staticLabel:"File Path", checkedState:true});
}
}
with(dialogColumns.add()){
with (dialogRows.add()){
var myTypeOpt = checkboxControls.add({staticLabel:"File Type\t\t", checkedState:false});
}
with (dialogRows.add()){
var myStatusOpt = checkboxControls.add({staticLabel:"Link Status", checkedState:false});
}
}
}
with(borderPanels.add()){
with(dialogColumns.add()){
with (dialogRows.add()){
staticTexts.add({staticLabel:"Image Info:\t"});
}
}
with(dialogColumns.add()){
with (dialogRows.add()){
var myActResOpt = checkboxControls.add({staticLabel:"Actual PPI\t", checkedState:true});
}
with (dialogRows.add()){
var myEffResOpt = checkboxControls.add({staticLabel:"Effective PPI", checkedState:false});
}
}
with(dialogColumns.add()){
with (dialogRows.add()){
var myScaleOpt = checkboxControls.add({staticLabel:"Scale Percentage\t", checkedState:false});
}
with (dialogRows.add()){
var myColSpaceOpt = checkboxControls.add({staticLabel:"Color Space", checkedState:true});
}
}
}
}
}
}
with (dialogRows.add()){
with(borderPanels.add()){
with(dialogColumns.add()){
with (dialogRows.add()){
var myLabelOpt = checkboxControls.add({staticLabel:"Printable Labels", checkedState:true});
}
}
}
}
with (dialogRows.add()){
staticTexts.add({staticLabel:"Contact Sheet Labels"});
}
}
}
var myResult = myDialog.show({name:"SplitOptions"});
if(myResult == true){
//Clear previous layer, color, and styles
for(i = 0;i < myDocument.layers.length;i++){
var myLayer = myDocument.layers;
if(myLayer.name == myInfoTitle){
myLayer.remove();
}
}
for(i = 0;i < myDocument.colors.length;i++){
var myColor = myDocument.colors;
if(myColor.name == myInfoTitle){
myColor.remove();
}
}
for(i = 0;i < myDocument.paragraphStyles.length;i++){
var myPStyle = myDocument.paragraphStyles;
if(myPStyle.name == myInfoTitle){
myPStyle.remove();
}
}
for(i = 0;i < myDocument.characterStyles.length;i++){
var myCStyle = myDocument.characterStyles;
if(myCStyle.name == myInfoTitle){
myCStyle.remove();
}
}
//Create the link info layer
var myLinkInfoLayer = myDocument.layers.add();
myLinkInfoLayer.name = myInfoTitle;
//Create the link info color
var myLinkInfoColor = myDocument.colors.add();
myLinkInfoColor.name = myInfoTitle;
myLinkInfoColor.colorValue = myInfoColor;
//Create the link info Character Style
var myLinkInfoCStyle = myDocument.characterStyles.add();
myLinkInfoCStyle.name = myInfoTitle;
try{
myLinkInfoCStyle.fontStyle = "Semibold";
}
catch(e){}
//Create the link info Paragraph Style
var myLinkInfoPStyle = myDocument.paragraphStyles.add();
myLinkInfoPStyle.name = myInfoTitle;
try{
myLinkInfoPStyle.paragraphDirection = ParagraphDirection.leftToRightDirection;
}
catch(e){}
myLinkInfoPStyle.justification = Justification.leftAlign;
try{
myLinkInfoPStyle.appliedFont = "Myriad Pro";
myLinkInfoPStyle.fontStyle = "Regular";
}
catch(e){}
myLinkInfoPStyle.pointSize = 6;
myLinkInfoPStyle.leading = 6;
myLinkInfoPStyle.appliedLanguage = "English: USA";
myLinkInfoPStyle.hyphenation = false;
myLinkInfoPStyle.leftIndent = "8mm";
myLinkInfoPStyle.firstLineIndent = "-8mm";
var myLink, myLinkPos, myLinkName, myLinkPath, myLinkType, myLinkStat, myLinkInfoStr, myLinkParent, myLinkSpread, myLinkStatus, myLinkInfoFrame;
for(l = 0;l < myLinks.length;l++){
myLink = myLinks
.appliedParagraphStyle = myInfoTitle; myLinkInfoFrame.parentStory.paragraphs
.words[0].appliedCharacterStyle = myInfoTitle; } myLinkInfoFrame.fit(FitOptions.frameToContent); } } } } myDocument.viewPreferences.horizontalMeasurementUnits = myOrgDocHUnits; myDocument.viewPreferences.verticalMeasurementUnits = myOrgDocVUnits; myDocument.viewPreferences.rulerOrigin = myOrgDocOrigin; }
Script #3: Code object area labels, but for Illustrator (basically what I want)
if ( app.documents.length > 0 && app.activeDocument.selection.length > 0 ) { //Declare the variables. var myDocument=app.activeDocument; var pathRef=docRef.selection[0]; var pathRefArea=pathRef.area; var myReturn="\r"; //Convert pathRefArea to other units of measure. Store them in a text variable named areaMessage. var areaMessage="Square Points: "+Math.round(pathRefArea*100)/100+myReturn +"Square Picas: "+(Math.round((pathRefArea/144)*100))/100+myReturn +"Square Inches: "+(Math.round((pathRefArea/5184)*100))/100+myReturn +"Square Millimeters: "+(Math.round((pathRefArea/8.037)*100))/100+myReturn +"Square Centimeters: "+(Math.round((pathRefArea/803.520)*100))/100 //Display areaMessage in an alert. alert (areaMessage); //Create a textFrame and set its contents to areaMessage. var areaLabel = docRef.textFrames.add(); areaLabel.contents = areaMessage; for(i=0;i<areaLabel.paragraphs.length;i++){ areaLabel.paragraphs.justification=Justification.CENTER; } //Position areaLabel at the center of the selected path. areaLabel.top = pathRef.top-pathRef.height/2+areaLabel.height/2; areaLabel.left = pathRef.left+pathRef.width/2-areaLabel.width/2; //Create a temporary textFrame named squarePoints to hold just the value of pathRef's area in square points. var squarePoints = docRef.textFrames.add(); squarePoints.contents = Math.round(pathRefArea*100)/100; //Deselect pathRef. Select squarePoints. Redraw. Cut squarePoints to the clipboard. pathRef.selected=false; squarePoints.selected=true; redraw(); app.cut(); }
