Home Technical Talk

Maxscript/Macro help?

MoP
polycounter lvl 18
Offline / Send Message
MoP polycounter lvl 18
Hey folks, I know a fair few of you are knowledgeable when it comes to Maxscript stuff... I've been dabbling with a little bit of it just to make some little macroscripts to bind to hotkeys now and then.


Right now I'm doing some highpoly stuff, and I've noticed some annoyances about Max for this - if I'm modelling in halves, with an instanced mirror, I can bind a hotkey to toggle NURMS smoothing on the EPoly, so I can swap quickly between the control mesh and high-poly smoothed version.

However, this method means that the two objects aren't connected, so I get a big nasty seam down the middle which is even more evident when toggling the smoothing on.


An alternate method is to have a Symmetry then a Turbosmooth modifier on top of the EPoly in the stack, and having a hotkey to toggle Show End Result on or off.

However, this means that whenever I deselect and re-select the object, it goes straight to the top of the stack, instead of to the EPoly, so it takes more time to go back to easily edit it. Also, it means when I'm working on the low-poly cage, I either have no mirrored copy (Show End Result off), or the annoying orange cage is there and slowing things down (Show End Result on).


I was trying to write a script that would, when activated by a hotkey, take the selected EPoly object and it's instanced mirror, delete/hide the instanced version, add a Symmetry and Turbosmooth modifier to get an accurate high-poly preview, then when the hotkey is pressed again, remove the Symmetry and Turbosmooth modifiers, and recreate/unhide the instance mirror of the object.

I'm guessing this would be a lot faster than any current method (that I know of! If you guys have better workflows for this, please tell me!), and give an accurate high-poly preview, while still having a nicely editable and viewable low-poly cage.


I did find Borislav Petrov's "BaseJump" script which makes the stack go straight to the EPoly object instead of either the Turbosmooth or Symmetry modifier, but this still leaves me with only half a model. At the moment, this potential script I have in mind would solve all my worries, and probably work just as quickly.


Basically what I want to learn now is how to make a macroscript togglable, bound to the same hotkey... I'm guessing I'd use a Case/Of or If expression?

I've got it working so that it can add and delete the modifiers on a keypress, but not the same one... I'm really a coding newbie, but I'm sure it'd be useful to learn, and reading the Maxscript help is sending my head spinning, it has example code but hardly explains it... I'm also finding it hard to locate any good tutorials online. confused.gif

Damn, that was a long post. Any help would be greatly appreciated! blush.gif

If anyone has any better ideas/plugins/scripts or workflow ideas to get a similar effect to the one I'm after with this, please let me know!

Thanks,
MoP

Replies

  • Eric Chadwick
    Options
    Offline / Send Message
    How about copying the model as a Reference, then applying the Symmetry/Turbo on that? Put it in another viewport even. I dunno, an idea maybe.
  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    Yeah, thanks for the suggestion! I had considered that, but it's a tad unwieldy, and I'd much prefer just to have one large Perspective viewport open, rather than two (or have to keep switching camera/viewport).

    I guess I'll just have to slog on with this scripting stuff smile.gif
  • Eric Chadwick
  • FatAssasin
    Options
    Offline / Send Message
    FatAssasin polycounter lvl 18
    If you want to test if a certain modifier is present, you can use the name of the modifier as it appears in the stack. Something like this:

    <font class="small">Code:</font><hr /><pre>if $.modifiers[#Turbosmooth] != undefined then deleteModifier $.modifiers[#Turbosmooth] else addModifier $ (turbosmooth())</pre><hr />
    If the modifier name has a space in it, convert it to an underscore... '[#Edit_Mesh]'. The '[#Turbosmooth]' part is the text name of the modifier in the stack, which can change if you manually, or through scripting, rename it. And the '(turbosmooth())' part is the maxScript name for the new modifier. Use the listener to get the correct syntax if you don't know it because sometimes it's not the same as what you see in the modifier list.

    You can also rename the modifier upon creation so that you're sure to delete the correct one if there are more than one on the stack. So the end of the line I wrote above would be...

    <font class="small">Code:</font><hr /><pre>else (
    tMod = turbosmooth()
    addModifier $ tMod
    tMod.name = "myTurbosmooth"
    )
    </pre><hr />
    And then change the begining part to match the new name when you're doing your check.

    Hope that helps with the toggling part at least.
  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    Ah, nice stuff guys!

    FatAssasin: Yeah, that's pretty much what I was looking for with the toggling thing... thanks! I'll see what I can come up with, in regards to the rest of it smile.gif

    Is it just me who finds the Maxscript help kind of... impenetrable? Or maybe that's just because I don't know enough about scripting yet...
  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    Hmm, this is odd... it works in that, if the modifiers already exist, it won't add a new set of them on top... but also, it won't delete either the Symmetry or the TurboSmooth modifiers.

    When I evaluate the script at the moment, it works "forwards" (adding the modifiers) no problem... but "backwards", it gives me this:

    <font class="small">Code:</font><hr /><pre>
    -- No ""deleteModifier"" function for TurboSmooth:TurboSmooth
    </pre><hr />

    I can't seem to figure it out... maybe I'm missing something obvious that I'm unaware of?

    Any help would be greatly appreciated.

    MoP
  • FatAssasin
    Options
    Offline / Send Message
    FatAssasin polycounter lvl 18
    Yeah, the maxScript reference is not for the faint of heart. I'm getting better at decifering it, but sometimes I still don't know what the hell it's trying to say. It's getting better though as Bobo has been adding more examples and better explanations of certain concepts.

    The Discreet webboard is a really good place to go for help though because a lot of really good scripters frequently answer questions there. And a lot of times Bobo expands on what's in the reference and explains things much more clearly.

    About the deleteModifier issue, I should have tested what I wrote, but it sounded good when I wrote it. smile.gif

    This works:

    <font class="small">Code:</font><hr /><pre>if $.modifiers[#Turbosmooth] != undefined then deleteModifier $ $.modifiers[#Turbosmooth] else addModifier $ (turbosmooth())</pre><hr />

    Overall, a better way to write it would be:

    <font class="small">Code:</font><hr /><pre>obj = selection[1]
    if obj != undefined then (
    tMod = obj.modifiers[#Turbosmooth]
    if tMod != undefined then deleteModifier obj tMod else addModifier obj (turbosmooth())
    )</pre><hr />

    This way you have a couple checks in place so that you won't get unwanted error messages. Feel free to keep asking questions here, I'll help where I can. And if you want an explanation of why I wrote something a certain way, I'll explain in more detail.
  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    Thanks, that's a huge help.
    I think I'm pretty good at working out why/how code works if I've got a good example to go from (which the Maxscript help seems sorely lacking in), so I think with this basis, I should be able to go and write the full script I originally had in mind (the Symmetry/Turbosmooth adding/removing works perfectly now, I just need to add the instance mirroring/hiding thingy...).

    You rock, Mr. Haywood!
  • Eric Chadwick
    Options
    Offline / Send Message
    Hey MoP you could also try here for good intro tutorials.
    http://www.scriptspot.com/start.asp?page=tutorials
  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    Eric: Damn, I'm totally blind. I went over to Scriptspot a couple of days ago, looking for tutorials - I swear I looked over every single link on the navigation bars... and somehow missed the one in the very bottom right, which is exactly what I was looking for! Thanks! smile.gif
Sign In or Register to comment.