selectNode - multiple objects same name?

selectNode - multiple objects same name?

Anonymous
Not applicable
1,460 Views
5 Replies
Message 1 of 6

selectNode - multiple objects same name?

Anonymous
Not applicable

Hi all,

 

I was hoping someone could help me solve a problem I'm having. I've forgotten how to write the script inside the variant set on how to select all objects with a single name regardless of the extra wording contained within.

I am looking to be able to select all items with the same name and then apply the corresponding materials with that equivalent.

 

Example below:


scenegraph
 -door_01
 -doorA
 -door_345
selectNode("door")?
*need to be able to select all nodes named door
*then replace nodes named door with material named door 'mat_door'
 
If anyone could help, it would be greatly appreciated!
 
thanks
0 Likes
Accepted solutions (1)
1,461 Views
5 Replies
Replies (5)
Message 2 of 6

sinje_thiedemann
Autodesk
Autodesk
Accepted solution

Hi,

to select all nodes that start with "door":

useWildcard = True
nodes = findNodes("door*", useWildcard)
selectNodes(nodes)

Please note, the function findNodes uses wildcard matching, not regular expressions as stated in the docs.

Kind regards

Sinje

Message 3 of 6

Anonymous
Not applicable

Hi, This works! Thank you for the help.

 

So using selectNodes to select the nodes in the scenegraph does not work in this way?

 

Is there an easier way to select each door and then alloy and apply door_mat and alloy_mat at the same time in the script?

 

select node "door" apply "door_material"

select node "alloy" apply "alloy_material"

 

 

0 Likes
Message 4 of 6

sinje_thiedemann
Autodesk
Autodesk

Hi,

sure you can apply materials with Python to nodes.

No need to use selectNode(s) then, just findNodes, then apply to the resulting list.

applyMaterial takes 2 lists, one node list, one material list. Both need to have the same length. If you want to apply the same material to all nodes, then pass a list that contains this material n times.

 

nodes = findNodes("door*", True)
newMaterial = findMaterial("mat_door")
materials = [newMaterial] * len(nodes) # list of materials, one for each node
applyMaterial(nodes, materials, False, False)

Kind regards

Sinje

0 Likes
Message 5 of 6

drewmcmasters
Observer
Observer

Hi, how would it work if you wanted to import mesh data with materials named MAT01, MAT02, etc. and assign them with a corresponding Vred Switch Material with the same name? Is this something built in when importing, or would I also need a script to do this?

 

Thanks for the help!

0 Likes
Message 6 of 6

seiferp
Community Manager
Community Manager

That can be done without script.

 

  1. Create your SwitchMaterials with the according Materials and call your Switch MAT01, MAT02 etc.
  2. Drag your SwitchMaterials into the Asset Manager. The according Materials are copied automatically
  3. Check "Apply Materials from Asset Manager" in the Import Dialog > Global Scene Options and select the folder you have stored your Switch Materials by clicking on the small library icon
  4. Press Import
  5. Your initial materials are than replaced with the Switch Materials that match the name

 

0 Likes