1. #1
    Senior Member Follow User Gallery
    Join Date
    Nov 2012
    Location
    BELGIUM Liège
    Age
    39
    Posts
    160

    Default zPlugin "jumping back"

    I encounter a problem in all my zScripts...

    Each time a plugin starts for the first time, its code is executed - I mean the code at the toplevel. For now that's ok, but when you switch/use another, (like for example - just go in maya blend shapes plugin menu and just change from visible to all or so) the next time you use the previous plugin its toplevel code get executed again...

    I've read about the "rebound effect" here but that's to be implemented if you want YOUR plugin to switch back to another... SO my question is : what are the general guidelines to avoid that ? Put all init code in an init routine ? I think that must cause problems with interface stuff and memory bloc definitions...
    I understand that variables are not very good to use in that scheme so I always store important persistent data in memory blocks.

    If someone can clarify... thanks !

  2. #2

  3. #3
    Moderator Follow User Gallery
    Join Date
    Jun 2004
    Location
    UK
    Posts
    11,462

    Default

    Yes, that can be a problem. There are various methods I have used to avoid unexpected behaviour. I use a memory test so that certain code isn't re-run, and a startup routine that makes sure things are restored properly. For example, switches will bounce back to their startup state if you don't take care of that.

    All part of the joys of zscripting.

  4. #4
    Senior Member Follow User Gallery
    Join Date
    Nov 2012
    Location
    BELGIUM Liège
    Age
    39
    Posts
    160

    Default

    Yeah hehe

    zScript is easy everyone should try (and loose their soul) lol

    And what about sleep loops ? I really don't understand what persists between "switchs" and what doesn't...

    And for memory blocks, if I put the MVarDef inside a init routine with some var checking if it had been executed already, I sometime get "memory block undefined"... Should I redo the MVarDef everytime ?
    I'm starting to think too much grr...

  5. #5
    Senior Member Follow User Gallery
    Join Date
    Nov 2012
    Location
    BELGIUM Liège
    Age
    39
    Posts
    160

    Default

    And also, for my swatches button, when it "switchs" my button lose its functionality... I tested a little it happens when I've got a RoutineCall in it... Should I put all my routines in hidden buttons instead ?

    Sorry this thread is starting to become keupon's rant about zScript... lol

  6. #6

  7. #7
    Moderator Follow User Gallery
    Join Date
    Jun 2004
    Location
    UK
    Posts
    11,462

    Default

    For memblocks, you can test for their size and then create them. There's no need to have them in a routine, the code can go at the start and it only runs once:

    [If,[MemGetSize,My_Memblock],
    //do nothing
    ,//else no memblock
    [MVarDef,My_Memblock,10,0]
    //fill the memblock with starting values if desired
    ]


    For switches, make sure you put [Enable,MyPlugin:My_Switch] at the end of your code (not in a routine) to avoid the switch becoming disabled. Also, if you use a memblock value for the switch state you can have it load at startup.

    Not sure how you are swapping your swatches button, so not sure what to suggest. I've swapped out buttons using [IHide] and [IShow] without problems.

  8. #8
    Senior Member Follow User Gallery
    Join Date
    Nov 2012
    Location
    BELGIUM Liège
    Age
    39
    Posts
    160

    Default

    Thanks Doug I didn't think of that (the button could be disabled like a slider between jumps), but unfortunately I tested and it is not that.

    I have several cases of this problem but the one I'm looking onto here is on zSwatches, and part of the problem is that the button gets destroyed and recreated when the image changes (when you change a color in it). So of course it is not very regular but,

    I finally found a good way to do it : I use the double edged button trick (found here) to differentiate click/shift-click, and in it I just added a check to see if the item pressed is this button and execute the code that normally would be inside the button declaration :

    [Sleep,0.001,
    [If,SleepResult==4,//waits for LButton down
    [VarSet,keyOnMouseDown,[IGet,preferences:utilities:viewkeyboardstatus]]
    ]
    [If,SleepResult==1024,//waits for interface pressed
    [If, [IGetID, "ZPlugin:zYourPlugin:zYourButton"]==#sleepWinId),
    [RoutineCall, goBtn]
    ]
    ]
    [SleepAgain]
    , 1024|4, sleepResult, sleepWinId]

  9. #9
    Senior Member Follow User Gallery
    Join Date
    Nov 2012
    Location
    BELGIUM Liège
    Age
    39
    Posts
    160

    Default

    Yes but the image doesn't update just with IHide IShow, so I had to IClose the button and recreate with IButton and fortunately enough the image updated.

    Thanks for all the advices !!!

  10. #10
    Senior Member Follow User Gallery
    Join Date
    Nov 2012
    Location
    BELGIUM Liège
    Age
    39
    Posts
    160

    Default

    Fantastic !!!
    I just found something very interesting !!!

    The sleep command, with events 256 and 512 (256 : Startup, 512 : Shutdown), are in fact triggered when the zScript gain or loose "focus". So init routines can be placed in it I think it is a very clean way to do it !!!

    I still didn't test yet if 256 is triggered at zBrush startup but there's no reason it doesn't. Will test that tomorrow.

    Good night everyone

  11. #11
    Senior Member Follow User Gallery
    Join Date
    Nov 2012
    Location
    BELGIUM Liège
    Age
    39
    Posts
    160

    Default

    In the doc :
    [IShow, Interface item path, Show Zoom Rectangles?, Target parent window?]
    [IHide, Interface item path, Show Zoom Rectangles?, Target parent window?]


    What's "Target parent window?" ??? That's undocumented... Has it to do with the zoom rectangles targeting the parent ? Or something else...

    ( Also Marcus, when you say you swapped out buttons with IHide/IShow - you mean just hide/show them or something more complicated ? )

  12. #12
    Moderator Follow User Gallery
    Join Date
    Jun 2004
    Location
    UK
    Posts
    11,462

    Default

    The 'zoom rectangles' stuff is left over from an earlier version of ZBrush. Like the target stuff in Notes, it no longer works. It's a shame because some nice interface help stuff could be done but I guess it's not a priority.

    Yes, I just meant Hide/Show. You can use a series of buttons and cycle through them which can be useful for some things.

    There's one thing to watch if using a modifier key for a double-edged button: if the user presses a modifier key for something else before pressing your plugin button then in some circumstances the modifier key will persist. The View Keyboard Status slider isn't cleared between keypresses.

  13. #13
    Senior Member Follow User Gallery
    Join Date
    Nov 2012
    Location
    BELGIUM Liège
    Age
    39
    Posts
    160

    Default

    For switching buttons an example is in zAdjustor, I use this technique to swatches between the 6 different buttons for each profile. (I asked because I hoped maybe you had a neat about it in your pocket )

    For modifiers keys, yes I have seen my mistake since I wrote that. Sometimes it doesn't get updated right and ModKeyDown is triggered thousands times a second which is annoying too... Also the line in the piece of code in post #8 is wrong, the line :
    [If,(SleepResult==64||(SleepResult==128)),//waits for keypress
    should instead be :
    [If,(SleepResult==4),//waits for LButton down
    (Post edited)

    Thanks marcus !!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •