• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Find Space around logo and alert if any pageitem present in that space

Community Beginner ,
Mar 28, 2022 Mar 28, 2022

Copy link to clipboard

Copied

Hi All,

I'm trying to find any object that is near or around the logo. By adding 1/3 of the logo height to it's bounds

How to skip the parent object of the graphic link? for the below script

Here is the script:

 

function _clear_space_around_logo(){  
    var myDoc = app.activeDocument;
    var myPages = myDoc.pages;
    for(var a=0;a<myPages.length;a++){
        var myGraphics = myPages[a].allGraphics;
        for(var b=0;b<myGraphics.length;b++){
            if(myGraphics[b].itemLink != null){
                if(myGraphics[b].itemLink.name.search(/Logo/i)>0){
                    if(myGraphics[b].parent.rotationAngle == 0 || myGraphics[b].parent.rotationAngle == 180){
                        var geo0 = myGraphics[b].geometricBounds[0];
                        var geo1 = myGraphics[b].geometricBounds[1];
                        var geo2 = myGraphics[b].geometricBounds[2];
                        var geo3 = myGraphics[b].geometricBounds[3];
                        var requiredHeight = (geo2-geo0)/3;
                        var reuqiredGeo0 = geo0-requiredHeight;
                        var reuqiredGeo1 = geo1-requiredHeight;
                        var reuqiredGeo2 = geo2+requiredHeight;
                        var reuqiredGeo3 = geo3+requiredHeight;
                    }
                    else{
                        var geo0 = myGraphics[b].geometricBounds[0];
                        var geo1 = myGraphics[b].geometricBounds[1];
                        var geo2 = myGraphics[b].geometricBounds[2];
                        var geo3 = myGraphics[b].geometricBounds[3];
                        var requiredHeight = (geo3-geo1)/3;
                        var reuqiredGeo0 = geo0-requiredHeight;
                        var reuqiredGeo1 = geo1-requiredHeight;
                        var reuqiredGeo2 = geo2+requiredHeight;
                        var reuqiredGeo3 = geo3+requiredHeight;
                    }
                    var myPagesItems = myPages[a].allPageItems;
                    for(var c=0;c<myPagesItems.length;c++){
                        if(myPagesItems[c].itemLayer.visible == true && myPagesItems[c].visible == true){
                            var itemGeo0 = myPagesItems[c].geometricBounds[0];
                            var itemGeo1 = myPagesItems[c].geometricBounds[1];
                            var itemGeo2 = myPagesItems[c].geometricBounds[2];
                            var itemGeo3 = myPagesItems[c].geometricBounds[3];
                            
                            if(itemGeo0>myPages[a].bounds[0] && itemGeo1>myPages[a].bounds[1]&&
                                itemGeo2<myPages[a].bounds[2] && itemGeo3<myPages[a].bounds[3]){
                                if(itemGeo2 > reuqiredGeo0 && itemGeo3 > reuqiredGeo1 &&
                                    itemGeo0 < reuqiredGeo2 && itemGeo1 < reuqiredGeo3){
                                    if(myPagesItems[c].constructor.name != "Group"){
                                        try{
                                            if(myPagesItems[c].itemLink.name.search(/Logo/i)==-1){
                                                alert(myPages[a].name);
                                            }
                                        }
                                        catch(e){
                                            alert(myPages[a].name);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

 

Thanks

TOPICS
Scripting

Views

183

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

Community Expert , Mar 28, 2022 Mar 28, 2022

Store the id of the parent container and skip it on your check. 

 

var pid = myGraphics[b].parent.id;

 

Then...

 

if (myPageItems[c].id == pid) continue;

 

Votes

Translate

Translate
Community Expert ,
Mar 28, 2022 Mar 28, 2022

Copy link to clipboard

Copied

Store the id of the parent container and skip it on your check. 

 

var pid = myGraphics[b].parent.id;

 

Then...

 

if (myPageItems[c].id == pid) continue;

 

Votes

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 ,
Mar 28, 2022 Mar 28, 2022

Copy link to clipboard

Copied

Thanks @brianp311 ,

I will update this now.

In mean time, I used this code to skip the pageitem

if(itemGeo0 != geo0 && itemGeo1 != geo1 && itemGeo2 != geo2 && itemGeo3 != geo3).

Votes

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 Expert ,
Mar 28, 2022 Mar 28, 2022

Copy link to clipboard

Copied

LATEST

Sure, that would work unless you have another container that is exactly the same as the parent. Always a possibility. 

Votes

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