Home Technical Talk

[Maxscript] Get the selection order of selected vertices?

I'm trying to write a few little tools for Max now that I'm having to use it properly, some of the more simple bits from the long list of features I miss from modo.

I figured I'd start small and easy and go for modo's weld verts and make poly tools, they rely on selecting vertices in a certain order (weld all selected verts to the last selected vert's position / vertex winding order for make polygon) then firing a command.

But querying the verts I've got selected ends up giving me them in numerical order, not their selected order... Does Max hide that information away somewhere else or does it just flat out not store it?

* I should probably note that I'm a total newbie to Maxscript, so this might be really easy to do, but I've tried looking through google and the help docs to no avail.

Replies

  • AnimeAngel
    Options
    Offline / Send Message
    Well I have never seen max keep anything on the order in which you selected it. Maya can and I was hoping that they would incorporate something like that in max but to date I have not seen anything.
  • Rob Galanakis
    Options
    Offline / Send Message
    Max stores selected verts as a bitarray. The only way to get the order of verts selected would be to store them as you select them yourself.

    Max has its problems but this makes sense- ordering your vert collection should be left to you.
  • Farfarer
    Options
    Offline / Send Message
    I was afraid that'd be the answer :P

    Still pretty annoying, modo and I'm pretty sure Maya both do that automatically. Ordering your vert collection numerically should be left to you, imo, as that's a far easier task than having to work out the selection order yourself without any help from the app.

    Storing them as I select them myself sounds like I'd have to activate a tool (my script), then do my selections and then perform the actions I want on them on deactivating the tool? If so then that defeats the purpose of the tools being faster than Max's own.

    I'll have another look at how to go about this, then.
  • Funky Bunnies
    Options
    Offline / Send Message
    Funky Bunnies polycounter lvl 17
    for the record, Maya doesn't order your component selection either. I think there are a few hacks, but by default it'll group them by ID because it's smaller. Traversing through a bunch of individual selected components would make the script slower than necessary in most cases. Just as in max, you have to manually do it if you need it.

    out of curiosity, what are you trying to do?
  • Michael Knubben
    Options
    Offline / Send Message
    Funky Bunnies:
    weld all selected verts to the last selected vert's position / vertex winding order for make polygon

    That's pretty interesting, actually. I was under the impression Silo did this by default, and took a mental note to make more use of it, but apparantly I was wrong. It merges the second selected vert to the first, but it won't merge when you select more than two. I think I'll start a feature request for that, as it could be useful in a lot of cases, so thanks for the suggestion :D

    Please post the script if you get it working, as well.
  • Rob Galanakis
    Options
    Offline / Send Message
    You could cast a ray from the mouse position (there's a function creating that ray, and use intersectrayex to get the hit point on the mesh), get the closest vert (do a raymeshgridintersect at the intersection point and get the closest vert), and merge all selected verts to that vert.

    It would be an excellent script if you are interested in learning MXS, would introduce some very important techniques without requiring much/any math (and you'd just need to search CGTalk for tons of references on how to do each of these things)... if not, I can probably whip something up if there's not a better way for this.
  • CrazyButcher
    Options
    Offline / Send Message
    CrazyButcher polycounter lvl 18
    I think a selection notifier/callback, that you activate and then track changes to selection made by max itself is the more conveniant way to go. That way users can still use all the standard max selection mechanisms (rectangle, click...)
  • Farfarer
    Options
    Offline / Send Message
    MightyPea: Yeah, it's pretty damn handy. Especially as it's done at the lowest level (while you're selecting elements) rather than having to activate a tool (like Max's Target Weld). I'll post it up if I get anywhere. No guarantees at this point, I'm just looking to dick about in Maxscript to get the hang of it.

    Cheers for the heads up, Rob, I'll look into that. I was just about to look if a method like you describe was possible - apparently it is.

    I'll have a play around with both suggested routes, can't hurt :)
  • CrazyButcher
    Options
    Offline / Send Message
    CrazyButcher polycounter lvl 18
    when going the manual intersect ray route, keep in mind that you will need discard hidden faces manually and launch rays from nodged last hit, until you either it something visible or nothing at all
  • Michael Knubben
    Options
    Offline / Send Message
    Talon: yeah, that's what I prefer too. Having tools work on selections is a powerful thing, much more so than having to call a tool before you get to set what it works on. I swear, if Max could just steal from Silo wholesale, I would be a much happier man.
Sign In or Register to comment.