Notifications
Clear all

[Closed] Copying Vraymtl to all MatEdit slots?

Hi again.

I wanted to write a script that would change all slots from default Standard to Vraymtl instantly. So this is what i wrote:

macroScript SetVraymtlAll
  category:"Martins's Utilities"
  (
  	global a
  	global foo
  	global tm
  	global m
  	global z
  	
  	foo = vraymtl diffusemap: none()
  	a=foo
  	z=0
  	for m in meditMaterials do 
  	(
  		z=z+1
  		setMeditMaterial z a
  	)
  
  )

Excuse me for using some random variable names, will have to change everything, when done.
Ok, so the problem is that it assigns the new material as instances, so when i add a checker for example as a diffuse map, every slot has a Vraymtl with a checker in diffuse slot. One thing that bugs me is that in material editor there is no sign of it – Make unique button is still inactive.
Any idea why? Some advice? Thanks in advance.

3 Replies

Honestly your code seems kinda crazy to me but that’s ok, that’s what this forum is for!
The reason your materials appear to be showing up as instances is that you have predefined a variable ‘foo’ to hold a single vraymtl, and that same material is being applied to each slot in the material editor. So you see, the materials aren’t actually instances at all, they are the exact same material! -which explains why the ‘make unique’ button is still inactive
the code you want is:

for i = 1 to 24 do meditMaterials[i] = VRayMtl name:("VrayMtl " + i as string)

this will create a new vraymtl for each iteration of the loop and assign it to the indexed slot of the material editor.
Hope this helps!

Hey, thanks for reply.
Yeah, have to agree my scripting skills right now are rubbish and now when i saw your code it looks so logical and clear. But it was my second script with more that one line so i hope sooner or later i will be there.
Thanks again!

Also you can use the code below:

 fn putvray = 
(
for i = 1 to 24 do
(
meditmaterials[i] = vraymtl name:("Vraymtl" + i as string)
)
)
fn putstnd = 
(
for j = 1 to 24 do
(
meditmaterials[j] = standard name:("Standard" + j as string)
)
)
rollout changemat "Change Mat"
(
group "Materials"
(
radiobuttons rud00 labels:#("Vraymtl","Standard")
button change "Change material"
)
on change pressed do
(
if rud00.state == 1 then
(
putvray()
)
else
(
putstnd()
)
 
)
)
createdialog changemat width:200 height:80

Best,
Ehsan.