This is a read-only mirror of pymolwiki.org

Difference between revisions of "Selection Exists"

From PyMOL Wiki
Jump to navigation Jump to search
 
Line 14: Line 14:
 
     return 0
 
     return 0
 
</source>
 
</source>
 +
 +
# Note from Warren:
 +
#
 +
# a simpler, faster approach:
 +
 +
def sele_exists(sele):
 +
  return sele in cmd.get_names("selections")
 +
 +
  
 
[[Category:Scripting_Script_Library|Selection Exists]]
 
[[Category:Scripting_Script_Library|Selection Exists]]

Revision as of 00:32, 4 March 2005

#
# The function below will return true if the selection is defined.
#
from pymol import cmd
from types import *

def sele_exists(sele):
    sess = cmd.get_session()
    for i in sess["names"]:
        if type(i) is ListType:
            if sele==i[0]:
                return 1
    return 0
  1. Note from Warren:
  2. a simpler, faster approach:

def sele_exists(sele):

  return sele in cmd.get_names("selections")