Giter VIP home page Giter VIP logo

expandcollapsestringparm's Introduction

Expand/Collapse String Parameter

Example files for Expand / Collapse String Parameter video

Snippets

Disable When / Hide When Expressions

Used to control parameter visibility.

Hide When Expression

{ expanded == 1 }

Hide When Expression (multiparm)

{ expanded# == 1 }

Toggle Expand

Callback function that controls our parameter reference switching.

# Toggle Expand (single)
def toggle_expand(node):
    collapsed = node.parm("note_collapsed")
    expanded = node.parm("note_expanded")
    parms = [collapsed, expanded]

    if node.evalParm("expanded"):
        parms.reverse()
    parms[0].deleteAllKeyframes()
    parms[1].deleteAllKeyframes()
    parms[1].set(parms[0])
    
toggle_expand(kwargs["node"])
# Toggle Expand (multiparm, Python 2.7+)
def toggle_expand(node, parm_index):
    collapsed = node.parm("note_collapsed" + str(parm_index))
    expanded = node.parm("note_expanded" + str(parm_index))
    parms = [collapsed, expanded]

    if node.evalParm("expanded" + str(parm_index)):
        parms.reverse()
    parms[0].deleteAllKeyframes()
    parms[1].deleteAllKeyframes()
    parms[1].set(parms[0])

toggle_expand(kwargs["node"], kwargs["script_multiparm_index"])
# Toggle Expand (multiparm, Python 3)
def toggle_expand(node, parm_index):
    collapsed = node.parm(f"note_collapsed{parm_index}")
    expanded = node.parm(f"note_expanded{parm_index}")
    parms = [collapsed, expanded]

    if node.evalParm(f"expanded{parm_index}"):
        parms.reverse()
    parms[0].deleteAllKeyframes()
    parms[1].deleteAllKeyframes()
    parms[1].set(parms[0])

toggle_expand(kwargs["node"], kwargs["script_multiparm_index"])

Action Button

Nice UI element that controls the state of the expanded toggle.

# Action Button
parm = kwargs["node"].parm("expanded")
parm.set(1)
parm.pressButton()
# Action Button (multiparm, Python 2.7+)
idx = kwargs["script_multiparm_index"]
parm = kwargs["node"].parm("expanded" + str(idx))
parm.set(0)
parm.pressButton()
# Action Button (multiparm, Python 3)
idx = kwargs["script_multiparm_index"]
parm = kwargs["node"].parm(f"expanded{idx}")
parm.set(1)
parm.pressButton()

Multiparm Default Channel Reference

chs("note_collapsed#")

UPDATE

Petr Zloty left a very handy comment on Vimeo demonstrating how you can expand/collapse a parm using only the Action Button only by modifying the parmTemplate. This solution is simple and elegant, and better overall for single parameters. However, this method will not work for individual multiparms since modifying the parmTemplate for one modifies them all which is something I wanted to avoid.

# current node
node = kwargs['node']

# current parameter
pt = kwargs["parmtuple"]

# its template
template = pt.parmTemplate()

# parameter's tags
tags = template.tags()

# invert collapsed tag
tags['editor'] = str(1-int(tags['editor']))

# invert icon
tags['script_action_icon'] = "KEYS_Up" if tags['script_action_icon'] == "KEYS_Down" else "KEYS_Down"

# set updated tags
template.setTags(tags)

# replace parameter template with updated tags
group = node.parmTemplateGroup()
group.replace(pt.name(), template)
node.setParmTemplateGroup(group)

expandcollapsestringparm's People

Contributors

jamesrobinsonvfx avatar

Watchers

 avatar

Forkers

maxsteven

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.