py api
authorCampbell Barton <ideasman42@gmail.com>
Tue, 27 Mar 2007 14:49:37 +0000 (14:49 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 27 Mar 2007 14:49:37 +0000 (14:49 +0000)
bpy.*libBlickSeq*.new() - name is now an optiona arg.
moved some more scripts to bpy.* api.

release/scripts/3ds_import.py
release/scripts/bpymodules/BPyImage.py
release/scripts/bvh_import.py
release/scripts/import_obj.py
source/blender/python/api2_2x/BPyModule.c
source/blender/python/api2_2x/doc/Bpy.py

index 6cec591ac4f3bd13c067afce41e4885e09a67ac6..2931e45c2746d1f037e4656c99cb1a13b7a1a376 100644 (file)
@@ -143,7 +143,7 @@ BOUNDS_3DS= []
 #which shold be more useful.
 
 def createBlenderTexture(material, name, image):
-       texture= Texture.New(name)
+       texture= bpy.textures.new(name)
        texture.setType('Image')
        texture.image= image
        material.setTexture(0, texture, Texture.TexCo.UV, Texture.MapTo.COL)
@@ -365,8 +365,8 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
                        vertsToUse = [i for i in xrange(len(myContextMesh_vertls)) if faceVertUsers[i]]
                        myVertMapping = dict( [ (ii, i) for i, ii in enumerate(vertsToUse) ] )
                        
-                       ##bmesh = Mesh.New(contextMesh.name)
-                       bmesh = Mesh.New()
+                       tempName= '%s_%s' % (contextObName, matName) # matName may be None.
+                       bmesh = bpy.meshes.new(tempName)
                        
                        if matName == None:
                                img= None
@@ -398,12 +398,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
                                                if img:
                                                        targetFace.image= img
                        
-                       tempName= '%s_%s' % (contextObName, matName) # matName may be None.
-                       bmesh.name= tempName
-                       
                        # bmesh.transform(contextMatrix)
-                       # ob = Object.New('Mesh', tempName)
-                       # ob.link(bmesh)
                        ob = SCN_OBJECTS.new(bmesh, tempName)
                        '''
                        if contextMatrix_tx:
@@ -466,7 +461,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
                #is it a material chunk?
                elif (new_chunk.ID==MATERIAL):
                        #print 'elif (new_chunk.ID==MATERIAL):'
-                       contextMaterial= Material.New()
+                       contextMaterial= bpy.materials.new('Material')
                
                elif (new_chunk.ID==MAT_NAME):
                        #print 'elif (new_chunk.ID==MAT_NAME):'
@@ -525,7 +520,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
                        
                elif (new_chunk.ID==MAT_TEXTURE_MAP):
                        #print 'elif (new_chunk.ID==MAT_TEXTURE_MAP):'
-                       new_texture= Blender.Texture.New('Diffuse')
+                       new_texture= bpy.textures.new('Diffuse')
                        new_texture.setType('Image')
                        img = None
                        while (new_chunk.bytes_read<new_chunk.length):
@@ -549,7 +544,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
                        
                elif (new_chunk.ID==MAT_SPECULAR_MAP):
                        #print 'elif (new_chunk.ID==MAT_SPECULAR_MAP):'
-                       new_texture= Blender.Texture.New('Specular')
+                       new_texture= bpy.textures.new('Specular')
                        new_texture.setType('Image')
                        img = None
                        while (new_chunk.bytes_read<new_chunk.length):
@@ -571,7 +566,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
        
                elif (new_chunk.ID==MAT_OPACITY_MAP):
                        #print 'new_texture=Blender.Texture.New('Opacity')'
-                       new_texture= Blender.Texture.New('Opacity')
+                       new_texture= bpy.textures.new('Opacity')
                        new_texture.setType('Image')
                        img = None
                        while (new_chunk.bytes_read<new_chunk.length):
@@ -592,7 +587,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
 
                elif (new_chunk.ID==MAT_BUMP_MAP):
                        #print 'elif (new_chunk.ID==MAT_BUMP_MAP):'
-                       new_texture= Blender.Texture.New('Bump')
+                       new_texture= bpy.textures.new('Bump')
                        new_texture.setType('Image')
                        img = None
                        while (new_chunk.bytes_read<new_chunk.length):
@@ -624,20 +619,17 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
 
                elif (new_chunk.ID==OBJECT_LAMP): # Basic lamp support.
                        
-                       #print 'LAMP!!!!!!!!!'
                        temp_data=file.read(STRUCT_SIZE_3FLOAT)
                        
                        x,y,z=unpack('<3f', temp_data)
                        new_chunk.bytes_read+=STRUCT_SIZE_3FLOAT
                        
-                       contextLamp[0]= Object.New('Lamp')
-                       contextLamp[1]= Lamp.New()
+                       contextLamp[1]= bpy.lamps.new()
+                       contextLamp[0]= SCN_OBJECTS.link(contextLamp[1])
                        contextLamp[0].link(contextLamp[1])
                        ##scn.link(contextLamp[0])
                        importedObjects.append(contextLamp[0])
                        
-                       
-                       
                        #print 'number of faces: ', num_faces
                        #print x,y,z
                        contextLamp[0].setLocation(x,y,z)
index 7f6de5366c632c063fc325bfc48b40a8651e5d5d..ac61264662f7021a3ec1380e082af4de153d3917 100644 (file)
@@ -26,7 +26,7 @@
 # Comprehensive image loader, will search and find the image                #
 # Will return a blender image or a new image if the image is missing        #
 #===========================================================================#
-import Blender
+import bpy
 from Blender import sys
 try:
        import os
@@ -101,7 +101,7 @@ def comprehensiveImageLoad(imagePath, filePath, PLACE_HOLDER= True, RECURSIVE=Tr
                #if path.endswith('\\') or path.endswith('/'):
                #       raise 'INVALID PATH'
                try:
-                       img = Blender.Image.Load(path)
+                       img = bpy.images.new(filename=path)
                        if VERBOSE: print '\t\tImage loaded "%s"' % path
                        return img
                except:
@@ -109,7 +109,7 @@ def comprehensiveImageLoad(imagePath, filePath, PLACE_HOLDER= True, RECURSIVE=Tr
                                if sys.exists(path): print '\t\tImage failed loading "%s", mabe its not a format blender can read.' % (path)
                                else: print '\t\tImage not found, making a place holder "%s"' % (path)
                        if PLACE_HOLDER:
-                               img= Blender.Image.New(stripPath(path),1,1,24)
+                               img= bpy.images.new(stripPath(path),4,4)
                                img.filename= path
                                return img #blank image
                        else:
@@ -123,7 +123,7 @@ def comprehensiveImageLoad(imagePath, filePath, PLACE_HOLDER= True, RECURSIVE=Tr
        imageFileName_lower =  imageFileName.lower() # image path only
        
        if VERBOSE: print '\tSearchingExisting Images for "%s"' % imagePath
-       for i in Blender.Image.Get():
+       for i in bpy.images:
                if stripPath(i.filename.lower()) == imageFileName_lower:
                        if VERBOSE: print '\t\tUsing existing image.'
                        return i
@@ -188,7 +188,7 @@ def comprehensiveImageLoad(imagePath, filePath, PLACE_HOLDER= True, RECURSIVE=Tr
        else:
                if VERBOSE: print '\tNo Path: "%s"' % tmpPath
 
-       tmpPath = addSlash(Blender.Get('texturesdir'))
+       tmpPath = addSlash(bpy.config.textureDir)
        if tmpPath and sys.exists(tmpPath):
                if VERBOSE: print '\t\tSearching in %s' % tmpPath
                paths[tmpPath] = [os.listdir(tmpPath)] # Orig name for loading 
index 68e4bf3aac48df0ad948280e136ef45627e3984f..8d54a9e0fe54f86103c5c1c939310cdb4821c19d 100644 (file)
@@ -358,10 +358,9 @@ def bvh_node_dict2objects(bvh_nodes, IMPORT_START_FRAME= 1, IMPORT_LOOP= False):
        
        scn.update(1)
        return objects
-       
 
 
-#TODO, armature loading
+
 def bvh_node_dict2armature(bvh_nodes, IMPORT_START_FRAME= 1, IMPORT_LOOP= False):
        
        if IMPORT_START_FRAME<1:
@@ -369,10 +368,13 @@ def bvh_node_dict2armature(bvh_nodes, IMPORT_START_FRAME= 1, IMPORT_LOOP= False)
                
        
        # Add the new armature, 
-       arm_ob= Blender.Object.New('Armature')
-       arm_data= Blender.Armature.Armature('myArmature')
-       arm_ob.link(arm_data)
+       scn = bpy.scenes.active
+       scn.objects.selected = []
        
+       arm_data= bpy.armatures.new()
+       arm_ob = scn.objects.new(arm_data)
+       scn.objects.context = [arm_ob]
+       scn.objects.active = arm_ob
        
        # Put us into editmode
        arm_data.makeEditable()
@@ -441,15 +443,6 @@ def bvh_node_dict2armature(bvh_nodes, IMPORT_START_FRAME= 1, IMPORT_LOOP= False)
        
        arm_data.update()
        
-       
-       
-       scn= bpy.scenes.active
-       
-       scn.objects.selected = []
-       
-       scn.link(arm_ob)
-       scn.objects.context = [arm_ob]
-       
        # Now Apply the animation to the armature
        
        # Get armature animation data
index 6c66b2097a887f434e149929891c019e209a043f..699be0a265ea0f8ccc6450f5326fd08bd799a653 100644 (file)
@@ -41,6 +41,7 @@ Note, This loads mesh objects and materials only, nurbs and curves are not suppo
 # --------------------------------------------------------------------------
 
 from Blender import *
+import bpy
 import BPyMesh
 import BPyImage
 import BPyMessages
@@ -117,7 +118,7 @@ def create_materials(filepath, material_libs, unique_materials, unique_material_
        #==================================================================================#
        def load_material_image(blender_material, context_material_name, imagepath, type):
                
-               texture= Texture.New(type)
+               texture= bpy.textures.new(type)
                texture.setType('Image')
                
                # Absolute path - c:\.. etc would work here
@@ -167,7 +168,7 @@ def create_materials(filepath, material_libs, unique_materials, unique_material_
        
        #Create new materials
        for name in unique_materials.iterkeys():
-               unique_materials[name]= Material.New(name)
+               unique_materials[name]= bpy.materials.new(name)
                
                unique_material_images[name]= None, False # assign None to all material images to start with, add to later.
                
@@ -426,7 +427,7 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v
        for name, index in material_mapping.iteritems():
                materials[index]= unique_materials[name]
        
-       me= Mesh.New(dataname)
+       me= bpy.meshes.new(dataname)
        
        me.materials= materials[0:16] # make sure the list isnt too big.
        #me.verts.extend([(0,0,0)]) # dummy vert
@@ -796,7 +797,7 @@ def load_obj_ui(filepath, BATCH_LOAD= False):
                        return
                
                for f in files:
-                       scn= Scene.New( stripExt(f) )
+                       scn= bpy.scenes.new( stripExt(f) )
                        scn.makeCurrent()
                        
                        load_obj(sys.join(filepath, f),\
@@ -861,7 +862,7 @@ else:
                        _obj= _obj[:-1]
                        print 'Importing', _obj, '\nNUMBER', i, 'of', len(lines)
                        _obj_file= _obj.split('/')[-1].split('\\')[-1]
-                       newScn= Scene.New(_obj_file)
+                       newScn= bpy.scenes.new(_obj_file)
                        newScn.makeCurrent()
                        load_obj(_obj, False)
 
index 8ca3f28912c077641fd8dad3fcd72300f98625bf..8c85324bde424d7c67028d89b0e561f8c0b24301 100644 (file)
@@ -457,7 +457,7 @@ PyObject *LibBlockSeq_new(BPy_LibBlockSeq *self, PyObject * args, PyObject *kwd)
        /* New Data */
        if (self->type == ID_IM) {
                /* Image, accepts width and height*/
-               if( !PyArg_ParseTuple( args, "s|ii", &name, &img_width, &img_height ) )
+               if( !PyArg_ParseTuple( args, "|sii", &name, &img_width, &img_height ) )
                        return EXPP_ReturnPyObjError( PyExc_TypeError,
                                "one string and two ints expected as arguments" );
                CLAMP(img_width,  4, 5000);
@@ -497,7 +497,7 @@ PyObject *LibBlockSeq_new(BPy_LibBlockSeq *self, PyObject * args, PyObject *kwd)
                
        } else {
                /* Other types only need the name */
-               if( !PyArg_ParseTuple( args, "s", &name ) )
+               if( !PyArg_ParseTuple( args, "|s", &name ) )
                        return EXPP_ReturnPyObjError( PyExc_TypeError,
                                "new(name) - name must be a string argument" );
        }
index 8ba9ef204692e158219e8c1fdd278cbd3f2e2b38..8f95a84dbe53a55b40cab035e73e7763260f79d2 100644 (file)
@@ -132,7 +132,6 @@ Example::
 @type actions: L{libBlockSeq}
 @var libraries: L{librarySeq<LibData>} submodule
 @type libraries: L{librarySeq<LibData>}
-
 """
 
 
@@ -218,6 +217,10 @@ class libBlockSeq:
                
                Most datatypes accept a name for their argument except for L{sounds}, L{fonts}, L{ipos} and L{curves} that need an additional argument.
                
+               The name argument is optional if not given a default name will be assigned.
+               
+               The name given may be modified by blender to make it unique.
+               
                Loading From File
                =================
                For L{images}, L{texts}, L{sounds}, L{fonts} types you can use the filename keyword to make a new datablock from a file.