Notifications
Clear all

[Closed] change vray effect ID channel script

Hey all,

I’m trying to knock up a script to make use of the Effect ID function to use with the MultiMatteElement. All is going OK, but I cannot figure out why I am receiving an error when I test the script.
When I run the script I get –

–Unknown property: “material” in undefined.

and it highlights the line “if classof i.material == MultiMaterial do”

If I comment out either VrayMtl section, or the MultiMaterial section, then I no longer recieve this error.

This is a snippet of the code where I believe the error is happening. –

		fn changechannel =
		(
			for i in selection do 
				
				if classof i.material == VrayMtl do
				(
				i.material.override_effect_id = on
				i.material.effect_id = matidd
				)
				
				if classof i.material == MultiMaterial do
				(
				
				for ID = 1 to i.material.materialList.count do 
					i.material.materialList[ID].effect_id = matidd
					i.material.materialList[ID].override_effect_id = on
				)
)

Also on possibly an unrelated issue, when I try to test the MultiMaterial script, I recieve this error –

–Type error : array must be positive number, got: , got: undefined.

using this script on a multi sub material.

fn changechannel =
		(
			for i in selection do 
				
				--if classof i.material == VrayMtl do
				--(
				--i.material.override_effect_id = on
				--i.material.effect_id = matidd
				--)
				
				if classof i.material == MultiMaterial do
				(
				
				--i.material.effect_id = matid
				for ID = 1 to i.material.materialList.count do 
					i.material.materialList[ID].effect_id = matidd
					i.material.materialList[ID].override_effect_id = on
				)

)

Any help would be really appreciated, max script isn’t really my thing, but I try!

Cheers,

Dean

26 Replies

I think the problem with you first snippet is the lack of parentheses around the code in the for loop:

fn changechannel =
(
	objs = getCurrentSelection()
	
	for i in objs where isProperty i #material do
	(		
		if classof i.material == VrayMtl do
		(
			i.material.override_effect_id = on
			i.material.effect_id = matidd
		)
		
		if classof i.material == MultiMaterial do
		(
			for ID = 1 to i.material.materialList.count do 
			i.material.materialList[ID].effect_id = matidd
			i.material.materialList[ID].override_effect_id = on
		)
	)
)

I’ve also added a check to test whether the object has the property material.

Here’s a way to find ALL VRay materials on selected objects. It should find those inside VRayBlend, VRayOverride, etc. not just multimaterial.

fn changechannel =
(
	objs = getCurrentSelection()
	
	for obj in objs do
	(
		vrmArr = getClassInstances vrayMtl target:obj
		
		for vrm in vrmArr do
		(
			vrm.override_effect_id = on
			vrm.effect_id = matidd
		)
	)
)

That’s amazing! Thanks a lot, that was going to be next on the task list, but you beat me to it! You’re definatley getting a mention in the script! It’s almost complete now, so will upload it to my site shortly and let you have a play!

Once again, thanks!!

Dean

Thanks.

I’ll definitely have a look when it’s finished. We use VRay mostly here.

Which company do you work for?

TSK group plc, it’s a design and build company.

Hello,

Me again! I have another querry, hopefully the last, before the script is ready.

I’m trying to select all objects where the effect id = 0

so far I have


 selected_objects = $
 
 			for m in selected_objects do
 			(
 				vrmArr = getClassInstances vrayMtl target:obj
 				select (for vrm in vrmArr where vrm.effect_id ==0 collect vrm)
 				
 			)
 

But when I run the script it says OK, but doesnt select the objects with ID = 0, any ideas?

EDIT: Also it would be great to collect where override_effect_id = off too.

Thanks,

Dean

Hi,

I not sure what you’re trying to do exactly. Scene objects themselves don’t have the property effect_id, they may have a material applied to them and the material might have the property effect_id. Do you want to select all objects that have a material applied that has effect_id set to 0?

Yes, I just want to select all objects that have vray materials applied, and that have an effect_id = 0

Thanks,

Dean

Page 1 / 3