Skip to main content
Known Participant
October 3, 2024
Answered

align rectangular objects

  • October 3, 2024
  • 3 replies
  • 986 views

Hi team!, I have an urgent question: is there a script or option that would allow me to align 10 randomly distributed squares, rectangles, or other rectangular geometric shapes so that they are adjacent to each other without overlapping or leaving any gaps? I frequently perform this task and would like to see if there is a way to save some valuable seconds. Thank you very much

This topic has been closed for replies.
Correct answer Kurt Gold

Based on your screenshot, the default Align palette should do it pretty effectively. Not sure if you can really save valuable seconds with any other techniques, such as using scripts.

 

Also based on your screenshot, I can imagine that you may save way more time by using some sophisticated template strategies. That would have to be clarified further, of course.

 

However, in case you may want to try another scripting approach, there is a nice script by Alexander Ladygin. It's called "Harmonizer" and you can get it on GitHub.

3 replies

Nicky G.
Known Participant
October 3, 2024

Simple, No script

HanschrsAuthor
Known Participant
October 3, 2024

Works perfectly, thanks

Charu Rajput
Community Expert
Community Expert
October 3, 2024

Hi,

Based on your description, try the following snippet.

Please. make sure to select your items that you would like to arrange. Also if you want to give some space between the shapes then change the value of gap variable.

if (app.activeDocument.selection.length === 0) {
    alert("Please select at least one object.");
} else {
    var selectedObjects = app.activeDocument.selection;
    var currentX = 0; // Starting X position
    var currentY = 0; // Starting Y position
    var gap = 0;
    for (var i = 0; i < selectedObjects.length; i++) {
        var obj = selectedObjects[i];
        obj.left = currentX;
        obj.top = currentY;
        currentX += obj.width + gap;
    }
}

 

Best regards
HanschrsAuthor
Known Participant
October 3, 2024

thans a lot

 

Doug A Roberts
Community Expert
Community Expert
October 3, 2024

Can you share an example?

HanschrsAuthor
Known Participant
October 3, 2024

sure

Kurt Gold
Community Expert
Kurt GoldCommunity ExpertCorrect answer
Community Expert
October 3, 2024

Based on your screenshot, the default Align palette should do it pretty effectively. Not sure if you can really save valuable seconds with any other techniques, such as using scripts.

 

Also based on your screenshot, I can imagine that you may save way more time by using some sophisticated template strategies. That would have to be clarified further, of course.

 

However, in case you may want to try another scripting approach, there is a nice script by Alexander Ladygin. It's called "Harmonizer" and you can get it on GitHub.