0

Need Help Making a Hotkey

Can you help me make a Hotkey please?

I have a stack with 2 renders and I would like to be able to toggle the Composite Mode -> Difference on and off. 

I'm hoping ctrl+d will toggle between OVER and DIFFERENCE.

 

thanks

7 comments

  • Avatar
    (Michael) Kessler Official comment

    Hi Nick!

     

    Hotkeys can be added through packages that run either python or mu code.  Toggling the composite mode is just a single property, but to discover the property; you can either check out the reference manual for the property ( http://www.tweaksoftware.com/static/documentation/rv/current/html/rv_reference.html ) or my favorite way is the save out the session file before I toggle the parameter and afterward and view the difference.

    Here I've taken both over and difference and saved each out as a session file and brought them into my diff viewer of choice (meld).


    You can see the only change is what we would expect, a change from over to difference; contained within the "stack" node under the component block "composite"

    We now know the property we need to change is (in this case) default_stack.composite.type

     

    To build the package, the minimal example in both mu and python is described here: http://www.tweaksoftware.com/static/documentation/rv/current/html/rv_reference.html#Chapter_10_A_Simple_Package

    If we take that package as a framework, we can build a function to call that swap between the two states with something like this:

    import rv.commands
    property_name ="@RVStack.composite.type"
    comp_types = rv.commands.getStringProperty(property_name)
    if comp_types:
    if comp_types[0] == "over":
    rv.commands.setStringProperty(property_name, ["difference"])
    else:
    rv.commands.setStringProperty(property_name, ["over"])

    That will look for the first RV stack's composite type.
    If it finds one it will check to see if it is already set to "over".
    If it is set to over, then set it instead to difference; otherwise, set it to over.


    Once we integrate it into a simple package, we have something that looks like this:

    from rv import commands, rvtypes, runtime
    from rv.commands import NeutralMenuState

    class ToggleCompositeMode(rvtypes.MinorMode):

    def __init__(self):
    rvtypes.MinorMode.__init__(self)

    self.init("ToggleCompositeMode", [("key-down--control--d", self.toggleMode, "Toggle Composite Mode")], None, None)

    def toggleMode(self, e=None):

    property_name ="@RVStack.composite.type"
    comp_types = commands.getStringProperty(property_name)
    if comp_types:
    if comp_types[0] == "over":
    commands.setStringProperty(property_name, ["difference"])
    else:
    commands.setStringProperty(property_name, ["over"])

    def createMode():
    return ToggleCompositeMode()

     

    I've packaged the above into an .rvpkg file as an example, but all that requires is writing a PACKAGE file and zipping the two up; that format is described here: http://www.tweaksoftware.com/static/documentation/rv/current/html/rv_reference.html#Chapter_9_Package_System_Package_File_Contents


    You can download the example package I wrote for this post here: https://autodesk.box.com/s/yy5w4vloln3fqug7vr0yb5nxidktmtny

     

  • 1
    Avatar
    (Michael) Kessler

    Nick, It appears that I linked the wrong package; the above one is a similar (though more complex example) of setting the annotation undo to a keyboard shortcut.


    The proper link is here:
    https://autodesk.box.com/s/j3y759b21mzg72fugq7ls1s0c720fqsp

  • 0
    Avatar
    Nick Joseph

    Hiya, 

    Thanks for your help :D

     

    I'm not able to download the package as I dont have a Box@Autodesk account. The link takes me to a Login page.

    Would it be possible to email me ? <email removed>

  • 0
    Avatar
    Nick Joseph

    also.. i'm using 6.2.7

  • 0
    Avatar
    (Michael) Kessler

    I've just opened up the permissions; but I'll also email it to you.

  • 0
    Avatar
    Nick Joseph

    that is awesome! works well, Thanks.

    Is the createMode() function required by RV? Can this be renamed per package, or does it have to be in each package? 

     

     

  • 0
    Avatar
    (Michael) Kessler

    Yes, the createMode() is called by RV and needs to exist for the mode to be registered by the package manager.  It needs to be in each package, but in most cases it is that simple boilerplate code, ie:

     

    def createMode():
    return ToggleCompositeMode()

     

    If you were to get fancy and need to set up things at mode definition time (or profiling, etc) you could do it there, but in most cases the implementation will be as simple as above.

Please sign in to leave a comment.