Jump to content

incremental button ?


Recommended Posts

Solution 1 (hack)

 

- Create the buttons in the Edit Parameter Interface.

- Use the Callback Script to update the value your parameter.

- You can put the code in the small box but the gui removes newlines!  :blink: 

- So if writing python add semi-colons (hack)

parm = hou.parm('tx');
increment = parm.evalAsFloat() + 1;
parm.set(increment)

Solution 2

 

Proper way is to create a new custom operator that way it's more reusable.
 
Option 1:
Reference a function from HDA Module. Write the function inside Scripts (Event Handler: Python Module) and then call it in the callback:
kwargs['node'].hdaModule().onButtonPress()
 
Option 2:
 
- Add a script file reference it with opdef:
- Not worth the hazzle. Just do option 1.
 
Solution 3 (hack)
 
Use a script to insert the code bypassing the gui.
  • Like 1
Link to comment
Share on other sites

It's slightly unrelated but can you get the currently edited parameter in Python and then modify it? That would allow you to increment values using hotkeys. I assume this can't be done.

 

You can but the hotkey can't be just `+`  or `-

 

Using PARMmenu.xml create a new entry with a script to increment the param value and assign it a hotkey.

Edited by ayidi
  • Like 1
Link to comment
Share on other sites

Thanks so just to be sure, I will for example select a node, click inside a parameter field like Scale, and then press the hotkey I assigned and it will operate on the active field, i.e. to set it to a fixed value, double it, etc? Not by right clicking the menu item?

 

If so, I will get to it right away :)

Link to comment
Share on other sites

select a node, click inside a parameter field like Scale, and then press the hotkey I assigned and it will operate on the active field, i.e. to set it to a fixed value, double it, etc

 

That's correct.

  • Like 1
Link to comment
Share on other sites

Ok I checked that file and it seems logical but I don't know where my script will reside and how I will link it to the menu? If I understand it correctly, the name of my shelf button (not label) for example will be the id name I will use in the menu file?

Link to comment
Share on other sites

Ok I checked that file and it seems logical but I don't know where my script will reside and how I will link it to the menu? If I understand it correctly, the name of my shelf button (not label) for example will be the id name I will use in the menu file?

 

You stole the thread.

 

Create a file named PARMmenu.xml with the following and place it in your Houdini preference folder or next to your .hip file.

<?xml version="1.0" encoding="UTF-8"?>
<menuDocument>
    <menu>
        <addScriptItem id="parm_increment">
            <label>Increment</label>
            <parent>root_menu</parent>
            <insertBefore>copy_parm</insertBefore>
            <scriptCode><![CDATA[# Increment Script
for parm in kwargs['parms']:
    parmType = parm.parmTemplate().type()
    if parmType == hou.parmTemplateType.Int:
        parm.set(parm.evalAsInt() + 1)
    elif parmType == hou.parmTemplateType.Float:
        parm.set(parm.evalAsFloat() + 1)
]]></scriptCode>
        </addScriptItem>
        <addScriptItem id="parm_decrement">
            <label>Decrement</label>
            <parent>root_menu</parent>
            <insertBefore>copy_parm</insertBefore>
            <scriptCode><![CDATA[# Decrement Script
for parm in kwargs['parms']:
    parmType = parm.parmTemplate().type()
    if parmType == hou.parmTemplateType.Int:
        parm.set(parm.evalAsInt() - 1)
    elif parmType == hou.parmTemplateType.Float:
        parm.set(parm.evalAsFloat() - 1)
]]></scriptCode>
        </addScriptItem>
    </menu>
</menuDocument>

Edited by ayidi
Link to comment
Share on other sites

Thanks a lot man, it works. I am sure kleer will be interested in this trick as well :)

 

When I try to assign it a hotkey though, Houdini doesn't let me. This is what I see, but I can't click the Assigned Keys section as there is nothing selected in the middle section of that dialog.

 

3qWPWv7.png

Link to comment
Share on other sites

  • 1 year 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...