We have some important news to share: the Pixelmator Team plans to join Apple. If you need product support please contact us here.
Learn morePermit re-sorting of layers info based on X or Y location
The Pixelmator Community has been archived and cannot accept new posts or comments.
2024-08-17 00:52:55
I often have/want to re-sort layers based on location to make it easy to see/detect which item or layer I am wanting to edit. Pretty confident that ShaTy would be able to come up with something, but it would be handy if it were a native process available it the right click layers menu. Like in my first image that is unsorted and and a menu addition would be so nice. The second smaller image is after my manual sort.

2024-08-25 02:58:09
I took a quick stab at this tonight to see how hard it would be. Here's some basic Applescript code to accomplish this below. To use: select several layers then run the script. They will be sorted in the layer panel according to their x location on the doc.
After:

tell application "Pixelmator Pro"
tell its front document
set sel_lays to selected layers
set final_lay to {}
repeat with iter from 1 to (count of sel_lays)
set max_x_loc to -99000
set max_x_layer to item iter in sel_lays
repeat with sort from 1 to (count of sel_lays)
set clay to item sort in sel_lays
if (visible of clay) then
set this_pos to position of clay
if (item 1 of this_pos > max_x_loc) then
set max_x_loc to item 1 of this_pos
set max_x_layer to clay
#display alert "Layer " & name of max_x_layer & " location is max"
end if
else
#display alert "Layer" & name of clay & " is not visible"
end if
end repeat
tell max_x_layer to set visible to false
move max_x_layer to the beginning of layers
end repeat
repeat with mysort in (sel_lays)
tell mysort to set visible to true
end repeat
end tell
end tell
Before:After:
2024-08-25 22:45:28
I get errors on my objects. As you can see from the first image the five objects are unsorted, selected and the applescript run. the second image shows the result. One heart item is completely gone and there is no sort performed. Is there anything I am doing wrong, ShaTy?
Initial run on previous version, now: Version 3.6.8 (20240829.1539)
Initial run on previous version, now: Version 3.6.8 (20240829.1539)
2024-09-01 15:18:41
And, in the off chance that it was a horizontal versus vertical problem. I reran it on some vertical (do not show the nine symbol, unsorted images) Results the same with the last item removed. Any ideas?

2024-09-01 20:39:04
mccoytest - I was able to recreate the problem. When the layers are in a group folder it was hiting that error. Fixed below. Also added horizontal or vertical sorting button:
tell application "Pixelmator Pro"
tell its front document
#display dialog "Sort Vertical or Horizontal? "
set aButton to display dialog "Choose layer sort order?" with icon note buttons {"Vertical", "Horizontal"} default button "Horizontal"
set sort_direction to (button returned of aButton)
set sel_lays to selected layers
set final_lay to {}
repeat with iter from 1 to (count of sel_lays)
set max_x_loc to -99000
set max_x_layer to item iter in sel_lays
set x_parent to parent of max_x_layer
repeat with sort from 1 to (count of sel_lays)
set clay to item sort in sel_lays
if (visible of clay) then
set this_pos to position of clay
if (sort_direction = "Horizontal") then
set sort_by to item 1 of this_pos
else if (sort_direction = "Vertical") then
set sort_by to item 2 of this_pos
else
display alert "How to sort?"
return "pick vertical or horizontal"
end if
if (sort_by > max_x_loc) then
set max_x_loc to sort_by
set max_x_layer to clay
#display alert "Layer " & name of max_x_layer & " location is max"
end if
else
#display alert "Layer" & name of clay & " is not visible"
end if
end repeat
tell max_x_layer to set visible to false
if (x_parent = missing value) then
move max_x_layer to the beginning of layers
else
move max_x_layer to the beginning of layers in x_parent
end if
end repeat
repeat with mysort in (sel_lays)
tell mysort to set visible to true
end repeat
end tell
end tell
2024-09-02 15:04:35
That is awesome! Honestly, I had wondered about vertical and horizontal sorting, but since we were only trying to change the order in the layers column, I knew it would likely be very close. Now with those additions it is alway gonna be sorted right! You should delete these script entries sell this on your Etsy site; https://www.etsy.com/shop/UpliftingQuickArtist