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

Trying to Compare Geometric Bounds if Many items are Selected instead of two items

Enthusiast ,
Sep 04, 2022 Sep 04, 2022

Copy link to clipboard

Copied

Hi Experts,

I was comparing the geometric bounds for just two selected items, so the following simple script will just test if the two selected items are different is size or not so it will (de-Select) one of them, can this script updated to select any items to comapre them and de-select all the items that are matching in geometric size instead of only two items?, here is the starting script :

//Test Two Selected items Gemoetry Size
var item1 = app.selection[0];
var item2 = app.selection[1];

//for Item 1
var myWidth1 =  Math.round(item1.geometricBounds[3]-item1.geometricBounds[1]);
var myHeight1 = Math.round(item1.geometricBounds[2]-item1.geometricBounds[0]);

//for Item 2
var myWidth2 =  Math.round(item2.geometricBounds[3]-item2.geometricBounds[1]);
var myHeight2 = Math.round(item2.geometricBounds[2]-item2.geometricBounds[0]);

try{
              if((myWidth1 == myWidth2) && (myHeight1 == myHeight2)){              
                    alert("Only One Same Size Item to Be Selected!, Please Always Select Different Size Items!", "Info!");
                    app.selection[0].select(SelectionOptions.REMOVE_FROM);
               }else{
                    alert("Your Selected items is Different Size Items!", "Info!");
		}
	}catch(e){
}

 I know i can collect all selected items but i dont know if i can compare them at once!, actually im not sure if this is possible with javascript?,  in this exmaple i collect all widths and heigt but i cant figure how to comapre them and deselect all the matches!, im stucked here and thanks in advance for any help or advice

for (var i = 0; i < app.selection.length; i++) {
        var mySelection =  app.activeDocument.selection[i].geometricBounds;
        var myWidth = Math.round(mySelection[3]-mySelection[1]);
        var myHeight = Math.round(mySelection[2]-mySelection[0]);
}

 

Best
Mohammad Hasanin
TOPICS
Scripting

Views

94

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 ,
Sep 04, 2022 Sep 04, 2022

Copy link to clipboard

Copied

First of all - which object in the selection will be the "source" for the size?

Then, you just need to loop through the rest of the selected objects and compare them to the "source".

ID-Tasker - most powerful tool ever created for InDesign

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
Enthusiast ,
Sep 04, 2022 Sep 04, 2022

Copy link to clipboard

Copied

@Robert Tkaczyk Thanks for your reply,  actually no matter which object is the source, just the one or two or more or whatever number of items, if one or more match any size of the others items it will be de-selected automatically!, so the only selection will remain in different size (geometries) object will still selected

Best
Mohammad Hasanin

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 ,
Sep 04, 2022 Sep 04, 2022

Copy link to clipboard

Copied

So you are looking for "singles"?

Then you need two loops - one inside the other - and when outer one is iteratig through all of them ONCE - the inside loop should check all remaining again and again - starting from the next object after the one from the outside loop - simplest approach.

 

Another way - get sizes of all objects into an array and sort and then compare results - fastest option. 

ID-Tasker - most powerful tool ever created for InDesign

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
Enthusiast ,
Sep 04, 2022 Sep 04, 2022

Copy link to clipboard

Copied

LATEST

@Robert Tkaczyk Thanks a lot for your guide, i will do my best, thanks again, have a great day

Best
Mohammad Hasanin

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