Trouble with array functions...


#1

I have a float[] array containing keyframe numbers. {1,5,5}

I want to:

  1. append more floats into that array (3) —> {1,5,5,3)
  2. remove duplicates {1,5,3}
  3. sort them {1,3,5}
  4. find (match) a specific item in the array list (5) —> found
  5. retrieve the match’s index number in that array (5)'s index = 2

I know MEL has a lot of array functions that could be useful to me (appendStringArray, stringArrayRemoveDuplicates, sort, etc) but most of them are made for string arrays, not float arrays…

What’s the easiest way to do this? Should I use Python instead? Or should I try to find a way to convert this float array into a string array…?

Thanks for your help.


#2

Never mind, I was looking at the old Maya 2010 documentation.
It seems like they added a bunch of floatArray functions. Thanks!


#3

My short answer is “probably”. I can give you a longer answer if you explain why you are using mel.

David


#4

like djx has said you are likely going to be much better off in python, pythons collections types are much more flexible than mels arrays.

Also python has the "set" collection type which does not allow duplicates in the first place, than for ordering you can cast to a list and use the sorting method available to lists
float_set = {1, 5, 5} # Create Set
float_set = float_set | {1, 5, 5, 3} # Get Union set with new values
sorted_list = sorted(float_set) # convert set to a sorted List

print sorted_list
print sorted_list.index(5) # get the index of the list element that contians5