~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/doc/LibData.py

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2007-05-17 11:47:59 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517114759-yp4ybrnhp2u7pk66
Tags: 2.44-1
* New upstream release.
* Drop debian/patches/01_64bits_stupidity, not needed anymore: as of this
  version blender is 64 bits safe again. Adjust README.Debian accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# bpy.lib submodule
 
2
 
 
3
"""
 
4
The bpy.libraries submodule.
 
5
 
 
6
Libraries
 
7
=========
 
8
 
 
9
This module provides access to objects stored in .blend files.  With it scripts
 
10
can append from Blender files to the current scene, like the File->Append
 
11
menu entry in Blender does.  It allows programmers to use .blend files as
 
12
data files for their scripts.
 
13
 
 
14
@warn: This module is new and being considered as a replacement for the 
 
15
L{original Library<Library>} module.  Users should stay tuned to see
 
16
which module is supported in the end.
 
17
 
 
18
Example::
 
19
        import bpy
 
20
 
 
21
        scn= bpy.scenes.active                            # get current scene
 
22
        lib = bpy.libraries.load('//file.blend')          # open file.blend
 
23
        ob = scn.objects.link(lib.objects.append('Cube')) # append Cube object from library to current scene
 
24
        mat = lib.objects.link('Material')                # get a link to a material
 
25
        me = ob.getData(mesh=1)                           # get mesh data
 
26
        me.materials[0] = mat                             # assign linked material to mesh
 
27
"""
 
28
 
 
29
def load(filename):
 
30
  """
 
31
  Select an existing .blend file for use as a library.  Unlike the 
 
32
  Library module, multiple libraries can be defined at the same time.  
 
33
  
 
34
  @type filename: string
 
35
  @param filename: The filename of a Blender file. Filenames starting with "//" will be loaded relative to the blend file's location.
 
36
  @rtype: Library
 
37
  @return: return a L{Library} object.
 
38
  """
 
39
 
 
40
class Libraries:
 
41
        """
 
42
        The Library object
 
43
        ==================
 
44
        This class provides a unified way to access and manipulate library types
 
45
        in Blender.
 
46
        It provides access to scenes, objects, meshes, curves, metaballs,
 
47
        materials, textures, images, lattices, lamps, cameras, ipos, worlds,
 
48
        fonts, texts, sounds, groups, armatures, and actions.
 
49
        @ivar filename: The path to the library
 
50
        @type filename: string
 
51
        @ivar scenes: library L{scene<Scene.Scene>} data
 
52
        @type scenes: L{LibData}
 
53
        @ivar objects: library L{object<Object.Object>} data
 
54
        @type objects: L{LibData}
 
55
        @ivar meshes: library L{mesh<Mesh.Mesh>} data
 
56
        @type meshes: L{LibData}
 
57
        @ivar curves: library L{curve<Curve.Curve>} data
 
58
        @type curves: L{LibData}
 
59
        @ivar metaballs: library L{metaball<Metaball.Metaball>} data
 
60
        @type metaballs: L{LibData}
 
61
        @ivar materials: library L{material<Material.Material>} data
 
62
        @type materials: L{LibData}
 
63
        @ivar textures: library L{texture<Texture.Texture>} data
 
64
        @type textures: L{LibData}
 
65
        @ivar images: library L{image<Image.Image>} data
 
66
        @type images: L{LibData}
 
67
        @ivar lattices: library L{lattice<Lattice.Lattice>} data
 
68
        @type lattices: L{LibData}
 
69
        @ivar lamps: library L{lamp<Lamp.Lamp>} data
 
70
        @type lamps: L{LibData}
 
71
        @ivar cameras: library L{camera<Camera.Camera>} data
 
72
        @type cameras: L{LibData}
 
73
        @ivar ipos: library L{ipo<Ipo.Ipo>} data
 
74
        @type ipos: L{LibData}
 
75
        @ivar worlds: library L{world<World.World>} data
 
76
        @type worlds: L{LibData}
 
77
        @ivar fonts: library L{font<Font.Font>} data
 
78
        @type fonts: L{LibData}
 
79
        @ivar texts: library L{text<Text.Text>} data
 
80
        @type texts: L{LibData}
 
81
        @ivar sounds: library L{sound<Sound.Sound>} data
 
82
        @type sounds: L{LibData}
 
83
        @ivar groups: library L{group<Group.Group>} data
 
84
        @type groups: L{LibData}
 
85
        @ivar armatures: library L{armature<Armature.Armature>} data
 
86
        @type armatures: L{LibData}
 
87
        @ivar actions: library L{action<NLA.Action>} data
 
88
        @type actions: L{LibData}
 
89
        """
 
90
 
 
91
class LibData:
 
92
        """
 
93
        Generic Library Data Access
 
94
        ===========================
 
95
        This class provides access to a specific type of library data.
 
96
        """
 
97
 
 
98
        def append(name):
 
99
                """
 
100
                Append a new datablock from a library. The new copy
 
101
                is added to the current .blend file.
 
102
 
 
103
                B{Note}: Blender Objects cannot be appended or linked without linking
 
104
                them to a scene.  For this reason, lib.objects.append() returns a
 
105
                special "wrapper object" which must be passed to Scene.objects.link()
 
106
                or bpy.scenes.active.link() in order to actually create the object.
 
107
                So the following code will not create a new object::
 
108
                        import bpy
 
109
 
 
110
                        scn= bpy.scenes.active                            # get current scene
 
111
                        lib = bpy.libraries.load('//file.blend')          # open file.blend
 
112
                        pseudoOb = lib.objects.append('Cube'))            # get an object wrapper
 
113
                But this code will::
 
114
                        import bpy
 
115
 
 
116
                        scn= bpy.scenes.active                            # get current scene
 
117
                        lib = bpy.libraries.load('//file.blend')          # open file.blend
 
118
                        pseudoOb = lib.objects.append('Cube'))            # get an object wrapper
 
119
                        ob = scn.objects.link(pseudoOb)                                   # link to scene
 
120
                @rtype: Blender data
 
121
                @return: return a Blender datablock or object
 
122
                @raise IOError: library cannot be read
 
123
                @raise ValueError: library does not contain B{name}
 
124
                """
 
125
        
 
126
        def link(name):
 
127
                """
 
128
                Link a new datablock from a library.  The linked data is not copied
 
129
                into the local .blend file.
 
130
 
 
131
                See L{append} for notes on special handling of Blender Objects.
 
132
                @rtype: Blender data
 
133
                @return: return a Blender datablock or object
 
134
                @raise IOError: library cannot be read
 
135
                @raise ValueError: library does not contain B{name}
 
136
                """
 
137