Light include/exclude list....format items in array?

Light include/exclude list....format items in array?

Anonymous
Not applicable
2,002 Views
10 Replies
Message 1 of 11

Light include/exclude list....format items in array?

Anonymous
Not applicable

Hello friends, I am trying to do a simple script for listing scene lights that have an include or exclude, and also print a list of the included/excluded items.

 

I have this for a start (filtering out the light targets):

 

for i in lights where (classof i != Targetobject) do
		if (i.includelist != undefined) then
		(
			print (i.name + " Includes these items:")
			print i.includelist
		)

 

...and it gives me this result:

 

"VRayLight001 Includes these items:"
$Box:Box001 @ [-35.890526,34.681732,0.000000]
$Box:Box002 @ [5.210434,31.309677,0.000000]
$Box:Box003 @ [5.210434,-8.237305,0.000000]
OK

 

I want to format the items in the includelist array so that only the names will be printed. If I try this:

for i in lights where (classof i != Targetobject) do
		if (i.includelist != undefined) then
		(
			print (i.name + " Includes these items:")
			
			for item in (i.includelist) to (i.includelist.count) do
				(
				print item.name
				)
		)

....it throws an error, saying it's unable to convert the items in the array to integer. The problem seems to be with me not knowing how to format the result as object names.

 

I could use a gentle push in the right direction. Any help or advice is most welcome. Thanks for your time.

 

0 Likes
Accepted solutions (1)
2,003 Views
10 Replies
Replies (10)
Message 2 of 11

Steve_Curley
Mentor
Mentor
You were almost there. The includelist is an array therefore you need to index into the array to get at each item in the list and only then can you access its Name property.

for theLight in lights where (classof theLight != Targetobject) do
	(
	if (theLight.includelist != undefined) then
		(
		print (theLight.name + " Includes these items:")
		for listItem = 1 to theLight.includelist.count do
			print theLight.includeList[listItem].name
		)
	)

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 3 of 11

Anonymous
Not applicable

Thank you Steve. As usual, when I post here I come up with a solution and come back and say 'duh, never mind guys, I figgered it out'....it seems the prime ingredient in my solution is to make myself look dumb on a forum and I come up with the answer! 🙂

 

In this case I tried to do exactly what you're saying and I came up with this, and it sort of works:

 

for i in lights where (classof i != Targetobject) do

		if (i.includelist != undefined) then
			(
				print (i.name + " Includes:")
				
				_incl = (i.includelist)
				for j=1 to _incl.count do
					(
					print _incl[j].name
					)
			)
		else
			if (i.excludelist != undefined) then
			(
				print (i.name + " Excludes:")
				
				_excl = (i.excludelist)
				for k=1 to _excl.count do
					(
					print _excl[k].name
					)				
			)
			else()

This does work for me but the problem is it prints all the lights, not just the ones with include or exclude. Seems my conditional statement is wrong somewhere. Does this make sense??

 

Thanks very much! Love this forum.

0 Likes
Message 4 of 11

Steve_Curley
Mentor
Mentor
Accepted solution
You need to test not only for the existence of the list but also its length, because the default is an Exclude list (of 0 length). It's also possible to set it to an empty Include list hence the same tests in both cases.
You can do that in a single compound statement because Maxscript uses Short Circuit evaluation of tests so if the first one fails the second is never evaluated (and would cause an error if it was).

for L in lights where (classof L != Targetobject) do
	(
	if ((L.includelist != undefined) and (L.includelist.count != 0)) then
		(
		print (L.name + " Includes:")

		_incl = L.includelist
		for j = 1 to _incl.count do
			print _incl[j].name
		)
	else
		(
		if ((L.excludelist != undefined) and (L.excludelist.count != 0)) then
			(
			print (L.name + " Excludes:")

			_excl = (L.excludelist)
			for j= 1 to _excl.count do
				print _excl[j].name
			)				
		)
	)

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 5 of 11

Swordslayer
Advisor
Advisor

It's worth mentioning that some lights don't have includelist/excludelist properties (for example mr_Sky). And you don't need to check for targetobject, that one belongs to the geometry collection. So the first line should rather be:

 

for L in lights where isProperty L #includelist do ...

My preference would also be to iterate the array directly (readability is the biggest point here), i.e. , for obj in L.includelist do print obj.name instead of _incl = L.includelist; for j = 1 to _incl.count do print _incl[j].name.

0 Likes
Message 6 of 11

Anonymous
Not applicable

Ah yes, I didn't think of that! So each light by default has an include/exclude list even if it's empty, so it still has an array even if it's empty. Makes perfect sense, thank you so much Steve.

 

What a great forum.

0 Likes
Message 7 of 11

Anonymous
Not applicable

Swordslayer, thank you, I will definitely study your suggestion. I'm a bit confused though; I filtered the list for targets because I kept getting an error when I ran the for loop for lights.

 

I didn't expect targets to show up in the findings either, but once I filtered for them the error went away. So I don't quite understand that part.

 

Your suggestion will be really good for me to study. Thanks very much!

0 Likes
Message 8 of 11

Swordslayer
Advisor
Advisor

Interesting - you're right, targets are included, too. Eitherway, since they don't have the includelist property, they are still eliminated this way.

0 Likes
Message 9 of 11

Anonymous
Not applicable

swordslayer, the readbility fix is perfect. thank you. It looks like I still need to filter for targets though. Perhaps I'm missing something?   Thanks very much.

0 Likes
Message 10 of 11

Anonymous
Not applicable

Yes they are. I incorporated both yours and Steve Curley's suggestions into the script and it seems fine now.

 

Problem is I tried it on a big file and I'm getting an error at the end. I'm going to try and get to the bottom of it and I might have to come back for more advice....probably shouldn't have designated those answers as solutions until I tested it more....sorry. 😞

 

0 Likes
Message 11 of 11

Anonymous
Not applicable
Even more interesting: it throws an error if I load vray light lister...so the prob might not be in this script. Troubleshooting...
0 Likes