Difference between revisions of "ObjectFocus"

From PyMOLWiki
Jump to navigation Jump to search
(Created page with "=Overview= A simple script to walk over objects in the object menu panel. =The Code= <source lang="python"> import pymol from pymol import cmd UP, DOWN = -1, 1 in_focus = 0 d...")
 
(No difference)

Latest revision as of 12:30, 20 September 2012

Overview

A simple script to walk over objects in the object menu panel.

The Code

import pymol
from pymol import cmd

UP, DOWN = -1, 1

in_focus = 0

def object_focus(direction):
    """
    A simple script that remaps the PgUp and PgDn keys to walk through
    objects in the object list.
    """

    global in_focus, UP, DOWN

    cmd.wizard()

    names = cmd.get_names("public_objects")

    in_focus += direction

    if in_focus<0:
        in_focus = 0
    if in_focus > len(names)-1:
        in_focus = len(names)-1

    cur_obj = names[in_focus]

    cmd.orient(cur_obj,animate=1)
    cmd.wizard("message", "Object: %s" % (cur_obj))


cmd.set_key("PgUp", object_focus, [UP])
cmd.set_key("PgDn", object_focus, [DOWN])