selection loop with a clause

I wonder if someone could point me in the right direction with this:

I have modified a script that converts all scene materials to plain random coloured materials.

I am trying to add a clause, so the script ignores materials that have a refraction colour less than black and/or have refractance map enabled.

The script as I have it is attached (it has been written to function with Vray).

Any help would be massively appreciated!

Thanks

Danny

AttachmentSize
channels.ms1001 bytes

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
barigazy's picture

I have not tested this but

I have not tested this but you can test it and tell me it is works

mtlClassArr = #(VRayMtl,Multimaterial,VRayOverrideMtl,VRayBlendMtl,Blend)
fn filtMTL mtl = isKindOf mtl VRayMtl and mtl.Relection == black and mtl.texmap_refraction != undefined
fn createStdMtl = 
(
	Mat = StandardMaterial diffuse:[random 0 255, random 0 255, random 0 255] selfillumamount:100
	Mat.Diffuse.s = Mat.Diffuse.v = 255 ; Mat
)
for o in objects where o.material != undefined do     
(
	mtl = o.material
	if (idx = findItem mtlClassArr (classof mtl) != 0 do
	(    
		case idx of (
			(1): ( --VRayMtl
				if filtMTL mtl do mtl = createStdMtl()
			)
			(2): ( --Multimaterial
				mmtArr = mtl.materialList
				for m = 1 to mmtArr.count where filtMTL mmtArr[m] do (mtl.materialList)[3] = createStdMtl()
			)
			(3): ( --VRayOverrideMtl
				if filtMTL mtl.baseMtl do mtl.baseMtl = createStdMtl()
				if filtMTL mtl.giMtl do mtl.giMtl = createStdMtl()
				if filtMTL mtl.reflectMtl do mtl.reflectMtl = createStdMtl()
				if filtMTL mtl.refractMtl do mtl.refractMtl = createStdMtl()
				if filtMTL mtl.shadowMtl do mtl.shadowMtl = createStdMtl()
			)
			(4): ( ---VRayBlendMtl
				if filtMTL mtl.baseMtl do mtl.baseMtl = createStdMtl()
				for m = 1 to 9 where filtMTL mtl.coatMtl[m] do mtl.coatMtl[m] = createStdMtl()
			)
			(5): ( --Blend
				if filtMTL mtl.map1 do mtl.map1 = createStdMtl()
				if filtMTL mtl.map2 do mtl.map2 = createStdMtl()
			)
		)
	)
)

bga

FATdan's picture

Thanks!!

Hi barigazy.
Thanks for looking at this!!

It generated an error the first time I ran it but I think that was due to an extra ) at the end.

The following error was as follows:

"-- Error occurred in anonymous codeblock; filename: ; position: 12; line: 1
-- Syntax error: at name, expected while
-- In line: mtlClassArr ="

(could you tell me how to insert code on posts please? I can't find any info on the sticky)

I am assuming that the script is halted at the point of error as nothing changes in the scene.

Any thoughts?

Many Thanks

Danny

barigazy's picture

try now

I forgot to put the close brucket in line 10

mtlClassArr = #(VRayMtl,Multimaterial,VRayOverrideMtl,VRayBlendMtl,Blend)
fn filtMTL mtl = isKindOf mtl VRayMtl and mtl.Relection == black and mtl.texmap_refraction != undefined
fn createStdMtl = 
(
	Mat = StandardMaterial diffuse:[random 0 255, random 0 255, random 0 255] selfillumamount:100
	Mat.Diffuse.s = Mat.Diffuse.v = 255 ; Mat
)
for mtl in scenematerials do     
(
	if (idx = findItem mtlClassArr (classof mtl)) != 0 do
	(    
		case idx of 
		(
			(1): ( --VRayMtl
				if filtMTL mtl do mtl = createStdMtl()
			)
			(2): ( --Multimaterial
				mmtArr = mtl.materialList
				for m = 1 to mmtArr.count where filtMTL mmtArr[m] do (mtl.materialList)[m] = createStdMtl()
			)
			(3): ( --VRayOverrideMtl
				if filtMTL mtl.baseMtl do mtl.baseMtl = createStdMtl()
				if filtMTL mtl.giMtl do mtl.giMtl = createStdMtl()
				if filtMTL mtl.reflectMtl do mtl.reflectMtl = createStdMtl()
				if filtMTL mtl.refractMtl do mtl.refractMtl = createStdMtl()
				if filtMTL mtl.shadowMtl do mtl.shadowMtl = createStdMtl()
			)
			(4): ( ---VRayBlendMtl
				if filtMTL mtl.baseMtl do mtl.baseMtl = createStdMtl()
				for m = 1 to 9 where filtMTL mtl.coatMtl[m] do mtl.coatMtl[m] = createStdMtl()
			)
			(5): ( --Blend
				if filtMTL mtl.map1 do mtl.map1 = createStdMtl()
				if filtMTL mtl.map2 do mtl.map2 = createStdMtl()
			)
		)
	)
)

bga

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.