Jump to content

calling function from tool


danilo2

Recommended Posts

Hi! This is my tool function on the shelve (it reads rss and display links on the stage. When this function is pasted into hou.session module it works, but I want to make the same only from the tool. So everything works ok apart of opening browser with links.

The bottom commented line makes this error. How to fix it?

Thank you:)

# The webbrowser module is distributed with Python.  The feedloader module
# is part of this example and its code is listed below.
import webbrowser
import feedloader

use_help_browser = False

links = []

def openLink(index):
    """Open the URL for a given link index."""
    openURL(links[index][1])

def openURL(url):
    """Open a given URL in the browser."""
    if use_help_browser:
        # If a help browser is already open, use it.
        desktop = hou.ui.curDesktop()
        browser = desktop.paneTabOfType(hou.paneTabType.HelpBrowser)
        if browser is None:
            browser = desktop.createFloatingPane(hou.paneTabType.HelpBrowser)
        browser.setUrl(url)
    else:
        webbrowser.open_new(url)


def createObjects():
    """Load the RSS feed and create objects containing the titles.  When
       you click on the objects, they'll open the link in the browser.
    """
    # Load from an RSS feed into the links global variable, storing
    # (title, url) tuples.
    global links
    links = feedloader.loadLinks()

    # Delete all the existing objects in /obj.
    for child in hou.node("/obj").children():
        child.destroy()

    y_pos = 0
    for index in range(len(links)):
        text, url = links[index]

        geo = hou.node("/obj").createNode("geo", run_init_scripts=False)
        font = geo.createNode("font")
        font.parm("text").set(text)

        color = geo.createNode("color")
        color.setFirstInput(font)
        color.parmTuple("color").set((1, 1, 1))
        color.setDisplayFlag(True)

        geo.parm("ty").set(y_pos)
        y_pos -= 2

#HERE I WANT TO CALL THE OpenLink FUNCTION OF THIS TOOL, NOT HOU SESSION.

        #geo.parm("pickscript").set('python -c "hou.session.openLink(%d)"' % index)

    hou.node("/obj").layoutChildren()

createObjects()

Link to comment
Share on other sites

Thank you :)

nut when I'm trying todo so:

geo.parm("pickscript").set('feedloader.goToLink()')

in the place I've orewiously showed, only error occured (after selecting the text) that Houdini doesn't see the feedloader (uknow command feedloader.goToLink).... hmm

How should i make it working?

Edited by danilo2
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...