title: Call current PyMOL session from python script
body: <p>I'm trying to call current PyMOL session from python script (wxpython GUI), and then load some data from PyMOL and send few commands to PyMOL. At the moment I can open a new PyMOL session in python script:</p>
  
  <pre><code>import sys, os
  from wx import *
  app = wx.App()
  dialog = wx.FileDialog ( None, message = 'Set PyMOL directiry', style = wx.OPEN)
  if dialog.ShowModal() == wx.ID_OK:
      # Pymol path
      moddir = dialog.GetDirectory()
      sys.path.insert(0, moddir)
      os.environ['PYMOL_PATH'] = moddir
  
      import pymol
      pymol.finish_launching()     
  else:
      print 'Nothing was selected.'
  
  from pymol import *   
  dialog1 = wx.FileDialog ( None, message = 'Set PDB file', style = wx.OPEN)
  if dialog1.ShowModal() == wx.ID_OK:
      pdbfile = dialog1.GetPath()
      cmd.load(pdbfile)
  else:
      print 'Nothing was selected.'
  
  dialog.Destroy()
  app.MainLoop() 
  </code></pre>
  
  <p>BUT actually I'd like to check in my python scrip whether any PyMOL session is already opened. 
  I found discussion corresponding to this topic here:
  <a href="https://stackoverflow.com/questions/11858681/only-call-function-if-pymol-running">Only call function if PyMOL running</a>
  Following this discussion I tried to call 'print' function in PyMOL:</p>
  
  <pre><code>try:
      from pymol import cmd
      print 'Connected'
  except:
      &lt;open new Pymol sesssion&gt;
  </code></pre>
  
  <p>but I do not see any text in PyMOL cmd. I tried to determine PyMOL path before this statement and again I failed. </p>
  
  <p>Does anyone know how to call current PyMOL session from python script? </p>