# Select all objects consecutivly along axis

Would like to be able to multi select objects consecutively along + or - XYZ axis. (Example: so that they are selected in order from left to right along X axis)

As it stands right now selecting multiple objects at once seems to randomize the order.

## Comment viewing options

### ...

This can help

```fn sortByAxis arr1 arr2 axis: maxtomin: =
(
local first, second
case axis of
(
(#x): (first = arr1.pos.x ; second = arr2.pos.x)
(#y): (first = arr1.pos.y ; second = arr2.pos.y)
(#z): (first = arr1.pos.z ; second = arr2.pos.z)
)
case of (
(first < second): if not maxtomin then -1 else 1
(first > second): if not maxtomin then 1 else -1
default:0
)
)
-- example
delete objects
cnt = 1
objArr = for c in #(Box, Teapot, Cylinder, Cone, Sphere) collect (obj = c pos:[(cnt*50), 0, 0] ; cnt+=1 ; obj)
qsort objArr sortByAxis axis:#x maxtomin:off -- selected in order from left to right along X axis
print objArr
--qsort objArr sortByAxis axis:#x maxtomin:on -- selected in order from right to left along X axis```

barigazy

### ...

As you can see you can choose any axis and sorting order ei:
-> if you set #x axis and "maxtomin" argument is "off" then objects array is sorted
along x-axis from left to right
-> if you set #z axis and "maxtomin" argument is "on" then objects array is sorted
along z-axis from top to bottom
etc.
It's easy pretty much :)
Cheers!

barigazy

### ...

This is another example of QSort method
http://www.scriptspot.com/forums/3ds-max/general-scripting/example-how-t...

barigazy

### This is just what I needed..

This is just what I needed.. however how do you ignore objects on hidden layers ?

### ...

To collect all not hidden objects just use

`for o in objects where not o.isHidden collect o`

At least try to read MXS help

barigazy