Select layers by prefix name

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 02 February 2012   #1
Select layers by prefix name

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!
__________________
http://www.yvgrafix.com
 
Old 02 February 2012   #2
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_"
__________________
Juan Martinez | Blog | Animator
 
Old 02 February 2012   #3
nice explanation, it's working like a charm!
Thanks!
__________________
http://www.yvgrafix.com
 
Old 10 October 2012   #4
I was searching something like this only.
 
Old 10 October 2012   #5
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_"

Last edited by PixelBaker : 10 October 2012 at 02:50 PM. Reason: modified after post from denisT
 
Old 10 October 2012   #6
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.
 
Old 10 October 2012   #7
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"
__________________
Juan Martinez | Blog | Animator
 
Old 10 October 2012   #8
Originally Posted by martinez: 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
 
Old 10 October 2012   #9
In my talk at EUE the year before last I detailed a layer control script that we used in production for many years. There are a lot of methods included that you could use for writing something similar.
__________________
Regards,
Pete

Read my technical blog - lonerobot.net
 
Old 10 October 2012   #10
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 04:58 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.