Notifications
Clear all

[Closed] Maxscript: reading or modifying "default" material

Hi!

I’m doing a script that dumps a CSV of every object in a scene with their applied materials (using the .mat.name property of each object). However, if there is an object with no material applied (IE when you create any object and you can change just the color in its properties), when scanning the whole list of objects and error occurs and maxscript stops…

Is there any way to know if an object has this “default material”? Any means of identifying it, or skipping it… what ever I have to do to differentiate it from the other objects at least :P?

Thanks!

3 Replies
1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

Yep, there is no default material as such, the property is set to ‘undefined’, so you can catch it by comparing to that.

For example:

for o in objects do format "Object:% Material:%
" o.name (if o.material == undefined then "NoMaterial" else o.material.name)

Hi,

When an object doesn’t have any material assigned to it (the situation you’re havng) it’s .material property will return undefined, and therefore will not have a name property. That’s probably why you get the error.
To avoid this do a test, e.g. if obj.material != undefined then (do whatever…)

hOpe this helps,
o

EDIT: Damn Bobo, you’re fast

Ohhh! Thank you both!

I’ll test it on monday since the script is on my work’s comp

Thx again!