Notifications
Clear all

[Closed] Looping/Array Help

Hi

This is my frist post, and I am completely new to MaxScript. I watched a tutorials and started to play on my own whilst viewing further DVD’s.

I am wanting to return how many MTL ID’s are used on a selected Editable Poly object. So if the model has upto 5 MTL ID’s then the result will be 5.

I ‘think’ this is what has to be done:
[ol]
[li]Search each face in the editable poly
[/li][li]Put the result into an array.
[/li][li]Add any new MTL ID#’s currently not in the array.
[/li][li]If a returned MTL ID # is already in the Array move onto the next face.
[/li][li]After each face has been scanned, count how many entries are in the array (myArray[].count?)
[/li][/ol]I would appreciated some help in this I understand this is so simple.

Many thanks

Col

5 Replies

Yeah, thats about right. For every mat id you need to search your Array for that mat id and add it only if it dosent exist.
Alternatively you can use or use appendIfUnique() or just add all of them then run [b]makeUniqueArray/b on the array (AVG or Max 2008+ only)

Thank you – I have found the functions I think i need, I am mainly for the moment stuck on compiling the logic together…will it be a combination of If, If else statements combined with for loops…

Currently I cant get my head around what it requierd. I can create the for loops to reutrn faces etc…but to get a for loop to search each face for a MTL ID # and then add the value to an array – this is the first step I am currently finding difficult, I hope to manage ok with the rest.

Thanks

 JHN

This code asumes you have 1 object selected and it’s a editable poly:


 usedMatIDs = #() -- initial cleared array
 for i = 1 to $.numfaces do appendIfUnique usedMatIDs ($.GetFaceMaterial i) -- the loop
 sort usedMatIDs -- sort by number
 print usedMatIDs.count -- print number of unique mat Id's
 

-Johan

Thanks for the code snippet – i am looking forward to seeing the results…the code seems a lot more simplified than i imagined.

Thanks for the help.

Col

ok I had a little play will be having a more detailed test after dinner. I seen this in your script and I never seen it before and when searching maxscript reference I could not see it – the only one I know of is:

polyop.getNumFaces

Is ‘numfaces’ a shorthand version? –(Nevermind found it)

Why did u choose numfaces instead of polyop.getNumFaces

Also GetFaceMaterial is something I was looking for but never found it – i now have the reference thanks for this.

Col