(Noob) Help with Selecting nodes from an Array

(Noob) Help with Selecting nodes from an Array

Anonymous
Not applicable
876 Views
8 Replies
Message 1 of 9

(Noob) Help with Selecting nodes from an Array

Anonymous
Not applicable

Hi All,

 

I'm trying to find info on how I can select the nodes from an array that has already been created? So if I defined the following array, how would I select that?

 

partsAR = #($part01, $component02, $thing03)

 

I found this site but if the answer is in there, I'm too ignorant to know what it looks like sadly. I'm expecting something like "select partsAR", but it probably isn't that simple. 

 

Thank you for your time guys, I really appreciate it!

0 Likes
Accepted solutions (1)
877 Views
8 Replies
Replies (8)
Message 2 of 9

kdbusi
Participant
Participant

selected = $ as array -- put selected in array 
print (selected as string)

select selected[1]  --"select partsAR[1]      ["1"] is the index in array "
select selected     --"selects all in array--

 

 

 

 

0 Likes
Message 3 of 9

Anonymous
Not applicable

So is this creating an array based on selection? 

 

I effectively want to define the contents of the array in advance (not based on selection) and use it as a sort of Selection Set, so I can easily select those parts since the names will always be the same. 

 

Edit: Ok so I when using only "select partsAR[1]" it will select whichever part corresponds to that index location, but how can I select the entire array as simply as possibly?

 

When I remove the brackets and index reference and run it I get this:

-- Runtime error: operation requires a collection of nodes, got: undefined

0 Likes
Message 4 of 9

denisT.MaxDoctor
Advisor
Advisor
partsAR = #($part01, $component02, $thing03)

select partsAR[1] -- selects node $part01 or the first element of your array

select partsAR -- selects all nodes from the array if all of them are still valid

 

0 Likes
Message 5 of 9

Anonymous
Not applicable
if all of them are still valid 

 Ok, so this is the part that was tripping me up, not all objects in my array will always be present in the scene at all times. Once I removed the node that was not in the scene, "select arrayName" works and selects all nodes in the scene AND array. 

 

I'm putting together some basic tools to help with my QA tasks at work to compare two sets of LODs, so it needs to be able to work based on a fixed set of node names, but not all nodes will be present at all times.

 

So this leads me to my next question, is there any way to have an all inclusive array to cover all potential nodes, but only select what happens to be available in any given scene? 

 

And while we're at it, my goal is to have it select 2 different arrays, lets say parts1AR and parts2AR and hide everything else so I can view both together for comparison. 

 

Thanks again for the help guys! I've done my best to scour the interwebs to cobble this stuff together, but unfortunately I'm never given enough time to actually understand anything so I appreciate your patience and willingness to help an ignorant fool like myself 🙂 

0 Likes
Message 6 of 9

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

you have to learn how to write scripts, bro ...

 

but here are some methods that can help you:

my_node_names = 
#(
	"A",
	"B",
	"C",
	"D"
)
my_lods_names = 
#(
	"A_lod",
	"B_lod",
	"C_lod",
	"D_lod"
)

fn collectMyNodes names = 
(
	for name in names where isvalidnode (node = getNodeByName name) collect node
)
fn selectNodes nodes =
(
	valid_nodes = for node in nodes where isvalidnode node collect node 
	if valid_nodes.count > 0 then select valid_nodes else clearselection()
)
fn selectNodeByName name = 
(
	if isvalidnode (node = getNodeByName name) do select node
)
fn selectNodesByName names = 
(
	valid_nodes = for name in names where isvalidnode (node = getNodeByName name) collect node
	if valid_nodes.count > 0 then select valid_nodes else clearselection()
)

/* usage ****************************

my_node_nodes = collectMyNodes my_node_names
my_lods_nodes = collectMyNodes my_lods_names

*/

but using this technique you have to understand that node names in your scene must be unique. Other way the system will return you the first picked node (usually first created in the scene) with specified name.

 

Hide/Unhide/Isolate... it will be better to use built-in MAX UI methods for now. Other way you have to write your own tool with a User Interface you like

 

  

   

 

 

0 Likes
Message 7 of 9

Anonymous
Not applicable

I agree I really do need to properly learn this stuff, I feel like such a dingus having to bug you guys. I'm sure you probably have better things to do with your time. I really do appreciate it though! 

 

I'll do my best to incorporate what you have provided, but for now I've relegated myself to making "dumb" code that gets the job done until I can make it smarter later. 

 

 

max unhide all            --these 3 lines are just to make sure everything is hidden to start, but not the layers
max select invert
max hide selection

unhide $*thing_a*         -- unhide first set of parts (more than this in actual code)
unhide $*part_a*

unhide $*thing_b* -- unhide second set of parts (more than this in actual code)
unhide $*part_b* select (for obj in $*_a* where not obj.isHiddenInVpt collect obj) --select one of the two sets based on keyword

The last part is not anything I came up with, just something someone was kind enough to help me with before. Like I said, overall pretty dumb "brute force" method I'm sure. 

 

0 Likes
Message 8 of 9

denisT.MaxDoctor
Advisor
Advisor

it will be helpful if you tell us about "naming convention" used in your pipeline. 

we might suggest some better solutions..  

0 Likes
Message 9 of 9

Anonymous
Not applicable

I know, I apologize for being obtuse. Since it is for a client, I'm being a bit cautious as I don't know what I'm allowed to say. I'm probably being a bit too cautious though. 

0 Likes