I’m trying to write a script that exports a list of objects with their corresponding materials.
I’m stuck with the multi-sub object because
I have to determine the material ID of an object
And from the material ID go back to the multi-sub object and retrieve the actual material.
Is there a way I can get the material ID of an object?
Interestingly, the objects only uses one material from the multi sub object. So I don’t have to query all the polygons/component. Only one is needed.
As you might know, the help(object) doesn’t work in pymxs. Doesn’t have any help information.
I tried dir(object). It doesn’t list any method for the material ID. I’m also lost in the documentation.
Just check maxscript docs really and you can then shove pymxs.runtime in front of the calls generally
But anyways, you can try to cheat a bit and use EditableMesh like something in
where you use snapshotasmesh to get a list back.
Another “potentially” quick way I’ve done this in the past is to do something like (psuedo code as I don’t have max installed atm)
for mat_id in range(1, myMultiSub.numsubs + 1 ):
# try to select all faces using the mat id
pymxs.runtime.myEPoly.selectByMaterial(mat_id)
# then check to see if there is any actual faces selected
if not pymxs.runtime.polyop.getFaceSelection(myEpoly).isEmpty:
# if this gets here you know you "should" have at least one face on your model with a material on it
# so do what you want with it
Not that I think it’s super performant but it should be “quick enough” since you really just need to check how ever many mats are in your multisub…unless it’s massive for some reason