Can anyone make this more elegant/professional

Here’s my script so far. Can anyone make this more elegant/professional for me please? I think this will help alot of people who use wacoms in max. Also will be happy to credit anyone who helps with it in the script.

All for the community folks.

(

global selectionChanged

callbacks.removescripts #selectionSetChanged id:#myCallbackID

callbacks.addscript #selectionSetChanged "selectionChanged()" id:#myCallbackID

fn selectionChanged =

(

if not (isCreatingObject()) and not keyboard.shiftPressed do

max select

)

)

Replies

  • _thatmilkman
    bump
  • _thatmilkman
    Anyone?
  • ProperSquid
    Offline / Send Message
    ProperSquid polycounter lvl 8
    I'm not an expert with Maxscript, but what's happening here? What does this do to help Max users with Wacom tablets?
  • _thatmilkman
    When using a tablet it's so ridiculously easy to move an object by accident when trying to select it. This script makes sure you're always using the select object tool instead of move,rotate,scale. 

    It's the same as pressing Q. But automates it everytime you make a selection.
  • ProperSquid
    Offline / Send Message
    ProperSquid polycounter lvl 8
    That's pretty cool. From what I can see, the code looks pretty good (without knowing the language). If this was in Python, then I'd probably be able to give you better feedback.
  • _thatmilkman
    Thanks :) trust me it makes a huge difference when working in max now. I just wish someone who was an actual programmer could "finalize it" so it has no kinks and people can enjoy it. 
  • Revel
    Offline / Send Message
    Revel greentooth
    Interesting, yeah I had similar issue with the wacom selection, and usually I instinctively switch to mouse whenever I want to make a precise selection without accidentally bump the mesh. Thanks for sharing this!
  • poopipe
    Offline / Send Message
    poopipe ngon master
    tech artist rather than programmer ... 

    the only potentially, mildly scary bit (without refreshing my memory about maxscript's dirty bits) is that selectionChanged is a global .
    In this context I can't see it being a problem (it's probably required tbh)

    I expect @monster or @miauu can clarify whether it's going to be an issue or not
  • _thatmilkman
    Possibly. Honestly I have no idea, I've mashed this code together by doing a lot of googling and checking the mxs reference. It all seems to work but I bet it could be better. especially when working in sub object mode.
  • miauu
    Offline / Send Message
    miauu polycounter lvl 9
    Is this is the whole script?
    @poopipe is right, you have to change the name of your global variables to be not so "obvious" and "common". At least use something like this:
    global selectionChanged_adj34wrff


  • poopipe
    Offline / Send Message
    poopipe ngon master
    That's simply to reduce the risk of another script overwriting the variable so we're clear.

    As far as the rest of the script goes - if it works you're good. There's not really enough code there to provoke any bugs.

  • _thatmilkman
    Thank you @miauu and @poopipe appreciate the feedback and explanation :) will change the global name and see how it functions after. Hopefully that'll be all and anyone using a wacom can finally enjoy max 
  • _thatmilkman
    Right, im being more ambitious with this now....can anyone find any issues with this? trying to get it working now properly with sub object mode. Also can anyone explain why this means? "ev nd" i have no idea, i just followed the maxscript reference.

    Ideally test this out with a wacom :) but woks fine with a mouse too. 

    (
    Global selectionChanged_mod
    Global subObjChanged_mod
    callbacks.removescripts #selectionSetChanged id:#myCallbackID
    --print "script removed"
    callbacks.addscript #selectionSetChanged "selectionChanged_mod()" id:#myCallbackID
    --print "script added"
    fn selectionChanged_mod =
    (
    if not (isCreatingObject()) and not keyboard.shiftPressed do
    (
    max select
    print "selection changed"
    NodeEventCallback subobjectSelectionChanged: subObjChanged_mod
    print "fire subObjChanged_mod"
    )
    )
    fn subObjChanged_mod ev nd=
    (
    max select
    print "sub object changed"
    )

    )



  • _thatmilkman
    There's a bug i've found which ill try sort today, or if anyone else wants to have a crack at it :)
    If your in "attach" mode it bugs out and changes your selection type.
  • Tekoppar
    Offline / Send Message
    Tekoppar polycounter lvl 8
    (
        global callbackItem
        global lastSelectedObject
       
        fn toggleToolMode arg = (
            toolmode.commandmode = #SELECT
            toolmode.commandmode = arg
        )
       
        --ev returns the event that fired the callback
        --nd returns the node
        fn CallbackFnWacomFixSelection ev nd = (
           
            --stores the current selected object to compare with last object
            currentSelection = $
           
            --checks if current selection is an editable poly and if so gets the current
            --selection type and with that gets the current selected and gets it's index
            if ((classOf currentSelection as string) == "Editable_Poly") do (
                currentMeshSel = currentSelection.GetMeshSelLevel()
                if currentMeshSel != undefined and currentMeshSel != #Object do (
                    currentSelection = currentSelection.GetSelection(currentMeshSel) as array
                    currentSelection = currentSelection[1]
                )
            )
           
            if lastSelectedObject != currentSelection do (
                --first the store the current toolmode in a variable
                currentToolMode = toolmode.commandmode
           
                --if the current toolmode is select already we don't want to fire any unessecary code           
                --only #SELECT, #MOVE, #ROTATE, #NUSCALE, #USCALE and #SQUASH is supported when setting the toolmode
                --so for the rest we will simply ignore them
                case currentToolMode of (
                    #MOVE:toggleToolMode(currentToolMode)
                    #ROTATE:toggleToolMode(currentToolMode)
                    #NUSCALE:toggleToolMode(currentToolMode)
                    #USCALE:toggleToolMode(currentToolMode)
                    #SQUASH:toggleToolMode(currentToolMode)
                )
            )
           
            lastSelectedObject = currentSelection
        )
       
        fn registerCallbackFnWacom = (
            callbackItem = NodeEventCallback selectionChanged:CallbackFnWacomFixSelection subobjectSelectionChanged:CallbackFnWacomFixSelection
        )
       
        fn unregisterCallbackFnWacom = (
            --set callback to undefined and call garbage collector so it's destroyed
            --and it's memory is set free
            callbackItem = undefined
            gc light:true
        )
       
        rollout wacomSelectionFix "Wacom Fix"
        (
            checkbutton theButton "Enable script" checked:false tooltip:"Toggles the wacom selection fix"
            on theButton changed state do (
                if state == on then (
                    registerCallbackFnWacom()
                    theButton.text = "Disable script"
                ) else (
                    unregisterCallbackFnWacom()
                    theButton.text = "Enable script"
                )
            )
        )
        createdialog wacomSelectionFix
    )

    I tried having a go at it, there is a "bug" where if you drag click with move, rotate or scale tool you can still apply the effect by letting go of the mouse button before you stop moving the cursor. Although I haven't been able to get it to apply the tool effect when testing with a wacom, but only with my mouse. I'm assuming it's because something is still waiting on the mouse move to finish and if the left mouse button finishes before mouse move that action overrides the NodeEventCallback.

Sign In or Register to comment.