getFaceMatID wrong return value


The max Documentations says about getFaceMatID: “Returns the indexed face’s material ID as an integer”. But if I do something like this, geting really wired results:

convert to editable_mes b
for i=1 to b.numfaces do format “%\n” getFaceMatID b i

I would expect 8 lines of 1, but that not the case, instead there are values from 1 to 6, so it looks like I am geting box plane IDs instead material IDs.


This code:

	converttoMesh b
	for i=1 to b.numfaces do format "% \n" (getFaceMatID b i)

prints in the listener this:


The box converted to mesh have 12 faces, not 8. If you check the MatId(in the command panel) of each face you will see that there is no 1,1,1,1,1… to expect.


you should name this topic “Box Material IDs. My wrong expectation” :wink:


You would be very lucky if you could get that piece of code running without throwing any error.

However, using the correct code (as miauu showed), why would you expect to have 8 lines of 1?

I mean, how did you come to that conclusion?

BTW, it would be good if you start enclosing your code (script) in code tags so it is properly formatted here in the forum. Just need to put [/code] at the end of your script and [code] in the begining.


I expected 1, because the documentation says so. Posibly I misunderstood something in the documentation, but if it said the function should return the material ID of a mesh with a single material, 1 is the value I expecting.
Is that problem only limited to box meshes?
I wrote my code looks something like this, which not meaning exactly like this, I was writing it from memory so some typing mistakes can hapen. My code looks exactly like the one by miauu and I am geting the same output. Also I meaned 12 lines, not 8, an other stupied typing error from me. I am also really new to maxscript and my english is terible.


Alright, that explains everything.

Regarding the Material ID of a face and the object material, you may be mixing up some concepts.

The Material ID of a face is an internal flag (a hidden value independent of the object material) that tells the face which material to use in case the object has a multi-material assigned to it. If the object does not have a material, each face can still have a Mat ID assigned to them. If you assign a single material, the whole object will use that material regardless of the Mat ID each face has, but as soon as you assign a multi-material to that object, each face will render with the matching Material ID (If they exist).

If you have a default box (which has 6 Material IDs) and you assign a multi-material with only 2 materials, only those 2 materials will be shown, and the faces will cycle the Material IDs they use from the multi-material (not sure how clear this is, sorry) :confused:

Also to consider is that when creating a default geometry they usually do not have any material assigned to them, but most usually have their faces Mat IDs assigned (this is a decision of the developer to implement). In the case of the Box(), the developer decided to assign a different material to each side of the box, but it could have only one Mat ID.


Also having the same problem with cylinder, cone, tube, sphere and geosphere. Even after asigning a standard material to the box or any other of the mentioned objects converted to mesh, I am still geting that material ID values. Is there a way to get the real material IDs?


The face Mat ID is independent of the material applied to the object. Applying any material to an object will NOT change the Material ID flag of the faces. They are two independent things.

The Face Mat ID is just an internal value that tells the renderer which material ID to use in case the object has a multi-material. To change the Face Mat ID you need to use the proper methods available for that, for instance for Meshes it would be setFaceMatID().

However, if an object has faces with different Mat IDs, and you assign a single material to it, the render will use that single material for all the faces, meaning the object will look as it has only one material, because it actually has one material, but the internal Faces Mat IDs will not be modified. If later you assign a multi-material to that same object, you will see that each face with different Mat ID will render the matching multi-material ID.


But I just need to get the real material IDs, the rendering plays here no role. For standard meshes I have no problem, but some objects which are converted to meshes have that problem. Unfortunatelly there is no way to find out if the mesh was one of that objects befor.


Did you have any experience working as an artist in 3DS MAX? It looks like you don’t understand the basic of 3DS MAX mesh… read the help first:


Well, that is, at best, frustrating. I am really disappointed with myself for not being clear enough, because in the end it looks like it was a complete waste of time.

I already recommended you to read the documentation to understand how meshes work. The solution for what you seems to need is in this Thread (if I understand correctly what you need). If not, it is most probably in another Thread in this forum.

If you don’t feel comfortable with the English level you have, I suggest you to expend some time learning it. If it is a barrier for you, then you must break that barrier if you want to make any progress. I can assure you that among all the things you will have to learn in the “Programming World”, English is by far the easiest one.

BTW, which is your native language? Aren’t there any 3ds Max book, tutorial, video, etc. in your language or in a language you feel comfortable with?


My native language is russian but I was not able to find any information about maxscript in my or any other language I know.
I didn´t wanted to go to much in detail about what I want to do, as with my bad english it dificult to explain and could cause some misunderstandings. However I try, have a script that should export meshes in a format they can be used by the gameengine. I am not only exporting the geometry but the coresponding materials, so I need to know which materials are used, this was done by runing through all faces of a mesh and cheking the corresponding material IDs. So when material ID i was present material i was exported.


Mate, it isn’t true about the absense of information in russian.
There’re several places where you could ask a question, really.,,

These aren’t nearly as great as this forum section but saying that there’s no info is available is really strange… :open_mouth:


Man, I thought your language was Sumerian. But Russian!!?? There are plenty of information in Russian, and a huge 3ds Max community.

Many Russian fellows in this forum, or at least that do speak Russian.


Yes about 3ds Max there are many sorces in russian and they were really helpfull to worck with 3D models in max. I am not a 3D artist, just doing small editing or remodeling worck on already existing models. Unfortunately the import and export scripts for that models were bugy as hell, so I had to start worcking on my own proper ones. Searching for information about maxscript programming in russian was not really succesful, but posibly I am just to stupied to use google or yandex.

@Serejah: Thanks for the links, have not found information about maxscript there till now, but like mentioned, posibly I am just to stupied. However I try to search beter.

Many thanks people.


Ugh, aside from the aforementioned forums there’s really lots of info everywhere, like MXS Theory or MAXScript | VK (you can find stuff like this there) for example… Besides, there’re people around with worse English level than yours that use the MAXScript reference without issues, it’s pretty approachable.


That´s really great man, THANKS A LOT. Now it´s oficial, I am just to stupied for searching.