Ejemplo n.º 1
0
def screenShot():
    """take a screen shot of the current viewport at the current frame"""
    help(screenShot)
    import hou
    import toolutils
    import os
    #selected node
    nodeSelect = hou.selectedNodes()
    path = hou.expandString("$HIP")
    frame = hou.expandString("$F")
    frame = int(frame)
    black = hou.Color((0, 0, 0))
    #name check there is a node selected
    if len(nodeSelect) < 1:
        print("!!!    error: select a node    !!!")
    else:
        for node in nodeSelect:
            name = node.name()
            node.setColor(black)
        #Get the current Desktop
        desktop = hou.ui.curDesktop()
        # Get the scene viewer
        scene = toolutils.sceneViewer()
        flipbook_options = scene.flipbookSettings().stash()
        # set frame range
        flipbook_options.frameRange((frame, frame))
        #set output path
        root = "{1}/{2}/{0}/".format(name, path, "screenShot")
        if os.path.exists(root):
            listPath = os.listdir(root)
            inc = len(listPath)
            inc = int(inc)
            outputPath = "{}{}.{:04d}.jpg".format(root, name, inc)
        else:
            os.makedirs(root)
            inc = 0
            outputPath = "{}{}.{:04d}.jpg".format(root, name, inc)
        #set flipbook current path
        flipbook_options.output(outputPath)
        #run flipbook
        scene.flipbook(scene.curViewport(), flipbook_options)
        # reload image
        print(outputPath)
        editor = hou.ui.paneTabOfType(hou.paneTabType.NetworkEditor)
        image = hou.NetworkImage()
        image.setPath(outputPath)
        image.setRect(hou.BoundingRect(0, 0, 5, 5))
        image.setRelativeToPath(node.path())
        editor.setBackgroundImages([image])
Ejemplo n.º 2
0
    def create_sticker(self, item):

        pane_tab = [t for t in hou.ui.paneTabs() if t.type() == hou.paneTabType.NetworkEditor and t.isCurrentTab()]

        if len(pane_tab) > 0 :
            pane_tab = pane_tab[0]

            image = hou.NetworkImage()
            image.setPath(item.data(Qt.UserRole))

            bounds = pane_tab.visibleBounds()
            bounds.expand((-bounds.size()[0]*0.4, -bounds.size()[1]*0.4))
            image.setRect(bounds)

            background_images = pane_tab.backgroundImages() + (image,)
            pane_tab.setBackgroundImages(background_images)
Ejemplo n.º 3
0
def add_image_to_netview(image_path, pane, pwd):
    """.
    """
    # add image to network view
    image = hou.NetworkImage(image_path)
    image.setBrightness(0.75)
    #image.setRect(hou.BoundingRect(0, 0, 5, 2))
    s = pane.visibleBounds()
    center = s.center()
    s.translate(-center)
    s.scale((0.25, 0.25, ))
    s.translate(center)
    image.setRect(s)

    images = nodegraphutils.loadBackgroundImages(pwd)
    images.append(image)
    pane.setBackgroundImages(images)
    nodegraphutils.saveBackgroundImages(pwd, images)
Ejemplo n.º 4
0
def paste_clipboard_to_netview(kwargs):
    """Paste clipboard contents (text or image) into the network editor.
    """
    clipboard = Qt.QtGui.QGuiApplication.clipboard()
    image = clipboard.image()
    text = clipboard.text()
    pane = kwargs.get('editor', None)

    if pane:
        pwd = pane.pwd()

        if image.isNull():
            # paste text (if any)
            if text != "":
                note = pwd.createStickyNote()
                note.move(pane.visibleBounds().center())
                s = note.size()
                s = hou.Vector2((
                    s.x() * 1.5,
                    s.y() * 0.5,
                ))
                note.setText(text)
                note.setSize(s)
        else:
            # paste image

            # TODO: generate automatic name
            image_name = ''
            ok, image_name = hou.ui.readInput(
                'Enter name of image to be pasted:',
                buttons=(
                    'Ok',
                    'Cancel',
                ),
                close_choice=1,
                initial_contents=image_name)
            if image_name == '':
                ok = 1
            image_name += '.png'

            if ok == 0:
                category = hou.objNodeTypeCategory()
                hda_typename = 'qLib::embedded_images'
                embedded = 'Embedded'
                hda_def = hou.hdaDefinition(category, hda_typename, embedded)

                # create hda definition if doesn't exist
                if not hda_def:
                    temp_node = hou.node('/obj').createNode('subnet')
                    hda_node = temp_node.createDigitalAsset(
                        name=hda_typename, save_as_embedded=True)
                    hda_node.destroy()

                hda_def = hou.hdaDefinition(category, hda_typename, embedded)

                # create an instance in /obj if doesn't exist
                node = None
                nodes = [
                    n for n in hou.node('/obj').children()
                    if n.type().name() == hda_typename
                ]

                if len(nodes) == 0:
                    node = hou.node('/obj').createNode(
                        hda_typename, node_name="embedded_images")

                # add clipboard image to hda definition (as section)
                ba = Qt.QtCore.QByteArray()
                buffer = Qt.QtCore.QBuffer(ba)
                buffer.open(Qt.QtCore.QIODevice.WriteOnly)
                image.save(buffer, "png")
                buffer.close()
                hda_def.addSection(image_name, str(buffer.data()))

                # add image to network view
                image = hou.NetworkImage(
                    "opdef:/qLib::Object/embedded_images?%s" % image_name)
                image.setBrightness(0.75)
                #image.setRect(hou.BoundingRect(0, 0, 5, 2))
                s = pane.visibleBounds()
                center = s.center()
                s.translate(-center)
                s.scale((
                    0.25,
                    0.25,
                ))
                s.translate(center)
                image.setRect(s)

                images = nodegraphutils.loadBackgroundImages(pwd)
                images.append(image)
                pane.setBackgroundImages(images)
                nodegraphutils.saveBackgroundImages(pwd, images)