I'm trying to write some simple UV tools, but I'm running up against some oddities with arrays. I'm no MaxScript expert, so I'm probably doing something wrong somewhere.
I'd started off with trying to find out the UV coords of the selected vertices in the Edit window of an Unwrap UVW modifier. The code is;
selVerts = $.modifiers[#unwrap_uvw].unwrap.getSelectedVertices()
numVerts = selVerts.count
for i = 1 to numVerts do (
vertPos = $.modifiers[#unwrap_uvw].unwrap.getVertexPosition currenttime selVerts[i]
[...there's other stuff here, but the script's breaks at the above line...]
)
And the results I get in the Maxscript listener don't seem to make sense;
selVerts gets the correct array of vertex IDs. So far I've just been selecting 2 verts, so I get 2 values in an array.
numVerts gives out the number of UV vertices there are in total, not the number of entries in my array (currently I'm just using a cube so it endsup being 24).
selVerts
just ends up false and then the script dies.
Any ideas as to what's going on?
Replies
selVerts = $.modifiers[#unwrap_uvw].unwrap.getSelectedVertices() as array
Feel free to delete this thread, sorry :P
The behaviour you get is correct. The function getSelectedVertices() returns a bitarray. This means a bit can be turned "on" or "off", 1 or 0, true or false.
The documentation says this:
BitArray Values
Edit: Damn, i should have thought of that, The C++ programmer in me says this is all kinds of weird though :P
Thanks for your help, though
Maybe you mean something else but then Rob will have to enlighten us :poly121:
When you tell it as array it magically converts the bit to an int, that is obviously very strange because why would you have a bitarray anyway if it holds integers? I bet something goes on there behind the screens. If someone can explain this, please do
As array produces 1 to 24 in this case.
These bitarrays are mostly for use with other functions which take them as parameters for operations on collections of vertices, but this you know.
And some methods in maxscript require bit arrays as parameters like when passing over a selection to transform and so on.
for bit arrays you can use:
Got my UV align scripts working. Now I just have to figure out how to stuff it into the interface :P
because either way I could implement it for you. I designed the GUI in a way that all scripts are seperate *.ms files with a single function in them.
The main script that builds the floater then loads the function and calls it from one of the buttons.
Maybe PM me again about what it is exactly is- if I perhaps can include it in the next release?