Complete Blender
Scripts Python 
Version Française
    Beginning   Index
précédent Index
Shadows: Wire frames Next
  • A- Warning.
  • B- Introduction.
  • C- Differences between Script Windows and "link" windows  (binding).
  • Few short cuts in text processing.
  • D- Load a script.
  • E- How does it works ?
  •  Be careful (give your whole mind to)word processing faults:
  •  Launch script running
  •  Displaying on terminal

  • Warning.



    This page is reserved for CKey Blender users . The Ckey is a personnal code wich unlock the soft paying options . To check that the Key is correctly installed just look at the RightTopCorner of your screen if there is a little gilded donut that is ok . CAREFUL: Since the 1.8a version blender has no more Ckey.
     

    Introduction.



    Complete Blender is fitted with a programming language wich allows the access to the various objects it contains: The Python. Is a language with a convivial shell wich works whatever the operating system may be. Studying programming is not the aim of this teachware. There are wonderful sites devoted to programming with Blender's Python script  (in english). You can obtain the describing of the language itself at the following address: http://www.python.org. For French-speaking :http://www.python.org/doc/NonEnglish.html#french.

    You must notice that a few  extremely efficient functions allow both : modifying each node (point/ vertices) of the mesh and displaying the shape we desire.








    A programming process does'nt avoid the usual steps : drawing, trussing, modelling "by hand".

    Résult:

       Test the file: mandelbrot.py







    Differences between script and "link" windows (binding).



    This window allows writing, it is a very simple wordprocessing.

       Few short cuts :

           Alt-S: Backup of the file
           Alt-O: Opening a file

           Alt-A: Select the whole text

           Alt-C: Copy the selected part
           Alt-V:  Past what is in buffer.
           Alt-X: Delete the selected part.
           Alt-J: Skip to line n

           Alt-U: (undo) Cancel.
           Alt-R: (redo)  Repeat.

           Alt-Shift-S : Menu Select including Jump to line n, very interesting for bug shooting.
           Alt-Shift-F : Menu File usual controls (instructions)
           Alt-Shift-E : Menu Edit cut, past, copy, display the content of the selection buffer.
           Alt-Shift-V : Menu View skip to : begin or end of the file, next page, previous page

    "binding" window, to join the file :
    either to an animation generally, the script runs picture by picture, using a few constants
    giving the picture's number or the time elapsed;
    or to an object in particular.
     
     

    To load a script :


        1. click the button : opening data block .

        2. choose OPEN NEW, doing so opens a window at the default directory to load a ".py" file.
     

    How does it work ?


    What's better than an exemple to really understand what's happening.
    If you have a windows O.S. ,  you have to open a script's window  by clicking ADD instead of OPEN,
    then type the following text :
     
     

    ligne 0     #version windows
    ligne 1     import Blender
    ligne 2     import sys
    ligne 3
    ligne 4     obj = Blender.Object.Get()
    ligne 5     print
    ligne 6     print obj
    ligne 7     print len(obj)
    ligne 8     print
    ligne 9     sys.stdout.flush()
    (to obtain the character #  with an european keyboard azerty, see: How to do ?)
    or
    ligne 0      # version linux
    ligne 1     import Blender
    ligne 2
    ligne 3     obj = Blender.Object.Get()
    ligne 4     print
    ligne 5     print obj
    ligne 6     print len(obj)
    ligne 7     print
    (the whole following explanations are fully reliable(100%)
    only for windows operating system)

    The script calls to  Blender module to obtain the contain of an object.
    The function that allows to do this is Blender.Object.Get().
    This is not a default function of the Python language. The python, indeed, can be completed by a group of modules containing new objects. As a reminder : When you work in Object-Oriented-Programming, an object is
    an ensemble of methods ( example, Get() is a method of the object Object  wich is contained by the module Blender) and datas. You must begin the writing of the script with a line asking the interpretor to load the module containing this function.

    If you do'nt give an object's name to the calling function for example Blender.Object.Get("Plane01"),
    the function gives you the whole list of objects existing at the time in memory.

    Beware of the errors in the word processing :



        The python runs line by line, so it is important to keep the order of the example.
        Indentations and tabulations inform the language it has to gather the instructions in a subroutine.
        therefore the text :
     
    ligne 4    obj = Blender.Object.Get()
    ligne 5    print obj
    ligne 6

        is executed without any problem , even when the text below ( the gap or blank is indicated in red) :
     

    ligne 4     obj = Blender.Object.Get()
    ligne 5     print obj
    ligne 6      ...

        will generate an error during the running :

        The trailing blank are to be avoid absolutly.
     

    ligne 4         obj = Blender.Object.Get()
    ligne 5         print obj
    ligne 6         ...

    Launch the running of the script.



    It is the combination of keys : Alt-P wich is going to activate the script.
    But it's not the only way to do it.
    A script can be linked to an animation(or be within an animation), in this case, it is the launch of the animation that will execute the script.

    Displaying on terminal.



    Of course if you intend to see the list displayed in the default window you will be deceived.
    but even if you can't see anything, the 'Terminal" 's contain has been changed.

    You just have to click the button to see it's contain :

    Another option shouldl be to launch Blender with the following parameters :
     blender -p 0 200 640 480  (a trick i borrowed to the article made by Strubi and Cartsen wich you can find at : http://www.blenderbuch.de/tutor/python1/python1_eng.html )
     
     

    This display fit with the frame of the default file that Blender loads at the launch.  The little icon  indicates that we are talking about an object.
    The python sent us back a list containing an object "camera" and an object "plane" due to the control print obj.

    The control len(obj) allows to know the length of the obj list.
     

    With python language, lists are declared and contained between brackets,
     "[" and "]". To have the characters "[" and "]" with an european keyboard azerty, look at : How to do ?)


     
     
     
     
     
     
    previous Index
     Shadows: Wire frames Next
    To the top of the page     Page Top

    Questions related to this page can be asked at   :
     news://news.zoo-logique.org/3D.Blender