View Full Version : .mesh Material ID?

04 April 2009, 03:06 PM

I am in the process of creating a script which returns the ammount of material ID's in a editable_Poly, a friend mentioned I should try to find it for the .mesh which should be available. Currently my script wont work on an editable mesh, I could do an 'if expression' to check if the selection is one or the other then execute the relevant script - this i may do as I am new and would be worthwhile...

But currently I am going to learn more about this '.mesh/trimesh' and if i can access material ID's at this level I will not have to generate 2 seperate bits of code and to my understanding should be more...universal i think is the best way to put it.

I have looked in the Maxscript help (.mesh, trimesh, meshops) and I have not found anything.

Can anyone offer any guidance/recommendations or whether this cant be done?

Thanks for your help.

04 April 2009, 09:34 PM
Hi Alan,
as you found out, polys and meshes have different methods to be accessed and modified. First you can check what you're working on by quering the classes of the currently selected objects:

for obj in selection do
format "Class of % is: %\n" (classOf obj)
In this way you can know exactly what kind of objects are those selected, in particular:

Editable Polys are 'Editable_Poly'
Objects with an active Edit Poly Modifier are 'PolyMeshObject'
Editable Meshes and objects with an active Edit Mesh Modifier are 'Editable_Mesh'

To get the material ID of these different object types you need their own methods:

-- for 'Editable_Poly' and 'PolyMeshObject' use:
matID = obj.getFaceMaterial faceIndex
-- or the equivalent
matID = polyOp.getFaceMatID obj faceIndex

-- for 'Editable_Mesh' use:
matID = getFaceMatID obj faceIndex
To make your script work with all object types you can specify the code with 'if' / 'else if', or a 'case':

case (classOf obj) of
-- Editable Poly
Editable_Poly: matID = obj.getFaceMaterial faceIndex

-- Edit Poly Modifier
PolyMeshObject: matID = obj.getFaceMaterial faceIndex

-- Editable Mesh or Edit Mesh Modifier
Editable_Mesh: matID = getFaceMatID obj faceIndex
- Enrico

04 April 2009, 10:07 PM
Cases never heard of them many thanks! to make sure i understand correctly, instead of having 3 different scripts for each type...I can use these 3 lines and that covers all bases of the different whichever one of the 3 is currently the Class of the selected will be used.

Superb, will check out 'case' in the index and give it a try. Thanks a lot!


CGTalk Moderation
04 April 2009, 10:07 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.