Hey there!
I need a piece of code that would execute random object selection among all objects belonging to a particular layer. And it's supposed to be one object. Also I need a snippet for children selection.
Thanks in advance.
Forum topic · Scripts Wanted
By Artie · 2015-11-21
Hey there!
I need a piece of code that would execute random object selection among all objects belonging to a particular layer. And it's supposed to be one object. Also I need a snippet for children selection.
Thanks in advance.
Artie · 2015-11-21
miauu, you've made my day!
I really appreciate your effort.
Thank you very much, miauu!
Artie · 2015-11-21
That's fabulous! Thank you very much, miauu!
Would be even geater if you wrote how to do the following:
1) Say, I have 5 layers each containing different objects.
2) I've selected all or a bunch of objects from each layer.
3) I want to select 5 random objects out of the current selection (one random object per each layer)
Thanks again!
.
miauu · 2015-11-21
(
selObjsArr = selection as array
if selObjsArr.count != 0 then
(
layersArr = #()
for o in selObjsArr do
(
selObjLayer = o.layer
appendIfUnique layersArr selObjLayer
)
objToSelArr = #()
for layer in layersArr do
(
layer.nodes &theNodes
append objToSelArr (theNodes[random 1 theNodes.count])
)
select objToSelArr
)
else
messagebox "Select at least one object" title:"Empty Selection"
)
.
miauu · 2015-11-21
The code below works with objects. How to use it:
1- select one object that belongs to the desired layer
2- run the script - random object from that layer will be selected.
You can run the script as many times as you want and it will select random object from the same layer
If you don't know which object to which layer belong, then in layer manager select all objects from the desired layer.
1- select several(or all) objects from desired layer
2- run the script - random objects from the selected will be selected
This works with objects that belongs to different layers, so you can select onbjects from different layers and the script will wors only with the selected objects.
(
if selection.count != 0 then
(
if selection.count == 1 then
(
-- "select all objects from the layer to which the selected object belong"
selObjLayer = (selection[1]).layer
selObjLayer.nodes &theNodes
select theNodes[random 1 theNodes.count]
)
else
(
selObjsArr = selection as array
select selObjsArr[random 1 selObjsArr.count]
)
)
else
messagebox "Select at least one object" title:"Empty Selection"
)