Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Need help unable to progress

Community Beginner ,
Nov 09, 2021 Nov 09, 2021

Copy link to clipboard

Copied

_SaftyMargin();

function _SaftyMargin(){
    //_reportMatch.push("Check_safty_margin");
    var myDoc = app.activeDocument;
    var myPages = myDoc.pages;
    var marginValue = 12.7;
    convertToMM();
    for(var p=0;p<myPages.length;p++){
        var BoundsTop = myPages[p].bounds[0].toFixed(2);
        
        var BoundsLeft = myPages[p].bounds[1].toFixed(2);
        
        var BoundsBottom = myPages[p].bounds[2].toFixed(2);
        
        var BoundsRight = myPages[p].bounds[3].toFixed(2);
        
        var myPagesItem = myPages[p].allPageItems;
        for(var s=0;s<myPagesItem.length;s++){
            if (myPagesItem[s].itemLayer.visible == true && myPagesItem[s].visible == true) {
                if(myPagesItem[s].constructor.name != "PDF"
                && myPagesItem[s].constructor.name != "Image" && myPagesItem[s].constructor.name != "EPS"){
                    var geo = myPagesItem[s].geometricBounds;

                    var objTop = geo[0].toFixed(2);
                    
                    
                    var objLeft = geo[1].toFixed(2);
                    
                    
                    var objBottom = geo[2].toFixed(2);
                    
                                        
                    var objRight = geo[3].toFixed(2); //0,0,215.9,274.4

                    alert(objTop + ">" + BoundsTop + "&&" + objLeft + ">" + BoundsLeft + "&&" + objBottom + "<" + BoundsBottom  + "&&" + objRight + "<" + BoundsRight);
                    
                                        
                    if(objTop > BoundsTop && objLeft > BoundsLeft && objBottom < BoundsBottom && objRight < BoundsRight){
                        
                        if(objTop < BoundsTop+marginValue || objLeft < BoundsLeft+marginValue || objBottom > BoundsBottom-marginValue || objRight > BoundsRight-marginValue){
                            alert(myPages[p].name);
                        }   
                    }
                    else if(objTop == BoundsTop || objLeft == BoundsLeft || objBottom == BoundsBottom || objRight == BoundsRight){
                        alert(myPages[p].name);
                    }                    
                }
            }
        }     
    }
}
function convertToMM(){
    app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
    app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
    app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
    app.activeDocument.zeroPoint = [0,0];
}

 

For this screenshot case the above script is not working I even checked with alert that all case in the IF loop is getting true.

 

To my knowledge the above script should work but it is not working. Kindly help me to progress further.

 

Thanks

 

 

 

Screenshot 2021-11-10 at 7.54.48 AM.png

TOPICS
Scripting

Views

49

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Nov 09, 2021 Nov 09, 2021
hi after .toFixed (2) the variable becomes a string, use + to get number var BoundsTop = +myPages[p].bounds[0].toFixed(2);

Likes

Translate

Translate
Participant ,
Nov 09, 2021 Nov 09, 2021

Copy link to clipboard

Copied

hi after .toFixed (2) the variable becomes a string, use + to get number

 

var BoundsTop = +myPages[p].bounds[0].toFixed(2);

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 10, 2021 Nov 10, 2021

Copy link to clipboard

Copied

LATEST

Thanks and this is the final version:

_SaftyMargin();
alert("Processed");
//_SaftyMargin_Array.push
function _SaftyMargin(){
    //_reportMatch.push("Check_safty_margin");
    var myDoc = app.activeDocument;
    var myPages = myDoc.pages;
    var marginValue = 3;
    convertToMM();
    
    for(var p=0;p<myPages.length;p++){
        var BoundsTop = Number(myPages[p].bounds[0]).toFixed(2);
        var BoundsLeft = Number(myPages[p].bounds[1]).toFixed(2);
        var BoundsBottom = Number(myPages[p].bounds[2]).toFixed(2);
        var BoundsRight = Number(myPages[p].bounds[3]).toFixed(2);
        var myPagesItem = myPages[p].allPageItems;
        for(var s=0;s<myPagesItem.length;s++){
            if (myPagesItem[s].itemLayer.visible == true && myPagesItem[s].visible == true) {
                if(myPagesItem[s].constructor.name != "PDF"
                && myPagesItem[s].constructor.name != "Image" && myPagesItem[s].constructor.name != "EPS" ){
                    var geo = myPagesItem[s].geometricBounds;
                    var objTop = Number(geo[0]).toFixed(2);
                    var objLeft = Number(geo[1]).toFixed(2);
                    var objBottom = Number(geo[2]).toFixed(2);
                    var objRight = Number(geo[3]).toFixed(2);
                    
                    

                    if(objTop >= BoundsTop || objLeft >= BoundsLeft || objBottom <= BoundsBottom || objRight <= BoundsRight){
                        if(objTop < Number(BoundsTop)+Number(marginValue) || objLeft < Number(BoundsLeft)+Number(marginValue) ||
                        objBottom > Number(BoundsBottom)-Number(marginValue) || objRight > Number(BoundsRight)-Number(marginValue)){
                            myPagesItem[s].select();
                            alert(myPages[p].name);
                        }   
                    }
                }
            }
        }     
    }
}


function convertToMM(){
    app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
    app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
    app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
    app.activeDocument.zeroPoint = [0,0];
}

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines