View Full Version : Select layers by prefix name
phantomx 02-14-2012, 01:24 PM Hi,
I'm still new to max script and I'm writing this function to select all nodes in layers that matches a given prefix name.
so far I'm able to find the right layers, I just don't know how to select objects in these layer.
here's my code :
fn selectLayerPrefix str = (
local objArray = #()
for i= 1 to (LayerManager.count-1) where (
matchpattern (LayerManager.getLayer i).name pattern:(str+"*")
) do (
append objArray (LayerManager.getLayer i).nodes
)
select objArray
)
selectLayerPrefix "LGT_"
so my array gives me: objArray: #(nodes(), nodes()), I just what ton know how to select them.
Thanks!
|
|
martinez
02-14-2012, 06:09 PM
It's a little weird, but nodes isn't a property of a layer. It's a function that assigns the array of nodes to a variable.
Also, you'll want to use JOIN instead of APPEND since the select command doesn't like arrays inside of arrays.
fn selectLayerPrefix str =
(
local objArray = #()
for i= 1 to (LayerManager.count-1) where
(
matchpattern (LayerManager.getLayer i).name pattern:(str+"*")
)
do
(
(LayerManager.getLayer i).nodes &theNodes
join objArray theNodes
)
select objArray
)
selectLayerPrefix "LGT_"
phantomx
02-14-2012, 06:37 PM
nice explanation, it's working like a charm!
Thanks!
coolankur49
10-11-2012, 10:50 AM
I was searching something like this only. :)
PixelBaker
10-11-2012, 12:55 PM
A shorter version would be:
function selectNodesInsideLayerWithPrefix inPrefix =
(
local nodesInsideLayerWithPrefix = for nodeOn in objects where matchPattern nodeOn.layer.name pattern:(inPrefix +"*") collect nodeOn
if nodesInsideLayerWithPrefix.count > 0 then
select nodesInsideLayerWithPrefix
else
clearSelection()
)
selectNodesInsideLayerWithPrefix "LGT_"
denisT
10-11-2012, 02:42 PM
if a function selects something by a condition it has to clear selection if nothing meets the criteria.
if list.count > 0 then select list else clearselection()
other way the selecting of empty list will keep the current selection, which is not correct.
martinez
10-11-2012, 07:55 PM
Even shorter. With no arrays. :)
function selectLayerPrefix str =
(
clearSelection()
for i = 1 to LayerManager.count-1 where matchPattern (LayerManager.getLayer i).name pattern:(str +"*") do (LayerManager.getLayer i).select on
)
selectLayerPrefix "Control"
denisT
10-11-2012, 08:14 PM
Even shorter. With no arrays. :)
function selectLayerPrefix str =
(
clearSelection()
for i = 1 to LayerManager.count-1 where matchPattern (LayerManager.getLayer i).name pattern:(str +"*") do (LayerManager.getLayer i).select on
)
selectLayerPrefix "Control"
more selection changed callbacks than by selecting all nodes at once ;)
LoneRobot
10-11-2012, 10:04 PM
In my talk at EUE the year before last I detailed a layer control script (http://lonerobot.net/?p=1239) that we used in production for many years. There are a lot of methods included that you could use for writing something similar.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.