Jump to content

scripting custom hotkeys (not available by HotkeyOverrides)


Recommended Posts

Please, I would like to add few hotkeys to speed up my workflow.

For example, is it possible to add these?
  - Set the Render flag (actually it is not possible to set the flag with mouse hovering over the Parameters pane or over the Scene Viewport pane)
  - Toggle Display Points in the viewport

Should I write any custom Python tool and then set hotkey to it?
Is there any log of recently executed actions by the user, which will help me to replicate those actions in my script?

I am Python newbie so please excuse my noob questions.

Link to comment
Share on other sites

as what you already discovered, create new tool, put it onto shelf and assign hotKey to it - note that in H16 you cant easily assign hotkeys with ALT key.

if you dont want your tool visible in TAB menu, dont fill any Label. I have whole toolbar only for scripts that im using as hotkeys.

 

  • Like 3
Link to comment
Share on other sites

Thank you very much for your answers. I am still a newbie, is there any log of performed actions? For example I would like to replicate the "Display Points" button in the Python script and I am lost where to find the right Python command. Where do you search for the right Python commands to replicate these actions?

If you would be so kind and direct me also to the "Set Render Flag" command.

Link to comment
Share on other sites

The basic idea is to retrieve the selected node and set the render flag. (Just for somebody finding this thread and seeing this for the first time, you would go in a shelf and RMB New Tool...)

node = hou.selectedNodes()[0]
node.setRenderFlag(True)

Strictly speaking that is all you need. Now the render flag is a sop node property, objects don't have it.

You could do a try except block to handle those exceptions.

The other thing you might want later is to set the display flag.

Here is what you can do with nodes in general:

http://www.sidefx.com/docs/houdini/hom/hou/Node

and with sops in particular:

http://www.sidefx.com/docs/houdini/hom/hou/SopNode

 

Just want to leave one last friendly reminder to people starting out with python to drag and drop your nodes on the python console. This will give you a node object to experiment with.

  • Like 1
Link to comment
Share on other sites

Eric thank you very very much, so I made my tool to set the Display and Render Flags and assigned Global Hotkey ... now it works everywhere :) not just in the Network as the Hotkey Overrides offer.

I did not know how and where to start. This is so so great :) thank you very much. Now, after few clicks I have found many interesting things.

Btw that Drag&Drop ... it gives me something like this: hou.node('/obj/rearing_1_fbx/horse_MID1/horse_MID1_deform') ... is this just to speed up typing of the path? Or is there some more functionality?

 

Link to comment
Share on other sites

Yes, you are right, it is really to speed up typing. It is just so convenient :)

What people do is:

node = hou.node('/obj/rearing_1_fbx/horse_MID1/horse_MID1_deform')

and then you can type next:

node.

and you will see the node objects methods be offered to you. This is a great way to experiment.

When coming from other languages it is sometimes useful to keep in mind that in python you are typically given objects (not values). So if you ask for a parm:

node.parm('tx')

you are getting the parm itself. If you want the value than you would ask for that.

parm = node.parm('tx')
parm.eval()

Houdini's python support is really awesome and intuitive. Hope you enjoy it too.

  • Like 1
Link to comment
Share on other sites

Please I have another noob question. I would like single hotkey to toggle between two states. Is it easier for noob like me to have a "global variable", or to detect the actual state from scene?

For example, I would like F12 to toggle "Show Only Selected Geometry" when selecting primitives (to check if I have the right selection on complex models). This Houdini command originally creates just the Visibility SOP, so with one press of F12 I will create the Visibility SOP (and set it right) and with the next press of F12 I will reselect parent and delete the Visibility SOP.

Link to comment
Share on other sites

Hi Jiri,

You can definitively use a global var strategy. 

# Set Houdini global:
value = str('12')
name = 'NEW_GLOBAL'
hou.hscript('set -g '+name+' = '+value)

# Get the value of a global:
hou.expandString('$HIP')

You can check this for more details and options:

http://www.sidefx.com/docs/houdini15.0/hom/hou/hscript

http://www.sidefx.com/docs/houdini/commands/set

 

I would usually refrain from having a global store a state of something that can be obtained dynamically. It is better to just check the state of this thing directly and have your code act accordingly.

Just a suggestion, before doing all this I would have a look at a display option to help visualize selections. If that does not work for you, than sure, go ahead. A word of warning: you might have to manage the selections do have made.

Display Options>Guides>Selection Fill Selection toggle 

  • Like 1
Link to comment
Share on other sites

9 hours ago, ikoon said:

Please I have another noob question. I would like single hotkey to toggle between two states. Is it easier for noob like me to have a "global variable", or to detect the actual state from scene?

