Home Technical Talk

maxscript windows chime

polycounter lvl 12
Offline / Send Message
jeremiah_bigley polycounter lvl 12
I have this bound to a hotkey and when I run it 3 times windows makes a "no" sound between the second and third button press. But then it will run on the forth press?

Any ideas? Any help would be very appreciated. :)


it just jumps between the top modifier and either last edit poly mod or base modifier.
local BaseSwitchSOL

if classof (modpanel.getcurrentobject()) == Editable_Poly or classof (modpanel.getcurrentobject()) == Edit_Poly then
            (
                BaseSwitchSOL = subobjectlevel
                modPanel.setCurrentObject $.modifiers[1]
            )
            else
            (
                try
                (
                    modPanel.setCurrentObject $.editpoly
                    subobjectlevel = BaseSwitchSOL
                )
                catch
                (
                    modPanel.setCurrentObject $.baseObject
                    if BaseSwitchSOL != undefined then
                    (
                        subobjectlevel = BaseSwitchSOL
                    )
                    else
                    (
                        subobjectlevel = 0
                    )
                )
            )

Replies

  • jeremiah_bigley
    Options
    Offline / Send Message
    jeremiah_bigley polycounter lvl 12
    so the issue isn't with my code... it is with setting it to a hotkey.
    Whenever I run it as a button I can hit the button a hundred times no problem. However the moment I run it through a hotkey, trying F and also tested Y, it gives me the "No!" sound as if I am not in the right window.

    If I move the viewport each time inbetween the hotkey press it will work. This is kinda stupid :/ Do I need to be setting the viewport to active or something?
  • xXm0RpH3usXx
    Options
    Offline / Send Message
    xXm0RpH3usXx polycounter lvl 13
    i'm sry for my complete noobishness, i do not even know if this is intelligent or not, but couldnt you redraw your screen as last statement in your script?
    so you would refresh the screen, but not actually change its focus
  • monster
    Options
    Offline / Send Message
    monster polycounter
    I'm not sure what you are trying to do with BaseSwitchSOL. When you get the the Else clause it will always equal undefined so it will always Catch. This is because each time the script is run, it's a new instance of the script, so BaseSwitchSOL always starts as undefined. You would need to make it global to keep the value persistent.

    But your script works for me every time, as a button or hotkey.

    I did take a crack at it too. It has a little extra error checking so there is no need for a try/catch.
    if selection.count == 1 do
    (
    	obj = selection[1]
    	
    	if obj.modifiers.count > 0 do
    	(
    		if modPanel.getCurrentObject() == obj.modifiers[1] then
    		(
    			if isProperty obj #Edit_Poly then
    			(
    				modPanel.setCurrentObject obj.Edit_Poly
    			)
    			else
    			(
    				modPanel.setCurrentObject obj.baseObject
    			)
    		)
    		else
    		(
    			modPanel.setCurrentObject obj.modifiers[1]
    		)
    	)
    )
    
  • jeremiah_bigley
    Options
    Offline / Send Message
    jeremiah_bigley polycounter lvl 12
    monster wrote: »
    But your script works for me every time, as a button or hotkey.

    !

    That is strange. It works fine at work... :( Guess it is something with my setup at home? ugh!

    Yeah haha! I don't know why but before I uploaded the code it was global. People always seem to get onto me for using globals so out of paranoia I switched it to local. BaseSwitchSOL is meant to remember the subobject level of the edit poly or editable poly so that it takes you back there when you switch back and forth.

    Here is where I was at with the code when I went to bed last night. Monster I will be sure to tweak it up to implement the extra checks. Is try catch generally a bad idea or is it just showing me being lazy? lol I thought I read somewhere that it was slower but I have never really felt the impact of a try catch.

    As always man thanks for the help.
        global BaseSwitchSOL
        
        undo "Modifier Base Switch" on
        (
            if selection.count == 1 do
            (
                max modify mode
                
                local BaseSwitchCurMod = modPanel.getCurrentObject()
                
                if classOf BaseSwitchCurMod == Editable_Poly or \
                classOf BaseSwitchCurMod == Edit_Poly or \
                superclassof (modPanel.getCurrentObject()) == geometryclass then
                (
                    BaseSwitchSOL = subObjectLevel
                    subobjectlevel = 0
                    try (modPanel.setCurrentObject $.modifiers[1]) catch(print "No top modifier.")
                    subobjectlevel = 0
                )
                else 
                (
                    if isProperty $ #editpoly then
                    (
                        subobjectlevel = 0
                        modPanel.setCurrentObject $.editpoly
                        subObjectLevel = 
                        (
                            if BaseSwitchSOL != undefined then
                            (
                                BaseSwitchSOL
                            )
                            else (0)
                        )
                    )
                    else
                    (
                        subobjectlevel = 0
                        modPanel.setCurrentObject $.baseObject
                        subObjectLevel = 
                        (
                            if BaseSwitchSOL != undefined then
                            (
                                BaseSwitchSOL
                            )
                            else (0)
                        )
                    )
                )
            )
        )
    
Sign In or Register to comment.