Jump to content

Another Python Question


few_a_fx

Recommended Posts

Adding some new features to my fx tool. I'm using a trail and cache node now, and I want to be able to clear the cache SOP without going to the cache node and clicking clear. I've create a button for the "clear cache" parameter on my wxPython GUI, now I'm stuck on this. If anyone knows how to clear the cache sop through python that would be very helpful.

Link to comment
Share on other sites

Hi,

you could do this:

node = hou.node( '/obj/geo1/cache1' ) #point at your cache node

node.parm('clear').pressButton() #and call its onPressedButton function

if you put these lines in a function, you can do a callback to this function from the button you have created in your UI

Cheers,

Emanuele

Link to comment
Share on other sites

Hi,

you could do this:

node = hou.node( '/obj/geo1/cache1' ) #point at your cache node

node.parm('clear').pressButton() #and call its onPressedButton function

if you put these lines in a function, you can do a callback to this function from the button you have created in your UI

Cheers,

Emanuele

For the onPressButton function, do I have to write a callback script for this to work?

Link to comment
Share on other sites

No. The function call will execute any internally defined events, as well as callbacks you have added.

Then do I have to put anything in the .pressButton() parentheses? I just put those to strings in my code and nothing is happening when I click the button.

Link to comment
Share on other sites

Nope. It should just execute the button and be happy. I just tested it out on a Cache SOP, as well as the Reset button on the Edit SOP and both worked as expected.

I must be putting it in wrong then, because its only clear the cache when I press the button on the cache SOP and not on my python GUI. Here's the code I have.

def clearCache(self, event):
        try:
            node = hou.node('/obj/Rain_System/TRAILING') #point at your cache node
            node.parm("clear").pressButton() #and call its onPressedButton function
        except:
            exc_log

Here's the wxPython scripts for the GUI:

def _add_trails(self):
        trails_sizer= wx.BoxSizer(wx.HORIZONTAL)
        self.flex_grid_sizer.Add(trails_sizer, flag= wx.ALIGN_CENTER_VERTICAL)
        self.trail_on= wx.CheckBox(self, label= "On/Off")
        trails_sizer.Add(self.trail_on, 0, flag= wx.ALIGN_CENTER_VERTICAL)
        self.trail_on.Bind(wx.EVT_CHECKBOX, self.TrailOn)
        self.clear_button= wx.Button(self, label= "Clear Cache")
        trails_sizer.Add(self.clear_button, 0, border= 10,
            flag= wx.LEFT|wx.ALIGN_CENTER_VERTICAL)
        self.clear_button.Bind(wx.EVT_BUTTON, self.clearCache)

Link to comment
Share on other sites

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...