ScriptSpot

Forum topic · General Scripting

selection loop with a clause

By FATdan · 2013-01-14

Downloads
Description

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

Comments (13)

teresa · 2013-02-19

Such a useful code! I did try your code posted and it really works. I'm familiar with different programming languages but I'm not familiar with these one. Can anyone tell me where I can undergo training in terms of programming?-testosterone booster

Thank you for your informative post, it gives me a big help

how to boost testosterone

FATdan · 2013-01-15

this time the output looks like this:


#(VRayMtl, Multimaterial, VRayOverrideMtl, VRayBlendMtl, Blend)
filtMTL()
createStdMtl()
OK

Which all looks good... however, nothing changes in the scene...
I'm probably missing something straight forward but I can't see it.

Thanks

insert code method

barigazy · 2013-01-15

Look under "INPUT FORMAT > Filtered HTML" for more tags

FATdan · 2013-01-15



--thanks

barigazy · 2013-01-15

If I understand you correctly, you need a function that will filter all VRay materials with black reflection color and assigned reflaction map.
For that i create "filtMTL" function.
If state is true then all theses materials will be converted to Standard Flat-Colored material.

FATdan · 2013-01-15

ahhh.
it's actually the other way around. Sorry I should have been clearer in my explanation.

Currently the script is used to convert a scene into solid colours per material. The rendered output is then used by the post production dep. What we are doing manually is converting all the glass materials (and alike) back to glass.

This is so that when glass objects cover another object, the channel render shows what is seen through the glass.

So, I am trying to get the script to basically ignore the mats that have transparency so they render the colours beyond them.

I hope that makes sense. Let me know if not.
I have attached an example of where this occurs.

Thanks for the help with this!!

Attachments

barigazy · 2013-01-15

Now you can change filtMtl function what to filter out.


fn filtMTL mtl = isKindOf mtl VRayMtl and mtl.reflection != black and mtl.texmap_refraction == undefined

Also why not find all glass mtl and put in opacyty slot VRayColor map with pure black color when you want to extract wall behind, and then remove VrayColor map for the final render

FATdan · 2013-01-15

Ok. Great. Could this be "or" instead of "and"?


black or mtl.texmap_refraction

The opacity is a good idea although I actually need to keep the refraction so it deforms the rendered serface behind.

Thanks again for the assistance on this.
I've got some more work to do with it but I'll let you know how I get on.

Danny

barigazy · 2013-01-15

About "or"
Yes u can use it but your fn need to find mtl that have both main proerties of glass shader (reflection and reflaction). Thats the reason why i use "And" instead of "or".
Cheers!

barigazy · 2013-01-14

In your case, i think it is better to start for-loop like this
for mtl in scenematerials do ...

barigazy · 2013-01-14

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()
)
)
)
)

Thanks!!

FATdan · 2013-01-15

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

try now

barigazy · 2013-01-15

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()
)
)
)
)