For example, I would like F12 to toggle "Show Only Selected Geometry" when selecting primitives (to check if I have the right selection on complex models). This Houdini command originally creates just the Visibility SOP, so with one press of F12 I will create the Visibility SOP (and set it right) and with the next press of F12 I will reselect parent and delete the Visibility SOP.

I have similar setup, as Houdini is missing isolate selection. I have it as RFE, but as they dont have high priority for it i created one myself.

Same idea as what you have. Im using radial menu for it.

Link to comment
Share on other sites

14 hours ago, ikoon said:

Please I have another noob question. I would like single hotkey to toggle between two states. Is it easier for noob like me to have a "global variable", or to detect the actual state from scene?

For example, I would like F12 to toggle "Show Only Selected Geometry" when selecting primitives (to check if I have the right selection on complex models). This Houdini command originally creates just the Visibility SOP, so with one press of F12 I will create the Visibility SOP (and set it right) and with the next press of F12 I will reselect parent and delete the Visibility SOP.

 
 

Isolate Selection

I wrote this many many years ago, still works :)

Can put it on a hotkey or new radial menu. It's a toggle. When nothing is selected - it shows everything.

import os
def isolate():
    sel = hou.selectedNodes()
    if not sel:
        sel_string = "*"
    else:
        sel_string = " ".join([n.name() for n in sel])
    try:
        if hou.os.environ['CUR_ISOLATE'] == sel_string:
            sel_string = "*"
    except: pass
    hou.hscript('viewdisplay -G "%s" `run("viewls -n")`' % sel_string)
    os.environ['CUR_ISOLATE'] = sel_string

 

Edited by Stalkerx777
  • Like 2
Link to comment
Share on other sites

Oh Alex thank you very much. Now I see, that this is really beyond my skils :) probably beyond my life goals ever unfortunately.

Please, what exactly does your script do? Originally I wanted to temporarily hide non-selected primitives (when in selection mode).

Link to comment
Share on other sites

17 hours ago, ikoon said:

Originally I wanted to temporarily hide non-selected primitives (when in selection mode).

 

If you open Display Properties you can find there Visible objects field (Optimize Tab). The script above just puts the selected object names into this field with a help of Hscript function.

If you want to hide primitives you have to play with visibility sop, there is no way to do that other than in sop context.

  • Like 1
Link to comment
Share on other sites

Somehow I have managed to make Python script to Toggle Display Points Markers in the viewport. I am using it for a while (I have assigned Alt-Shift-W hotkey) and it seems ok, so maybe somebody may find it useful too:

Here is the relevant docs url:
http://www.sidefx.com/docs/houdini/hom/hou/GeometryViewportDisplaySet

 

# Get a reference to the geometry viewer
pane = hou.ui.curDesktop().paneTabOfType(hou.paneTabType.SceneViewer)

# Get the display settings
settings = pane.curViewport().settings()

# Get the GeometryViewportDisplaySet for objects
markersDisplayModel = settings.displaySet(hou.displaySetType.DisplayModel)
markersSceneObject = settings.displaySet(hou.displaySetType.SceneObject)

# Toggle the markers (visible when inside /obj/...)
markersDisplayModel.showPointMarkers(not markersDisplayModel.isShowingPointMarkers())

# Unify with the scene (visible when in top level "/obj")
markersSceneObject.showPointMarkers(markersDisplayModel.isShowingPointMarkers())

 

Link to comment
Share on other sites

  • 3 weeks later...

Everything works fine, except one thing. When I unset Display or Render flag (in sops), it doesn't jump back to its last position. Houdini has some intrinsic logic, sometimes the unset flag "jumps" to the top node upstream, sometimes to the bottom downstream. Please, I would like to save the last Display Flag's position and when unset, make it go there. Do I have to use Python? Or is it somewhere in Preferences? I searched but found nothing.

 

EDIT: BTW, if anyone is interested, I have got optimized my hotkeys nicely. They are global (except textport), so you dont have to hover over Network view:

Everything in reach of one hand:
insert = display
pgup = up node
pgdn = dn node
ctrl+insert = display and render
ctrl+del = bypass (on/off), can run on multiple nodes selected

ctrl+shift+insert = template (on/off)
ctrl+shift+del = clean all templates (in the viewport)

ctrl+pgup/pgdn = left/right node multiple inputs

 

Edited by ikoon
Link to comment
Share on other sites

  • 1 month later...

Please, could anybody give me a hint to solve the issue from my previous post? Quote: "When I unset Display or Render flag (in sops), it doesn't jump back to its last position."

Should I use hou.getenv() and hou.putenv() ?

Btw: I have put list of my hotkeys here. It is really convenient to browse the nodes pgup/pgdn and hit Insert to view, or ctrl-del to un/bypass multiple nodes.
http://lab.ikoon.cz/index.php/2017/07/26/shelf-tools-and-hotkeys/

Link to comment
Share on other sites

  • 6 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...