[Closed] Removing XRef Materials from scene
heyhey,
i am prototyping a little tool for XRefing .max files.
i wrote a little function that localizes the Texturemaps fileNames (as i keep them local to the .max file location) after the XRef
here the material localisation function:
fn localizeXRef_Mat XRef_Obj =
(
for XR in XRef_Obj do --looop through all XRef Objs
(
local mat = XR.material.GetSrcItem resolveNested:true
if hasProperty mat "materialList" then --mat is MultiMat
(
for m in mat.materialList do --loop through all subMaterials
(
for map in m.maps where map != undefined AND classOf map == Bitmaptexture do --loop through all textureMaps of current material
(
local n = map.fileName
if not doesFileExist n do
(
local p = getFilenamePath XR.material.srcFileName --get XRef path
map.fileName = p + n --mix with fileName and assign to TextureMap
)
)-- end Maps loop
)--end subMTL loop
)
else --Single Mat
(
for map in mat.maps where map != undefined AND classOf map == Bitmaptexture do --loop through all textureMaps of current material
(
local n = map.fileName
if not doesFileExist n do
(
local p = getFilenamePath XR.material.srcFileName --get XRef path
map.fileName = p + n --mix with fileName and assign to TextureMap
)
)-- end Maps loop
)
for m in scenematerials where m == XR.material do
(
-- ??? remove the XRef Material ???
)
XR.material = mat --assign localized material to current obj
) -- end XRef OBJs loop
)
my problem is: how can i get rid of the initial XRef material from my sceneMaterials, cuz it allways drops me an error about the missing textureFiles (wich r not missing in the localized material)
ive looked for some hours now but i cant seem to find a way to remove/reset/whatever the initial materials 0.O
thx in advance
-Insanto
I would avoid using scenematerials as much as possible, as it keeps deleted materials in there and so it always breaks
Maybe you can collect them with a function like so:
fn GetScenematerials =
(
MySceneMaterials = #()
for i in material.classes do for j in (getclassinstances i) do append MySceneMaterials j
MySceneMaterials
)
mymats = GetScenematerials()
its ok i found a way
for m= 1 to scenematerials.count where scenematerials[m] == XR.material do
(
deleteItem scenematerials m -- remove the XRef Material
)
i didnt need to use the sceneMaterials, just remove one XRef item from them so i could get rid of the errorMSGs