CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 02-14-2012, 02:24 PM   #1
phantomx
New Member
portfolio
Yan Verde
Montreal, Canada
 
Join Date: Jul 2010
Posts: 20
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 :

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-14-2012, 07:09 PM   #2
martinez
Expert
 
martinez's Avatar
portfolio
Juan Martinez
Animator
Verse, Inc
Dallas, USA
 
Join Date: Feb 2002
Posts: 218
Send a message via ICQ to martinez Send a message via AIM to martinez
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.

Code:
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-14-2012, 07:37 PM   #3
phantomx
New Member
portfolio
Yan Verde
Montreal, Canada
 
Join Date: Jul 2010
Posts: 20
nice explanation, it's working like a charm!
Thanks!
__________________
http://www.yvgrafix.com
 
Old 10-11-2012, 10:50 AM   #4
coolankur49
Veteran
 
coolankur49's Avatar
portfolio
Ankur Chaudhary
Technical Artist
Crest Animation Studios Ltd
Mumbai, India
 
Join Date: Jan 2007
Posts: 30
I was searching something like this only.
 
Old 10-11-2012, 12:55 PM   #5
PixelBaker
New Member
 
PixelBaker's Avatar
André Schaarschmidt
Germany
 
Join Date: Nov 2004
Posts: 12
A shorter version would be:

Code:
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-11-2012 at 02:50 PM. Reason: modified after post from denisT
 
Old 10-11-2012, 02:42 PM   #6
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,871
Send a message via ICQ to denisT
if a function selects something by a condition it has to clear selection if nothing meets the criteria.
Code:
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-11-2012, 07:55 PM   #7
martinez
Expert
 
martinez's Avatar
portfolio
Juan Martinez
Animator
Verse, Inc
Dallas, USA
 
Join Date: Feb 2002
Posts: 218
Send a message via ICQ to martinez Send a message via AIM to martinez
Even shorter. With no arrays.

Code:
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-11-2012, 08:14 PM   #8
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,871
Send a message via ICQ to denisT
Quote:
Originally Posted by martinez
Even shorter. With no arrays.

Code:
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-11-2012, 10:04 PM   #9
LoneRobot
Swami Lama's Lovechild
 
LoneRobot's Avatar
portfolio
Pete Addington
Technical Director
Nexus
United Kingdom
 
Join Date: Dec 2004
Posts: 1,784
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-11-2012, 10:04 PM   #10
CGTalk Moderation
Expert
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,478
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 06:35 AM.


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