Reference bitmap textures in an array based on bitmap name with maxscript
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm looking at writing a script that will take the selected bitmap textures in the slate editor, and then automatically connect the nodes to the correct slots on the objects material. I've chosen to do it based on bitmap name as part of the script will make the name of the bitmap node the same name as the image filename.
I can then connect the diffuse texture map to the base color map slot of a physical material by searching the selected nodes for bitmap textures with "_Diffuse" in its name, and then doing the same for the other selected nodes in the array ("_Roughness", "_Normal", etc etc).
However I'm having trouble search through the array and separately get each selected node to connect to their intended slots, currently this version of the script works but it will just connect the last node in the array and connect it to the base color map slot on the material:
on btn5 pressed do
(
if sme.IsOpen() do
(
v = sme.GetView sme.activeView
pm = physicalMaterial()
if (node = (v.GetSelectedNodes())[1]) != undefined do
map = node.reference
(
if iskindof map Bitmaptexture do $.material.base_color_map = map
)
)
)I've tried a few different things to separate objects in selected nodes based on name including using matchpattern() but I cannot figure it out, I think at the very least I am ruining the syntax when I try to do anything too complex.
Any help please?