home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2005 November / WNnov2005.iso / Windows / Equipement / Blender / blender-2.37a-windows.exe / $_5_ / .blender / scripts / camera_changer.py < prev    next >
Text File  |  2005-05-22  |  4KB  |  121 lines

  1. #!BPY
  2.  
  3. """ Registration info for Blender menus: <- these words are ignored
  4. Name: 'Camera Changer'
  5. Blender: 234
  6. Group: 'Animation'
  7. Tip: 'Create script link to change cameras (based on their names) during an animation'
  8. """
  9.  
  10. __author__ = '3R - R3gis'
  11. __version__ = '1.2'
  12. __url__ = ["Author's site , http://cybercreator.free.fr", "French Blender support forum, http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender"]
  13. __email__=["3R, r3gis@free.fr"]
  14.  
  15.  
  16. __bpydoc__ = """\
  17. This script creates an script link to change cameras during an animation.
  18.  
  19. The created script link (a Blender Text) is linked to Scene Frame Changed events.
  20.  
  21. Usage:
  22.  
  23. Run the script, then name the camera Object with the number of the frame(s)
  24. where you want this camera to become active.
  25.  
  26. For example:<br>
  27.   - a camera called "10" will become active at frame 10.<br>
  28.   - a camera called "10,25,185" will become active at frames 10, 25 and 185.  
  29.  
  30. Notes:<br>
  31.   - This script creates another script named camera.py, which is linked to the current scene.<br>
  32.   - If there is already a text called "camera.py", but it's from an old version or is not recognized,
  33. you can choose if you want to rename or overwrite it.
  34.   - Script inspired by Jean-Michel (jms) Soler's:<br>
  35.     http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_changerdecamera.htm
  36. """
  37.  
  38.  
  39. # $Id: camera_changer.py,v 1.3 2005/05/20 05:14:03 ianwill Exp $
  40. #
  41. # --------------------------------------------------------------------------
  42. # ***** BEGIN GPL LICENSE BLOCK *****
  43. #
  44. # Copyright (C) 2004-2005: Regis Montoya
  45. #
  46. # This program is free software; you can redistribute it and/or
  47. # modify it under the terms of the GNU General Public License
  48. # as published by the Free Software Foundation; either version 2
  49. # of the License, or (at your option) any later version.
  50. #
  51. # This program is distributed in the hope that it will be useful,
  52. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  53. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
  54. # GNU General Public License for more details.
  55. #
  56. # You should have received a copy of the GNU General Public License
  57. # along with this program; if not, write to the Free Software Foundation,
  58. # Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  59. #
  60. # ***** END GPL LICENCE BLOCK *****
  61. # --------------------------------------------------------------------------
  62.  
  63. #Script inspired of the idea of this one :
  64. #http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_changerdecamera.htm
  65. #
  66. #----------------------------------------------
  67. # R3gis Montoya (3R)
  68. #
  69. # Pout tout probleme a:
  70. # cybercreator@free.fr
  71. # ---------------------------------------------
  72.  
  73. import Blender
  74. from Blender import *
  75. import string
  76.  
  77. sc=Scene.GetCurrent()
  78.  
  79. #import du texte
  80. lestext=Blender.Text.Get()
  81. Ntexts=[]
  82. for txt in lestext:
  83.     Ntexts.append(txt.getName())
  84. ecrire=0
  85.  
  86. if 'camera.py' not in Ntexts:
  87.     ecrire=1
  88. else :
  89.     if lestext[Ntexts.index('camera.py')].asLines()[0] != "# camera.py 1.2 link python #":
  90.         reecrire=Blender.Draw.PupMenu("WARNING: Text camera.py already exists but is outdated%t|Overwrite|Rename old version text")
  91.         if reecrire == 1:
  92.             Text.unlink(lestext[Ntexts.index('camera.py')])
  93.             ecrire=1
  94.         if reecrire == 2:
  95.             lestext[Ntexts.index('camera.py')].name="old_camera.txt"
  96.             ecrire=1
  97.  
  98.  
  99.  
  100. if ecrire == 1:
  101.     scripting=Blender.Text.New('camera.py')
  102.     scripting.write("# camera.py 1.2 link python #\nimport Blender\nfrom Blender import *\nfrom math import *\nimport string\n")
  103.     scripting.write("sc=Scene.GetCurrent()\n#Changement camera\nlescam=[]\nobjets=Blender.Object.Get()\n")
  104.     scripting.write("for ob in objets:\n    if type(ob.getData())==Blender.Types.CameraType:\n        try:")
  105.     scripting.write("\n            lesfram=string.split(ob.name,',')\n            for fr in lesfram:\n                lescam.append(ob.name)\n                lescam.append(int(fr))\n        except:\n            pass")
  106.     scripting.write("\nframe = Blender.Get('curframe')\nif frame in lescam:\n    nom=lescam.index(frame)\n    sc.setCurrentCamera(Blender.Object.Get(lescam[nom-1]))\n")
  107.  
  108.  
  109. #Linkage
  110. list=[]
  111. try:
  112.     for script in sc.getScriptLinks('FrameChanged'):
  113.         list.append(script)
  114. except:
  115.     pass
  116. if 'camera.py' not in list:
  117.     sc.addScriptLink('camera.py','FrameChanged')
  118.     Blender.Draw.PupMenu("Done! Remember:%t|Name cameras as (a comma separated list of) their activation frame number(s)")
  119.     Blender.Redraw(-1)
  120.  
  121.