recursive loop

Hi

I'm quite new to scripting and wonder if its possible to write a function that will search through multiple nested vray blend materials.

For example
myBall has a blendMaterial and within this is another BlendMaterial and within this another.

At the moment I can use a for loop to keep goin through each array but this gets messy as the number of blendMaterials increases.

e.g
for i in 1 to ($.material.coatMtl.count) where classof $.material.coatMtl[i] == vrayBlendMtl do
(
for j in 1 to ($.material.coatMtl[i].coatMtl.count) where classof $.material.coatMtl[i].coatMtl[j] == vrayBlendMtl do
(
for h in 1 to ($.material.coatMtl[i].coatMtl[j].coatMtl.count) where classof $.material.coatMtl[i].coatMtl[j].coatMtl[h] == VrayBlendMtl do
"keep goin for all existing nested BlendMaterials"
)
)

I want to be able to search through and access all the vray materials that may populate these slots and for any given number of BlendMaterials that may exist.

if anyone could shed some light or point me in the right direction i'd appreciate it cheers

Comments

Comment viewing options

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

getClassInstances x

getClassInstances x

Raphael 'Insanto' Steves
http://Graph.Net84.Net

Situla's picture

Thanks

This is perfect thank you so much :)

Situla's picture

Thanks

Hi Garp

yea this seems to be what I need, excuse my lack of knowledge here:)

This gives me access to the an array of all the blends, how can I add all the vrayMtls that might populate the other 8 .coatMtl slots.

The idea here is to be able to find all vrayMtls in a scene no matter how deep in various blendMtl multiSub vray2SidedMtl etc

cheers

Garp's picture

Somthing like this?

(
    fn storeCoatMtls mtl arr = (
        if classOf mtl == VRayBlendMtl do (
            append arr mtl
            for m in mtl.coatMtl do storeCoatMtls m arr
        )
    )
 
    local theMtl = $.material
    local theCoatMtls = #()
    storeCoatMtls theMtl theCoatMtls
 
    print theCoatMtls
)

Comment viewing options

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