PDA

View Full Version : Looping/Array Help


ColMatrix
04-20-2009, 12:06 PM
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:

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

Many thanks

Col

floopyb
04-21-2009, 06:57 AM
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 makeUniqueArray() on the array (AVG or Max 2008+ only)

ColMatrix
04-21-2009, 07:42 AM
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
04-21-2009, 08:33 AM
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

ColMatrix
04-21-2009, 10:54 AM
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

ColMatrix
04-21-2009, 04:38 PM
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

CGTalk Moderation
04-21-2009, 04:38 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.