This is a read-only mirror of pymolwiki.org

Difference between revisions of "Selection Exists"

From PyMOL Wiki
Jump to navigation Jump to search
m (5 revisions)
 
(3 intermediate revisions by one other user not shown)
Line 13: Line 13:
 
                 return 1
 
                 return 1
 
     return 0
 
     return 0
</source>
 
  
 
# Note from Warren:
 
# Note from Warren:
 
#
 
#
# a simpler, faster approach:
+
# simpler, faster:
  
 
def sele_exists(sele):
 
def sele_exists(sele):
 
   return sele in cmd.get_names("selections")
 
   return sele in cmd.get_names("selections")
 +
</source>
  
 
+
[[Category:Script_Library|Selection Exists]]
 
+
[[Category:ObjSel_Scripts]]
[[Category:Scripting_Script_Library|Selection Exists]]
 

Latest revision as of 03:49, 28 March 2014

#
# 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

# Note from Warren:
#
# simpler, faster:

def sele_exists(sele):
   return sele in cmd.get_names("selections")