Materialz=#()
AllMAterialz=#()
	

fn CollectMaterialz=
(
for obj in $ do (try appendifunique Materialz obj.material catch false)
for m in Materialz do (
mcount=0
try (
mcount=m.count 
for mm in m do appendifunique AllMAterialz mm
) 
catch appendifunique AllMAterialz m
)	
Materialz=#()
AllMAterialz
)


fn MapEnablerrr=
(
	
AllMAterialz=CollectMaterialz()
	
Mdifuse=off
Mbump=off
Mopacity=off
Mreflection=off
Mrefraction=off
Mselfilum=off
MDispl=off
	
if MapEnabler.chkDiff.state==true then Mdifuse=on
if MapEnabler.chkBump.state==true then Mbump=on
if MapEnabler.chkOpac.state==true then Mopacity=on
if MapEnabler.chkReflect.state==true then Mreflection=on
if MapEnabler.chkRefract.state==true then Mrefraction=on
if MapEnabler.chkSelfIlum.state==true then Mselfilum=on
if MapEnabler.chkDispl.state==true then MDispl=on
for m in AllMaterialz do (

if  (classof m) == VrayMtl then 
	( 
	m.texmap_diffuse_on = Mdifuse
	m.texmap_bump_on = Mbump
	m.texmap_opacity_on = Mopacity
	m.texmap_reflection_on = Mreflection
	m.texmap_refraction_on = Mrefraction
	m.texmap_displacement_on=MDispl
	)
	
	
if  (classof m) == StandardMaterial then 
	(

	m.diffuseMapEnable = Mdifuse
	m.bumpMapEnable = Mbump
	m.opacityMapEnable = Mopacity
	m.selfillumMapEnable = Mselfilum
	m.reflectionMapEnable = Mreflection
	m.refractionMapEnable = Mrefraction
	m.displacementMapEnable=MDispl	
	)
)
	
)	
	
fn MapAmounterrr=
(
AllMAterialz=CollectMaterialz()
Adifuse=MapEnabler.spnDiff.value
Abump=MapEnabler.spnBump.value
Aopacity=MapEnabler.spnOpac.value
Areflection=MapEnabler.spnRefl.value
Arefraction=MapEnabler.spnRefr.value
Aselfilum=MapEnabler.spnSelf.value
Adispl=MapEnabler.spnDispl.value
	
for m in AllMaterialz do (

if  (classof m) == StandardMaterial then 
	(
	m.diffuseMapAmount = Adifuse
	m.opacityMapAmount = Aopacity
	m.bumpMapAmount = Abump
	m.reflectionMapAmount = Areflection
	m.refractionMapAmount = Arefraction
	m.selfIllumAmount = Aselfilum
	m.displacementMapAmount = Adispl
	)	
if  (classof m) == VrayMtl then 
	( 
	m.texmap_diffuse_multiplier = Adifuse
	m.texmap_reflection_multiplier = Areflection
	m.texmap_refraction_multiplier = Arefraction
	m.texmap_bump_multiplier = Abump
	m.texmap_displacement_multiplier = Adispl
	m.texmap_opacity_multiplier = Aopacity
	)


)	
)
	
rollout MapEnabler "Map Controller" width:182 height:180
(
	groupBox grp1 "Map Controller" pos:[2,3] width:178 height:169
	
	checkbox chkDiff "Diffuse" pos:[74,20] width:100 height:16 checked:true
	checkbox chkBump "Bump" pos:[74,56] width:100 height:16 checked:true
	checkbox chkOpac "Opacity" pos:[74,38] width:100 height:16 checked:true
	checkbox chkReflect "Reflection" pos:[74,74] width:100 height:16 checked:true
	checkbox chkRefract "Refraction" pos:[74,92] width:100 height:16 checked:true
	checkbox chkSelfIlum "SelfI llumination" pos:[74,110] width:100 height:16 checked:true
	checkbox chkDispl "Displacement" pos:[74,128] width:95 height:16 checked:true
	button btn1 "Apply" pos:[73,149] width:103 height:19
	
	
	spinner spnDiff "" pos:[8,20] width:59 height:16 range:[0,100,100]
	spinner spnOpac "" pos:[8,38] width:59 height:16 range:[0,100,100]
	spinner spnBump "" pos:[8,56] width:59 height:16 range:[0,100,100]
	spinner spnRefl "" pos:[8,74] width:59 height:16 range:[0,100,100]
	spinner spnRefr "" pos:[8,91] width:59 height:16 range:[0,100,100]
	spinner spnSelf "" pos:[8,110] width:59 height:16 range:[0,100,100]
	spinner spnDispl "" pos:[8,128] width:59 height:16 range:[0,100,100]
	button btn6 "Apply" pos:[7,149] width:63 height:19
	
	on btn6 pressed  do MapAmounterrr()
	on btn1 pressed do MapEnablerrr()
)

	
if $!=undefined then ( 
	
try destroydialog MapEnabler catch false
CreateDialog MapEnabler	
	)
else MessageBox "Nothing selected"