Home Technical Talk

MaxScript Issues (arrays?)

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

  • Farfarer
    Options
    Offline / Send Message
    Aha, nevermind. Googled the answer by accident. It appears I needed "as array" at the end of the first line, so;

    selVerts = $.modifiers[#unwrap_uvw].unwrap.getSelectedVertices() as array



    Feel free to delete this thread, sorry :P
  • jerry
    Options
    Offline / Send Message
    Ok i figured it out.

    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
    Operators
    <bitarray>[<integer>]
    Yields true if selected, else false

    You will have to search another function or figure out how to make it work with this setup, i can't help you there because i haven't written any unwrap scripts.

    Edit: Damn, i should have thought of that, The C++ programmer in me says this is all kinds of weird though :P
  • Farfarer
    Options
    Offline / Send Message
    The anything programmer in me says this is all kinds of weird, heheh.

    Thanks for your help, though :)
  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    You can actually do a "for" in a bitarray I believe, but it's a different syntax (Rob Galanakis told me how once, can't remember offhand though)... personally I prefer using arrays since they're more familiar, but I think it's probably a little faster / more efficient to keep it as a bitarray.
  • jerry
    Options
    Offline / Send Message
    This example actually iterates over the bitarray fine. When you print its contents of a selected box uv, you get true or false 24 times.

    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.
  • renderhjs
    Options
    Offline / Send Message
    renderhjs sublime tool
    bit array is though a lot faster - and if you are once familiar with them they can improve the performance.
    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:
    for v in myBitarray do(
    print("element: "+v as string);
    )
    
  • Farfarer
    Options
    Offline / Send Message
    Yeh, I figured it out in the end, cheers guys. I was just confused as to what it was doing as the Maxscript listener displays it as a regular array with the vertex IDs, so I thought that's what I was getting.

    Got my UV align scripts working. Now I just have to figure out how to stuff it into the interface :P
  • renderhjs
    Options
    Offline / Send Message
    renderhjs sublime tool
    got your PM, is it something you want to contribute or is it more personal?
    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?
Sign In or Register to comment.