Notifications
Clear all

[Closed] change vray effect ID channel script

ok, this will select all objects that have a VRay material where either effect_id is 0 or override_effect_id is off (false).

objARR =  for obj in objects where (isKindOf obj.material VRayMtl and (obj.material.effect_id == 0 or obj.material.override_effect_id == false)) collect obj
select objARR

Maybe you don’t want to select hidden objects…

objARR =  for obj in objects where ((obj.isHidden == false and isKindOf obj.material VRayMtl) and (obj.material.effect_id == 0 or obj.material.override_effect_id == false)) collect obj
select objARR

OK this works for when there is just a vraymtl applied to an object, but doesn’t look inside multisub materials, blend materials, etc. Is it possible to do that? That was why I was trying to re-use

vrmArr = getClassInstances vrayMtl target:obj

from your origional script.

Thanks,

Dean

Ok, I haven’t tested this much and it seems a bit slow in the large scene I’m working in:

objARR = #()
for obj in objects where obj.isHidden == false do
(
	vrmArr = for vrm in getClassInstances vrayMtl target:obj where (vrm.effect_id == 0 or vrm.override_effect_id == false) collect vrm
	if vrmArr.count != 0 do append objARR obj
)
select objARR

Here’s a faster way…

objARR = #()
vrmArr = for vrm in getClassInstances vrayMtl where (vrm.effect_id == 0 or vrm.override_effect_id == false) collect vrm
for m in vrmArr do
(
	deps = for d in refs.dependents m where isKindOf d GeometryClass collect d
	for dp in deps do appendIfUnique objARR dp
)
select objARR

I don’t know what is slowing the other way down.

Wow that’s spot on! (and totally past my ability!!) I can’t claim to understand it, but I know it will work perfectly in my script!

Thank you so much for your help, this script is almost ready. If you want to test it before I release it please let me know!

Thanks,

Dean

Amended to include renderable shapes and exclude hidden geometry:

objARR = #()
vrmArr = for vrm in getClassInstances vrayMtl where (vrm.effect_id == 0 or vrm.override_effect_id == false) collect vrm
for m in vrmArr do
(
	deps = for d in refs.dependents m where ((isKindOf d GeometryClass or isKindOf d shape) and d.isHidden == false) collect d
	for dp in deps do appendIfUnique objARR dp
)
select objARR
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

using of the refs.dependents to find nodes with an assigned material in this context is not correct. refs.dependents is doing recursive search of dependencies and might return the nodes with secondary dependency from the material.
here is a sample:
there is a node1 with assigned material ->
node1 is used as morph target of a modifier ->
the modifier applied to another node2
node2
will be in the list of the material dependents.

the right way is to use refs.dependentnodes. … and it’s faster. … and you don’t need to check node’s class.

Wow that’s spot on! (and totally past my ability!!) I can’t claim to understand it, but I know it will work perfectly in my script! Thank you so much for your help, this script is almost ready. If you want to test it before I release it please let me know!
That’s ok, here’s the code with a bit of explanation:

objARR = #() -- Declare an empty array
vrmArr = for vrm in getClassInstances vrayMtl where (vrm.effect_id == 0 or vrm.override_effect_id == false) collect vrm --find all VRay materials with either effect_id set to 0 or override_effect_id off
for m in vrmArr do --Go through the materials
(
	--find all unhidden GeometryClass or shape objects that reference the material m and put them in an array "deps"
	deps = for d in refs.dependents m where ((isKindOf d GeometryClass or isKindOf d shape) and d.isHidden == false) collect d
	--append the objects in deps to the array objARR but only if they aren't in there already (appendIfUnique)
	for dp in deps do appendIfUnique objARR dp 
)
select objARR

Yes I’ll certainly have a look at your script when it’s finished and I hope some this makes sense.

Thanks, I understand it a bit more now, but I definitly wouldn’t have figured all that out by myself!!

If you drop me a PM with your email I can forward it to you.

Thanks,

Dean

Thanks (again) for your input Denis. I hadn’t really thought about situations like the one in your example. I only tested it on the scene I’m working in and it selected the same number of nodes as my first (slower) method so I assumed it was ok.

So if you’re still reading this Dean code should be:

objARR = #()
vrmArr = for vrm in getClassInstances vrayMtl where (vrm.effect_id == 0 or vrm.override_effect_id == false) collect vrm
for m in vrmArr do
(
	deps = for d in refs.dependentnodes m where d.isHidden == false collect d
	for dp in deps do appendIfUnique objARR dp 
)
print objARR.count
select objARR
Page 2 / 3