如果您想查找所有现有材料(在场景中或不在场景中),以下代码片段将为您完成
for aMtlType in material.classes do
(
for aMtl in (getClassInstances aMtlType processAllAnimatables:true) do
(
print aMtl
-- Does this material exist in the scene or not?
if (findItem sceneMaterials aMtl) == 0 do (print "This material does not exist in the scene")
)
)
我不太确定如何从现场清除它。您可以获取依赖项(refs.dependents aMtl),然后将对此材料的任何引用替换为新的默认材料。这应该可行,尽管我还没有尝试过(甚至没有尝试过运行它)。所以...好好测试一下并小心使用:-)。
defMtl = ...
for d in refs.dependents aMtl do (
refIdx = 0
for i = 1 to refs.getNumRefs d do ( if (refs.getreference d i) == aMtl ) do ( refIdx = i )
refs.replaceReference aMtl refIdx defMtl
)
对于您的第二个问题 - 检查属性 - 您可以检查它是否具有适当的属性并根据需要设置值
if (hasProperty aMtl "diffuse") 做 (aMtl.diffuse = 0)