Notifications
Clear all

[Closed] Materials by layer

This is my first attempt at Maxscript. I’d like a script that will assign materials by layer. Most of my jobs are architectural, and start out very similar. I also use standard layer naming. My models may be created in a variety of software, but they all honor the same layer names.

So it would be very helpful if I could open my template scene which contains starting lights, cameras, etc., then import or link the model, then run the script to do the majority of the mapping. I’d rather go in and make changes than start from scratch on every job.

I searched for something similar, but came up with nothing. So here’s what I’ve come up with so far.


 macroScript JSS-BasicSetup category:"JSS" 
 (
 	intTotalLayers = layermanager.count
 
 	For i = 1 to intTotalLayers	do -- Note:  Skip 0 since I don't care about layer 0
 	(
 		indCurLayer = layermanager.getlayer i
 		strCurLayer = indCurLayer.Name
 		max select none
 		indCurLayer.select true
 		
 		-- Need to use a lookup table here to get material name	    
 		
 		
 	) -- end layer loop
 ) -- end script
 

I know it’s not much, but I’m trying!

What would work best here? To store the layer:material associations in an external file? How would I read it in and parse it?

Can someone give me a push in the right direction?

4 Replies

Nothing?

What I would do first is to create a material library with all your materials named in a logical way so it would be easier to work with their names. Also at the end of the name I would add for example (UxVxW) where you replace U, V & W with numbers to be parsed in the script and used for mapping size.

The last part is to select all objects whithin the same layer or with the same name and to apply material from lib and mapping.

It’s a pretty custom script because you have to use your naming convention for the objects and materials.

Hope this helps!

Thanks for the reply. I understand the steps… I’m stuck on the details.

For example, how do I select all the objects on a layer?

Here is a small sample on how to select from all the objects in the scene just the ones in the layer named “_red” :

 
clearNodeSelection()
for i=1 to objects.count do
(
 if objects[i].layer.name == "_red" do selectMore objects[i]
)

Look in the MAXScript Reference because you’ll find everything in there! (I never worked with layers before and it took me 5 minutes to find what I needed to write this little sample…)