Welcome to od|forum

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

ikoon

scripting custom hotkeys (not available by HotkeyOverrides)

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.

Share this post


Link to post
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.

 

1 person likes this

Share this post


Link to post
Share on other sites
1 hour ago, martinkindl83 said:

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.

 

I came here literally with this exact issue, thank you

Share this post


Link to post
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.

Share this post


Link to post
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.

1 person likes this

Share this post


Link to post
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?

 

Share this post


Link to post
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.

1 person likes this

Share this post


Link to post
Share on other sites

I will go through it, thank you very much for showing me the path into it!

Share this post


Link to post
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.

Share this post


Link to post
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 

1 person likes this

Share this post


Link to post
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.

Share this post


Link to post
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
1 person likes this

Share this post


Link to post
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).

Share this post


Link to post
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.

1 person likes this

Share this post


Link to post
Share on other sites

If you are on H16 you can use those two scripts. One adds visibility node with blast (as i didnt wanted to render hidden prims) and second finds all visibility nodes with specific names and deletes them.

 

kill isolate.txt

isolate after.txt

1 person likes this

Share this post


Link to post
Share on other sites

Thank you very very very much! Martin this is exactly what I wanted. Also it helps me to develop more on my own, thank you guys!

Share this post


Link to post
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())

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now