[Closed] .mesh Material ID?
Hi
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.
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: %
" obj.name (classOf obj)
In this way you can know exactly what kind of objects are those selected, in particular:
[ul]
[li]Editable Polys are ‘Editable_Poly’
[/li][li]Objects with an active Edit Poly Modifier are ‘PolyMeshObject’
[/li][li]Editable Meshes and objects with an active Edit Mesh Modifier are ‘Editable_Mesh’
[/li][/ul]
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
Cases never heard of them many thanks!..so 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 types…so 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!
Alan