Home Technical Talk

Script functionality by multiple modifier keys

polycounter lvl 12
Offline / Send Message
jeremiah_bigley polycounter lvl 12
okay so... first things first.
I looked around on the internet how to make something happen in max based on a specific button being held and it led me to some dotnet stuff. Works great. However I was wondering if anyone knew how to set it up to use mutliple keys.

I looked around a bit but it is difficult to find something when I don't really know what I am looking for.

Here is a example of what I have in the script.
wincon = dotnetclass "system.windows.forms.control"
obj = $

if wincon.modifierKeys == wincon.modifierkeys.control do 
    if $ == undefined
    then
        for i in geometry do
            if isproperty i #turbosmooth == true do
                i.modifiers[#turbosmooth].enabled = on
    else
        for i in obj do
            if isproperty i #turbosmooth == true do
                i.modifiers[#turbosmooth].enabled = on



Also if there is an easier way to go about doing this like without dotnet... I am all ears. :D

Replies

  • jeremiah_bigley
    Options
    Offline / Send Message
    jeremiah_bigley polycounter lvl 12
    fffffffffffffffff

    lol okay. I had been checking the maxscript help but I don't know why I didn't think to check the reference on that one.

    Really appreciate it perna. When I posted this I was actually thinking of you because I had seen you talk about smart scripts before.
  • Bryan Cavett
    Options
    Offline / Send Message
    Bryan Cavett polycounter lvl 19
    Jeremiah: I just posted a function to query the modifier keys and examples of how Im using them in the thread Perna linked just so you know.
  • jeremiah_bigley
    Options
    Offline / Send Message
    jeremiah_bigley polycounter lvl 12
    Really would love to Perna... if I could. There is some great information in there but it is a bit over my head still. I am still learning more every weekend but you guys script circles around me. Maybe when I actually read one of your scripts and understand it without reference. :P

    Bryan - I checked it out and I have to say awesome! Really good stuff. I had to go and look up case statements to understand what is going on... but it is definitely what I am looking for. I pretty much have a good understanding of it.

    Maybe you guys can help answer a few questions of mine that came up when I started playing with the code.

    First...

    What is the point of saying for example (keyboard.shiftpressed and not keyboard.controlpressed)? Is that not the same as just saying keyboard.shiftpressed?


    Why a function? I guess it is obvious when I think about it... because you can create this one function that you use throughout all of your scripts. But how would it really help me if I am making single scripts? I would want my scripts to standalone so that I can share them individually with people at work.

    I guess I am just not sure about how to implement that into a workflow yet because as of now my workflow just consists of typing on a keyboard.
  • jeremiah_bigley
    Options
    Offline / Send Message
    jeremiah_bigley polycounter lvl 12
    On the not that makes since... but is it necessary? I haven't tried the same script without them in there. Why can't we just buy milk without the beer without being told? lol

    I guess on the function I noticed you guys seem to have a very specific convention for your keyboard modifiers. What I meant was are you typing this specific modifier function at the beginning of every one of your scripts that need to use modifiers?
    I assumed you might have had a library of functions that are specific to you that load into max every time.

    Thanks for the help btw. ;) I actually just finished my first script implementing the case expressions I learned from the scripts you guys were making. Link
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Jeremiah not sure if I'm misreading here (not a big maxscript guy but have handles on programming in various languages) but the functions run when the script/program runs. Not sure on Maxscript side but most programming languages you can build a library of helper functions and import them. I really should get on board this maxscript train :P
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    gah cant lose you to the darkside of maxscript haiddasalami, your so dam helpful already with the ton of python and mel questions for maya i asked already hehe.
  • Bryan Cavett
    Options
    Offline / Send Message
    Bryan Cavett polycounter lvl 19
    Lots of great info there from Perna.

    Jeremiah: I would experiment with creating a library of useful functions later on down the line, once you get more experienced. Right now just play around and figure out what you want to get working. All I did when I started out was simple standalone macroscripts and then I began to share them with coworkers. Since we all worked a little differently I would have to fix bugs and modify their behavior if I felt the artist had a valid suggestion. This improved my logic handling and error checking. Im just now getting into consolidating all my scripts (I have about 100 different scripts) and re writing them with a library of functions to use throughout them, though I wish I had investigated it sooner (This is a few years down the line). It also requires a bit more work if you want to share your scripts that use a shared library, but if there is a bug in your code you only need to fix it once and not several times.
  • LoTekK
    Options
    Offline / Send Message
    LoTekK polycounter lvl 17
    Perna:
    Fantastic, I hadn't known there were global system variables for keyboard modifiers. I'd toyed with them a bit with some of the dialog/rollout controls, but I wasn't aware of the globally-available system variables, thanks!

    Jeremiah:
    Building (or using/co-opting) a library of useful functions can be a super time saver (and hair saver!). Whether that's large functions that you'll need from time to time, or super small functions that simplify little tasks or provide alternatives to built-in methods, they can be extemely handy. For example, I wrote a small global function that I can use anywhere in my scripts/tools at work:
    function findInArray arr item = (	--case-insensitive array search
    	for i = 1 to arr.count do (
    		if toLower (arr[i] as string) == toLower (item as string) then (
    			return i
    		)
    	)
    	0	--returns 0 if not found, same as built-in findItem()
    )
    

    Now, since the built-in array search method (FindItem()) only does case-sensitive search, I wrote a small function that does case-insensitive searches within arrays, to save me a fair bit of hassle.

    Or something like:
    function subtractArray arr1 arr2 = (
    	--subtract arr2 from arr1
    	local temp = #()
    	for i in arr1 do (
    		if finditem arr2 i == 0 then (
    			append temp i
    		)
    	)
    	temp
    )
    

    Maxscript doesn't provide a method to subtract all the items in an array from a second array, which is something I find myself doing from time to time, so again, I wrote a little function to do just that.
  • jeremiah_bigley
    Options
    Offline / Send Message
    jeremiah_bigley polycounter lvl 12
    wow.. um. I will have to slowly start sifting through all of this information. lol thanks everyone and I will probably be getting back to you in a month or so...

    I get the not pressed thing now... Even after I read your beer and milk thing I still didn't understand what you were saying. So I was like I guess I will just make a quick script with 2 different alt commands... and before I could even get done typing up the keyboard modifier function it hit me.

    I kept telling myself...
    keyboard.shiftpressed
    is the same as
    keyboard.shiftpressed and not keyboard.controlpressed

    and it isn't!

    The case statement would stop at keyboard.shiftpressed even if I was holding control because it found Shift to be true. Could you not just order the case statement in a very specific order to counter that problem? You would just order the case statement backwards... like this...
    case of
    (
        (keyboard.controlpressed and keyboard.shiftpressed and keyboard.alt pressed): return #ctrl_shift_alt
    
        (keyboard.controlpressed and keyboard.shiftpressed): return #ctrl_shift
    
        (keyboard.controlpressed): return #ctrl
    (
    
    This should work just fine right?



    Now...
    There are three boxes. One is labeled "APPLES" another is labeled "ORANGES". The last one is labeled "APPLES AND ORANGES". You know that each is labeled incorrectly. You may ask me to pick one fruit from one box which you choose.

    How can you label the boxes correctly?
    I will admit I had to look up the answer. I think the reason I had so much trouble with it... is because you still can never know. It is brilliant deduction but it is still an assumption There is a 50% chance it is wrong because who is to say that it wasn't completely random?


    My question about the function is in here.
    The function for the modifier keys was never defined in this script. So how are you guys using them? This is why I assumed you had a library somewhere that was being called.


    As for all the script crits... I will have to pick up sometime during the week. If not then it will be over the weekend. Been trying to hit a hard deadline for Wednesday... so I haven't had much time for middle of the week scripting. Regardless of when I get to them I greatly appreciate it Perna. I won't let the crits go to waste.

    Bryan: Guess it is standalone scripts then for now :)

    I really appreciate the time everyone is putting in to me. Really awesome of you guys to help because self teaching myself was going really slow.

    Cheers
  • LoTekK
    Options
    Offline / Send Message
    LoTekK polycounter lvl 17
    The function for the modifier keys was never defined in this script. So how are you guys using them? This is why I assumed you had a library somewhere that was being called.
    Once you've [globally] defined (and evaluated) a function, it is accessible from anywhere. If you have any helper functions you want accessible at any time, you can stick that maxscript file in your startup scripts directory, and it will be evaluated at startup (and hence you can call that function from any of your scripts, or even in the listener).
  • Sage
    Options
    Offline / Send Message
    Sage polycounter lvl 19
    awesome thread. :D i was really missing the smart functions of xsi or silo in max. A few tools that do a lot of things.
  • jeremiah_bigley
    Options
    Offline / Send Message
    jeremiah_bigley polycounter lvl 12
    Lol, you're not married, are you? :D!
    lol no no... not married yet. Just new to the language of programming.

    Seeing the AO puzzle written down helps. It now makes complete sense and I clearly had no idea what I was talking about. While I could agree with you that someone who struggles with logics would struggle with programming. But I also believe that logics could be taught to someone... it is just whether or not they can grasp the concept in the end.

    I am glad we settled the "and not" thing. I was just trying to get out of you guys if this was the only way to go and then I remembered that case statements are order specific. It is good to know both methods as I was taught that the only absolute is that there are no absolutes.

    I really appreciate the information Perna. Just with the bit of information you have supplied you have greatly accelerated the process of me learning scripting. :)

    I will definitely start learning more through the help. Just got side tracked with the turbosmooth script and trying to keep up with this thread. :P

    LoTekK wrote: »
    Once you've [globally] defined (and evaluated) a function, it is accessible from anywhere. If you have any helper functions you want accessible at any time, you can stick that maxscript file in your startup scripts directory, and it will be evaluated at startup (and hence you can call that function from any of your scripts, or even in the listener).

    Okay that makes sense. So if you were making standalone scripts you would have to put it in the script. And if you were making a ton of scripts to be distributed among coworkers or to be downloaded as a package you could create and installer that would put those scripts in the startup folder?

    While it might be faster I don't know that I am at a level of scripting that I need to do that extensively. The only reason it got brought up is because I could see myself using this same modifier key function over and over among all my scripts.

    Thanks for the information LoTekK. :)
Sign In or Register to comment.