Select Child nodes in MaxScript

Select Child nodes in MaxScript

M_J_ARSHAD
Explorer Explorer
1,973 Views
3 Replies
Message 1 of 4

Select Child nodes in MaxScript

M_J_ARSHAD
Explorer
Explorer

Hi, We use selectmore $ or select $ to select the objects.

selectmore $.children only lets us select children of the first level down, but what is the code for selecting all the children, like when we right click and do select child nodes?

I want to select the parent and all the children.
As of now im using :

 

for obj in objects where matchPattern (obj.name) pattern:((truncatedName + "*")) do
(
selectmore obj
selectmore obj.children
IsolateSelection.EnterIsolateSelectionMode()
)

0 Likes
Accepted solutions (1)
1,974 Views
3 Replies
Replies (3)
Message 2 of 4

Swordslayer
Advisor
Advisor
Accepted solution

Many many ways to do that, here you can use the pathname literals:

 

select (execute ("$'" + truncatedName + "'*...*"))

 

Then there're ways that are more universal like the classic recursion way, while loop or you can use live array:

 

 

pattern = truncatedName + "*"
collectedObjs = for obj in objects where matchPattern obj.name pattern:pattern collect obj
select (for obj in collectedObjs collect (join collectedObjs obj.children; obj))

 

 

And if you wanted to create hard to comprehend code that does too many selection updates instead, you could do this:

 

 

pattern = truncatedName + "*"
for obj in objects where matchPattern obj.name pattern:pattern do selectMore (#() + obj)

 

 

0 Likes
Message 3 of 4

denisT.MaxDoctor
Advisor
Advisor

@Swordslayer wrote:

 

select (execute ("$'" + truncatedName + "'*...*"))

 

The above solution is the best one in terms of performance and memory usage... Unfortunately, it looks pretty ugly for the code.

 

( ... and maybe it needs a little fix:)

 

(
	select (execute ("$'" + pattern + "'/...*"))		
)

 

 

 

It also could be not as performance-good, but can be nice to look at:

 

(
	nodes = #()
	for obj in objects where matchPattern obj.name pattern:pattern do (nodes += obj)
	select nodes
)

 

0 Likes
Message 4 of 4

denisT.MaxDoctor
Advisor
Advisor

@denisT.MaxDoctor wrote:

@Swordslayer wrote:

 

 

 

 

select (execute ("$'" + truncatedName + "'*...*"))

 

 

 

 

The above solution is the best one in terms of performance and memory usage... Unfortunately, it looks pretty ugly for the code.

 


There is another problem with using the pathname value with the pattern... the problem is that for pathname, the "_" and " " (space) in the name are not different. Also pathname does not expect a space at the beginning and end of name. This can make it difficult to find the right nodes using a pattern that contains spaces.

 

 

 

 

delete objects

a = dummy name:"a a a"
b = dummy name:"a_a a" pos:[20,0,0]
c = dummy name:"a a_a" pos:[40,0,0]
d = dummy name:"a_a_a" pos:[60,0,0]
x = dummy name:"a b b" pos:[80,0,0] -- !!!
 
select $'* a *'

 

 

 

0 Likes