Running a fn on classes of objects that only have a material?

Running a fn on classes of objects that only have a material?

Anonymous
Not applicable
1,219 Views
12 Replies
Message 1 of 13

Running a fn on classes of objects that only have a material?

Anonymous
Not applicable

Hi,

I have a script that applies a material wrapper to all materials in a selection set so I can apply a matte to multiple objects. Works well.... but if a light or camera is in the selection it goes haywire.

 

I have tried using if ==classof to sort out objects but cant work out how  only to use objects with a material attribute applied? I have included where selection[i].material!=undefined but that does not do what i need

 

Can anyone point me in the right direction?

 

a snippet is of the code as it stands now is:

 


MatBank=for i in 1 to selection.count where selection[i].material!=undefined collect selection[i].material

mySlot=MatBank.count
for i=1 to mySlot do
(

--apply the material wrapper etc

)

 

 

Thanks for any leads

Mike

0 Likes
Accepted solutions (1)
1,220 Views
12 Replies
Replies (12)
Message 2 of 13

miauuuu
Collaborator
Collaborator

Something like this.

 

MatBank = for i in 1 to selection.count \
		where (selection[i].material!=undefined) \
			and superclassof o != light \
				and superclassof o != camera \
					and classof o != Targetobject collect selection[i].material

 

https://miauu-maxscript.com/
0 Likes
Message 3 of 13

Anonymous
Not applicable

Hi thanks for the snippet,

I think I am getting closer but I have some fundamental gaps in my knowledge

 

1st really simple one that will highlight how little I know about using loops

should not the o in below by i?

superclassof o != light

second issue I having is if the loop selects a group it goes haywire

 

I have tried using the filter only to pickup the superclass of GeometryClass but it does not work

MatBank = for i in 1 to selection.count  where (selection[i].material!=undefined)  and superclassof i == GeometryClass collect selection[i].material

 

but it still selects the group ?

 

any help out there?

 

thanks

Mike

 

 

0 Likes
Message 4 of 13

miauuuu
Collaborator
Collaborator

You have one error in your code. Here the correct syntax:

 

MatBank = for i in 1 to selection.count  where (selection[i].material!=undefined)  and superclassof selection[i] == GeometryClass collect selection[i].material

 I am sure that you can find the error.

 

About the FOR loops and the difference between for o in objects do an for i = 1 to objects.count do, please read in maxscript help file the topic of

For Loop By Index Vs For Loop Through Collection Performance

 

https://miauu-maxscript.com/
0 Likes
Message 5 of 13

Anonymous
Not applicable

Thanks ..I can see the syntax needs the superclass of the slection array not the loop iteration number itself

 

apreciate your time. 

 

cheers

 

Mike

0 Likes
Message 6 of 13

Anonymous
Not applicable

Hi me agian,

code works well generally but the following code selects an open group dummy even though it is not of a superclass of Geometry?

 

MatBank = for i in 1 to selection.count  where (selection[i].material!=undefined)  and superclassof selection[i] == GeometryClass collect selection[i].material

 

How can this be?

0 Likes
Message 7 of 13

miauuuu
Collaborator
Collaborator

I don't have this problem.

Useing this

 

collect selection[i].name

 

the script collects the names of the objects(open group with 4 spheres I used in my test) and the dummy is not in the collected objects.

 

Can you attach the scene and the exact code that you use?

 

By the way, the superclass of the group dummy is HELPER. Create an group, open it, type this in the listener and execute it

 

superclassof $Group001

 

I assume that the name of the group is Group001, and the result should and will be

helper

 

https://miauu-maxscript.com/
0 Likes
Message 8 of 13

Anonymous
Not applicable
Hi

This is the complete script

It is a Vray script so I can easily apply a wrapper material for Mattes





I would be interested inyour thoughts

It works well but I still need to write the code to open all groups select
all objects then close all groups but not select the helper or dummy of the
group



cheers






Mike Nowson


Ph. 0410 527 366









cid:image001.gif@01CE3C38.4CBD1BA0






Melbourne

Geelong

3idstudios.com.au

miken@3idstudios.com.au


PO Box 73,

Shop 6,79 Ryrie St

Ph. 1 300 55 33 69

Animation


North Carlton,

Geelong, Vic.

Ph. (03) 52 219 420

3D Visualisation


3054.

3220.

ABN 61640261424

3D Data simulation
0 Likes
Message 9 of 13

miauuuu
Collaborator
Collaborator

I can't find the script in your post(no links or etc.). Also, it is good idea to upload sample scene, because the problem may be in the scene, not in the script.

Why you need to open groups, then to close them?

https://miauu-maxscript.com/
0 Likes
Message 10 of 13

Anonymous
Not applicable

Hi,

sorry on the attachment I just replied to the email but by the looks of it it does not auto-attach the attachmet to the post

The file is attached, as is a max file

 

I have put a hide selected in the loop so I can see what is being modified

Group 3 hangs the process when open 

 

as allways there is probably a very simple explanation?

 

 

The more I think about it a better way would be just to change the Vray property rather than going through applying a Material Wrapper....... but I am that close I am going to finish this script.

 

cheers

 

 

0 Likes
Message 11 of 13

miauuuu
Collaborator
Collaborator

Hi!

The problem with your script is the... Download the attachment and check my comments.

If you can understand my explenations, because my english is not very good, I can try to explain again why your code not works properly.

🙂

https://miauu-maxscript.com/
Message 12 of 13

Anonymous
Not applicable

Hi I suspected that the 2 array values were different.

I need to sit down and spend some time and pull the script apart.

 

I am most grateful for your time and efforts

 

Thanks

Mike

0 Likes
Message 13 of 13

miauuuu
Collaborator
Collaborator
Accepted solution

Glad to help.

🙂

https://miauu-maxscript.com/
0 Likes