diff options
author | Campbell Barton <ideasman42@gmail.com> | 2007-04-18 18:40:01 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2007-04-18 18:40:01 +0400 |
commit | 3e1a5ce7a2596ebc135455f9934d128223cc089a (patch) | |
tree | e9d12a0e39c1de8e33e2b32965a91d8bd90a18c1 | |
parent | a59f7c08cef1fd4f0ce60463fe93eb53a8dadffa (diff) |
PyAPI.
moved bpy into bpy.data and bpy will be eventually replace the root level 'Blender' module.
currently we have bpy.library bpy.config and bpy.data
31 files changed, 227 insertions, 106 deletions
diff --git a/release/scripts/3ds_export.py b/release/scripts/3ds_export.py index 7cf7bb2cf5e..7742a9d3430 100644 --- a/release/scripts/3ds_export.py +++ b/release/scripts/3ds_export.py @@ -878,7 +878,7 @@ def save_3ds(filename): time1= Blender.sys.time() Blender.Window.WaitCursor(1) - scn= bpy.scenes.active + scn= bpy.data.scenes.active # Initialize the main chunk (primary): primary = _3ds_chunk(PRIMARY) diff --git a/release/scripts/3ds_import.py b/release/scripts/3ds_import.py index 2931e45c274..28220db4b82 100644 --- a/release/scripts/3ds_import.py +++ b/release/scripts/3ds_import.py @@ -143,7 +143,7 @@ BOUNDS_3DS= [] #which shold be more useful. def createBlenderTexture(material, name, image): - texture= bpy.textures.new(name) + texture= bpy.data.textures.new(name) texture.setType('Image') texture.image= image material.setTexture(0, texture, Texture.TexCo.UV, Texture.MapTo.COL) @@ -366,7 +366,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH): myVertMapping = dict( [ (ii, i) for i, ii in enumerate(vertsToUse) ] ) tempName= '%s_%s' % (contextObName, matName) # matName may be None. - bmesh = bpy.meshes.new(tempName) + bmesh = bpy.data.meshes.new(tempName) if matName == None: img= None @@ -461,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= bpy.materials.new('Material') + contextMaterial= bpy.data.materials.new('Material') elif (new_chunk.ID==MAT_NAME): #print 'elif (new_chunk.ID==MAT_NAME):' @@ -520,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= bpy.textures.new('Diffuse') + new_texture= bpy.data.textures.new('Diffuse') new_texture.setType('Image') img = None while (new_chunk.bytes_read<new_chunk.length): @@ -544,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= bpy.textures.new('Specular') + new_texture= bpy.data.textures.new('Specular') new_texture.setType('Image') img = None while (new_chunk.bytes_read<new_chunk.length): @@ -566,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= bpy.textures.new('Opacity') + new_texture= bpy.data.textures.new('Opacity') new_texture.setType('Image') img = None while (new_chunk.bytes_read<new_chunk.length): @@ -587,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= bpy.textures.new('Bump') + new_texture= bpy.data.textures.new('Bump') new_texture.setType('Image') img = None while (new_chunk.bytes_read<new_chunk.length): @@ -624,7 +624,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH): x,y,z=unpack('<3f', temp_data) new_chunk.bytes_read+=STRUCT_SIZE_3FLOAT - contextLamp[1]= bpy.lamps.new() + contextLamp[1]= bpy.data.lamps.new() contextLamp[0]= SCN_OBJECTS.link(contextLamp[1]) contextLamp[0].link(contextLamp[1]) ##scn.link(contextLamp[0]) @@ -857,7 +857,7 @@ def load_3ds(filename, PREF_UI= True): ##IMAGE_SEARCH - scn= bpy.scenes.active + scn= bpy.data.scenes.active SCN_OBJECTS = scn.objects SCN_OBJECTS.selected = [] # de select all diff --git a/release/scripts/armature_symmetry.py b/release/scripts/armature_symmetry.py index 8d861aaf72d..5ee4e086fb0 100644 --- a/release/scripts/armature_symmetry.py +++ b/release/scripts/armature_symmetry.py @@ -248,7 +248,7 @@ def main(): User interface function that gets the options and calls armature_symetry() ''' - scn= bpy.scenes.active + scn= bpy.data.scenes.active arm_ob= scn.objects.active if not arm_ob or arm_ob.type!='Armature': diff --git a/release/scripts/bpymodules/BPyAddMesh.py b/release/scripts/bpymodules/BPyAddMesh.py index 0000dec144e..c11d178d4fb 100644 --- a/release/scripts/bpymodules/BPyAddMesh.py +++ b/release/scripts/bpymodules/BPyAddMesh.py @@ -12,7 +12,7 @@ def add_mesh_simple(name, verts, edges, faces): faces - list of int triplets/quads ''' - scn = bpy.scenes.active + scn = bpy.data.scenes.active if scn.lib: return ob_act = scn.objects.active @@ -67,7 +67,7 @@ def add_mesh_simple(name, verts, edges, faces): # Object mode add new - me = bpy.meshes.new(name) + me = bpy.data.meshes.new(name) me.verts.extend(verts) me.edges.extend(edges) me.faces.extend(faces) @@ -137,7 +137,7 @@ import bpy def main(): # Add error checking - scn = bpy.scenes.active + scn = bpy.data.scenes.active ob = scn.objects.active me = ob.getData(mesh=1) diff --git a/release/scripts/bpymodules/BPyImage.py b/release/scripts/bpymodules/BPyImage.py index ac61264662f..2c342ddec39 100644 --- a/release/scripts/bpymodules/BPyImage.py +++ b/release/scripts/bpymodules/BPyImage.py @@ -101,7 +101,7 @@ def comprehensiveImageLoad(imagePath, filePath, PLACE_HOLDER= True, RECURSIVE=Tr #if path.endswith('\\') or path.endswith('/'): # raise 'INVALID PATH' try: - img = bpy.images.new(filename=path) + img = bpy.data.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= bpy.images.new(stripPath(path),4,4) + img= bpy.data.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 bpy.images: + for i in bpy.data.images: if stripPath(i.filename.lower()) == imageFileName_lower: if VERBOSE: print '\t\tUsing existing image.' return i diff --git a/release/scripts/bpymodules/BPyMesh.py b/release/scripts/bpymodules/BPyMesh.py index de7b88b056a..f04c3531f3e 100644 --- a/release/scripts/bpymodules/BPyMesh.py +++ b/release/scripts/bpymodules/BPyMesh.py @@ -385,9 +385,9 @@ def getMeshFromObject(ob, container_mesh=None, apply_modifiers=True, vgroups=Tru ''' if not scn: - scn= bpy.scenes.active + scn= bpy.data.scenes.active if not container_mesh: - mesh = bpy.meshes.new(ob.name) + mesh = bpy.data.meshes.new(ob.name) else: mesh= container_mesh mesh.verts= None diff --git a/release/scripts/bpymodules/BPyMesh_redux.py b/release/scripts/bpymodules/BPyMesh_redux.py index 4c45a3846a4..1bcc6e9f7c8 100644 --- a/release/scripts/bpymodules/BPyMesh_redux.py +++ b/release/scripts/bpymodules/BPyMesh_redux.py @@ -643,7 +643,7 @@ def redux(ob, REDUX=0.5, BOUNDRY_WEIGHT=2.0, REMOVE_DOUBLES=False, FACE_AREA_WEI # Example usage def main(): Blender.Window.EditMode(0) - scn= bpy.scenes.active + scn= bpy.data.scenes.active active_ob= scn.objects.active t= Blender.sys.time() redux(active_ob, 0.5) diff --git a/release/scripts/bvh_import.py b/release/scripts/bvh_import.py index 8d54a9e0fe5..17d905842ac 100644 --- a/release/scripts/bvh_import.py +++ b/release/scripts/bvh_import.py @@ -311,7 +311,7 @@ def bvh_node_dict2objects(bvh_nodes, IMPORT_START_FRAME= 1, IMPORT_LOOP= False): if IMPORT_START_FRAME<1: IMPORT_START_FRAME= 1 - scn= bpy.scenes.active + scn= bpy.data.scenes.active scn.objects.selected = [] objects= [] @@ -368,10 +368,10 @@ def bvh_node_dict2armature(bvh_nodes, IMPORT_START_FRAME= 1, IMPORT_LOOP= False) # Add the new armature, - scn = bpy.scenes.active + scn = bpy.data.scenes.active scn.objects.selected = [] - arm_data= bpy.armatures.new() + arm_data= bpy.data.armatures.new() arm_ob = scn.objects.new(arm_data) scn.objects.context = [arm_ob] scn.objects.active = arm_ob @@ -743,7 +743,7 @@ def main(): if __name__ == '__main__': main() ''' - scn = bpy.scenes.active + scn = bpy.data.scenes.active for ob in list(scn.objects): scn.objects.unlink(ob) load_bvh_ui('/test.bvh', False) ''' diff --git a/release/scripts/console.py b/release/scripts/console.py index ee4b132e2e1..4b187b6684d 100644 --- a/release/scripts/console.py +++ b/release/scripts/console.py @@ -174,7 +174,7 @@ def writeCmdData(cmdLineList, type): Draw.PupMenu('%s written' % newText.name) def insertCmdData(cmdBuffer): - texts = list(bpy.texts) + texts = list(bpy.data.texts) textNames = [tex.name for tex in texts] if textNames: choice = Draw.PupMenu('|'.join(textNames)) diff --git a/release/scripts/import_obj.py b/release/scripts/import_obj.py index 04b8bd42592..8b76335f686 100644 --- a/release/scripts/import_obj.py +++ b/release/scripts/import_obj.py @@ -118,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= bpy.textures.new(type) + texture= bpy.data.textures.new(type) texture.setType('Image') # Absolute path - c:\.. etc would work here @@ -168,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]= bpy.materials.new(name) + unique_materials[name]= bpy.data.materials.new(name) unique_material_images[name]= None, False # assign None to all material images to start with, add to later. @@ -432,7 +432,7 @@ def create_mesh(scn, new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_l for name, index in material_mapping.iteritems(): materials[index]= unique_materials[name] - me= bpy.meshes.new(dataname) + me= bpy.data.meshes.new(dataname) me.materials= materials[0:16] # make sure the list isnt too big. #me.verts.extend([(0,0,0)]) # dummy vert @@ -706,7 +706,7 @@ def load_obj(filepath, CLAMP_SIZE= 0.0, CREATE_FGONS= True, CREATE_SMOOTH_GROUPS # deselect all - scn = bpy.scenes.active + scn = bpy.data.scenes.active scn.objects.selected = [] new_objects= [] # put new objects here @@ -805,7 +805,7 @@ def load_obj_ui(filepath, BATCH_LOAD= False): return for f in files: - scn= bpy.scenes.new( stripExt(f) ) + scn= bpy.data.scenes.new( stripExt(f) ) scn.makeCurrent() load_obj(sys.join(filepath, f),\ @@ -870,7 +870,7 @@ else: _obj= _obj[:-1] print 'Importing', _obj, '\nNUMBER', i, 'of', len(lines) _obj_file= _obj.split('/')[-1].split('\\')[-1] - newScn= bpy.scenes.new(_obj_file) + newScn= bpy.data.scenes.new(_obj_file) newScn.makeCurrent() load_obj(_obj, False) diff --git a/release/scripts/lightwave_import.py b/release/scripts/lightwave_import.py index e2fc7d0cc95..14974878e4b 100644 --- a/release/scripts/lightwave_import.py +++ b/release/scripts/lightwave_import.py @@ -149,7 +149,7 @@ def read(filename): print "This is: %s" % importername print "Importing file:", filename - bpy.scenes.active.objects.selected = [] + bpy.data.scenes.active.objects.selected = [] start = Blender.sys.time() file = open(filename, "rb") @@ -208,7 +208,7 @@ def read_lwob(file, filename): objspec_list = None #add default material for orphaned faces, if any - surf_list.append({'NAME': "_Orphans", 'g_MAT': bpy.materials.new("_Orphans")}) + surf_list.append({'NAME': "_Orphans", 'g_MAT': bpy.data.materials.new("_Orphans")}) #pass 2: effectively generate objects ###if DEBUG: print "Pass 1: dry import" @@ -344,7 +344,7 @@ def read_lwo2(file, filename, typ="LWO2"): lwochunk.skip() #add default material for orphaned faces, if any - surf_list.append({'NAME': "_Orphans", 'g_MAT': bpy.materials.new("_Orphans")}) + surf_list.append({'NAME': "_Orphans", 'g_MAT': bpy.data.materials.new("_Orphans")}) #pass 2: effectively generate objects ###if DEBUG: print "Pass 2: now for the hard part" @@ -1000,7 +1000,7 @@ def read_surfs(lwochunk, surf_list, tag_list): pass #uncomment this if material pre-allocated by read_surf - my_dict['g_MAT'] = bpy.materials.new(my_dict['NAME']) + my_dict['g_MAT'] = bpy.data.materials.new(my_dict['NAME']) ###if DEBUG: print "-> Material pre-allocated." return my_dict @@ -1097,8 +1097,8 @@ def my_create_mesh(clip_list, surf, objspec_list, current_facelist, objname, not #end loop on faces store_edge = 0 - scn= bpy.scenes.active - msh = bpy.meshes.new() + scn= bpy.data.scenes.active + msh = bpy.data.meshes.new() obj = scn.objects.new(msh) mat = None @@ -1431,7 +1431,7 @@ def create_blok(surf, mat, clip_list, obj_size, obj_pos): tname += "x" #let's signal when should not be enabled if blok.has_key('CHAN'): tname += blok['CHAN'] - newtex = bpy.textures.new(tname) + newtex = bpy.data.textures.new(tname) newtex.setType('Image') # make it anu image texture newtex.image = img #how does it extends beyond borders @@ -1705,8 +1705,8 @@ for i, _lwo in enumerate(lines): _lwo= _lwo[:-1] print 'Importing', _lwo, '\nNUMBER', i, 'of', len(lines) _lwo_file= _lwo.split('/')[-1].split('\\')[-1] - newScn= bpy.scenes.new(_lwo_file) - bpy.scenes.active = newScn + newScn= bpy.data.scenes.new(_lwo_file) + bpy.data.scenes.active = newScn size += ((os.path.getsize(_lwo)/1024.0))/ 1024.0 read(_lwo) # Remove objects to save memory? diff --git a/release/scripts/mesh_skin.py b/release/scripts/mesh_skin.py index c417e2059ed..6840b44f6e2 100644 --- a/release/scripts/mesh_skin.py +++ b/release/scripts/mesh_skin.py @@ -521,7 +521,7 @@ def main(): is_editmode = Window.EditMode() if is_editmode: Window.EditMode(0) - ob = bpy.scenes.active.objects.active + ob = bpy.data.scenes.active.objects.active if ob == None or ob.type != 'Mesh': BPyMessages.Error_NoMeshActive() return diff --git a/release/scripts/mesh_solidify.py b/release/scripts/mesh_solidify.py index aa05b2b3d50..9e11ed68c63 100644 --- a/release/scripts/mesh_solidify.py +++ b/release/scripts/mesh_solidify.py @@ -299,7 +299,7 @@ def solidify(me, PREF_THICK, PREF_SKIN_SIDES=True, PREF_REM_ORIG=False, PREF_COL def main(): - scn = bpy.scenes.active + scn = bpy.data.scenes.active ob = scn.objects.active if not ob or ob.type != 'Mesh': diff --git a/release/scripts/mesh_wire.py b/release/scripts/mesh_wire.py index b98de7d218d..35cfa325497 100644 --- a/release/scripts/mesh_wire.py +++ b/release/scripts/mesh_wire.py @@ -235,7 +235,7 @@ def solid_wire(ob_orig, me_orig, sce, PREF_THICKNESS, PREF_SOLID, PREF_SHARP, PR def main(): # Gets the current scene, there can be many scenes in 1 blend file. - sce = bpy.scenes.active + sce = bpy.data.scenes.active # Get the active object, there can only ever be 1 # and the active object is always the editmode object. diff --git a/release/scripts/object_apply_def.py b/release/scripts/object_apply_def.py index e7cdf4089b1..67e4179a674 100644 --- a/release/scripts/object_apply_def.py +++ b/release/scripts/object_apply_def.py @@ -86,7 +86,7 @@ def copy_vgroups(source_ob, target_ob): def apply_deform(): - scn= bpy.scenes.active + scn= bpy.data.scenes.active #Blender.Window.EditMode(0) NAME_LENGTH = 19 diff --git a/release/scripts/object_batch_name_edit.py b/release/scripts/object_batch_name_edit.py index d9725c66ea8..e89494af21a 100644 --- a/release/scripts/object_batch_name_edit.py +++ b/release/scripts/object_batch_name_edit.py @@ -47,7 +47,7 @@ import bpy global renameCount renameCount = 0 -obsel = bpy.scenes.active.objects.context +obsel = bpy.data.scenes.active.objects.context def setDataNameWrapper(ob, newname): if ob.getData(name_only=1) == newname: diff --git a/release/scripts/object_find.py b/release/scripts/object_find.py index a52f6810da9..4ce93998f00 100644 --- a/release/scripts/object_find.py +++ b/release/scripts/object_find.py @@ -109,7 +109,7 @@ def main(): NAME_TEXTURE = NAME_TEXTURE.lower() def activate(ob, scn): - bpy.scenes.active = scn + bpy.data.scenes.active = scn scn.objects.selected = [] scn.Layers = ob.Layers ob.sel = 1 @@ -131,10 +131,10 @@ def main(): if NAME_INGROUP: # Best we speed this up. - bpy.objects.tag = False + bpy.data.objects.tag = False ok = False - for group in bpy.groups: + for group in bpy.data.groups: if name_cmp(NAME_INGROUP, group.name): for ob in group.objects: ob.tag = True @@ -143,7 +143,7 @@ def main(): Draw.PupMenu('No Objects Found') return - for scn in bpy.scenes: + for scn in bpy.data.scenes: for ob in scn.objects: if NAME_DATA: if name_cmp(NAME_DATA, ob.getData(1)): @@ -152,7 +152,7 @@ def main(): if NAME_INGROUP: # Crap and slow but not much we can do about that ''' - for group in bpy.groups: + for group in bpy.data.groups: if name_cmp(NAME_INGROUP, group.name): for ob_group in group.objects: if ob == ob_group: diff --git a/release/scripts/scripttemplate_mesh_edit.py b/release/scripts/scripttemplate_mesh_edit.py index 07220205e71..e94b139a92d 100644 --- a/release/scripts/scripttemplate_mesh_edit.py +++ b/release/scripts/scripttemplate_mesh_edit.py @@ -55,7 +55,7 @@ def my_mesh_util(me): def main(): # Gets the current scene, there can be many scenes in 1 blend file. - sce = bpy.scenes.active + sce = bpy.data.scenes.active # Get the active object, there can only ever be 1 # and the active object is always the editmode object. @@ -91,7 +91,7 @@ if __name__ == '__main__': main() ''' -new_text = bpy.texts.new('mesh_template.py') +new_text = bpy.data.texts.new('mesh_template.py') new_text.write(script_data) -bpy.texts.active = new_text +bpy.data.texts.active = new_text Window.RedrawAll()
\ No newline at end of file diff --git a/release/scripts/uvcalc_follow_active_coords.py b/release/scripts/uvcalc_follow_active_coords.py index 2a6648ab4e6..fc91c0b648a 100644 --- a/release/scripts/uvcalc_follow_active_coords.py +++ b/release/scripts/uvcalc_follow_active_coords.py @@ -43,7 +43,7 @@ import bpy import BPyMesh def extend(): - scn = bpy.scenes.active + scn = bpy.data.scenes.active ob = scn.objects.active # print ob, ob.type diff --git a/release/scripts/uvcalc_from_adjacent.py b/release/scripts/uvcalc_from_adjacent.py index e5cd64fe5b0..b4ed25868df 100644 --- a/release/scripts/uvcalc_from_adjacent.py +++ b/release/scripts/uvcalc_from_adjacent.py @@ -70,7 +70,7 @@ def mostUsedImage(imageList): # Returns the image most used in the list. def main(): - scn = bpy.scenes.active + scn = bpy.data.scenes.active ob = scn.objects.active if ob == None or ob.type != 'Mesh': Draw.PupMenu('ERROR: No mesh object in face select mode.') diff --git a/release/scripts/uvcalc_lightmap.py b/release/scripts/uvcalc_lightmap.py index 9fda4d44f85..64eb1bb4e75 100644 --- a/release/scripts/uvcalc_lightmap.py +++ b/release/scripts/uvcalc_lightmap.py @@ -505,7 +505,7 @@ PREF_MARGIN_DIV= 512): Window.RedrawAll() def main(): - scn = bpy.scenes.active + scn = bpy.data.scenes.active PREF_ACT_ONLY = Draw.Create(1) PREF_SEL_ONLY = Draw.Create(1) diff --git a/release/scripts/uvcalc_quad_clickproj.py b/release/scripts/uvcalc_quad_clickproj.py index 760d9ab2767..84c54ae30da 100644 --- a/release/scripts/uvcalc_quad_clickproj.py +++ b/release/scripts/uvcalc_quad_clickproj.py @@ -75,7 +75,7 @@ def mousedown_wait(): def main(): - scn = bpy.scenes.active + scn = bpy.data.scenes.active ob = scn.objects.active if not ob or ob.type!='Mesh': return diff --git a/release/scripts/uvcalc_smart_project.py b/release/scripts/uvcalc_smart_project.py index ae6ffacf593..9f40b63b67e 100644 --- a/release/scripts/uvcalc_smart_project.py +++ b/release/scripts/uvcalc_smart_project.py @@ -827,7 +827,7 @@ def main(): global USER_STRETCH_ASPECT global USER_ISLAND_MARGIN - objects= bpy.scenes.active.objects + objects= bpy.data.scenes.active.objects # we can will tag them later. obList = [ob for ob in objects.context if ob.type == 'Mesh'] @@ -922,7 +922,7 @@ def main(): time1 = sys.time() # Tag as False se we dont operate on teh same mesh twice. - bpy.meshes.tag = False + bpy.data.meshes.tag = False for ob in obList: me = ob.getData(mesh=1) diff --git a/release/scripts/widgetwizard.py b/release/scripts/widgetwizard.py index 48168e11681..8facf115d9e 100644 --- a/release/scripts/widgetwizard.py +++ b/release/scripts/widgetwizard.py @@ -104,7 +104,7 @@ def delCurve(ipo): def verifyIpocurve(ky,index): ipo = ky.ipo if ipo == None: - nip = bpy.ipos.new("keyipo", "Key") + nip = bpy.data.ipos.new("keyipo", "Key") ky.ipo = nip ipo = ky.ipo if index == 0: @@ -378,7 +378,7 @@ def setupDrivers(ob,ctrl,type): def build(type): global shapes,widmenu,rangename - sce = bpy.scenes.active + sce = bpy.data.scenes.active ob = sce.objects.active try: @@ -410,7 +410,7 @@ def build(type): #Create the text def makeText(sce, name): - txt = bpy.curves.new(name+'.name', 'Text3d') + txt = bpy.data.curves.new(name+'.name', 'Text3d') txt.setDrawMode(Text3d.DRAW3D) txt.setAlignment(Text3d.MIDDLE) @@ -423,7 +423,7 @@ def makeText(sce, name): #Create the mesh controller def makeController(sce, name): - me = bpy.meshes.new(name+".ctrl") + me = bpy.data.meshes.new(name+".ctrl") ob = sce.objects.new(me) me.verts.extend([\ (-0.15,0, 0),\ @@ -438,7 +438,7 @@ def makeController(sce, name): def makeRange(sce,type,name): #ob.setDrawMode(8) # Draw Name - me = bpy.meshes.new(name) + me = bpy.data.meshes.new(name) ob = sce.objects.new(me) if type == SHAPE1_ONE_ZERO: @@ -581,7 +581,7 @@ EVENT_BACK = 103 #get the list of shapes from the selected object def shapeMenuText(): - ob = bpy.scenes.active.objects.active + ob = bpy.data.scenes.active.objects.active if not ob: return "" diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c index 9bead926b92..be4bc690d97 100644 --- a/source/blender/python/BPY_interface.c +++ b/source/blender/python/BPY_interface.c @@ -66,7 +66,7 @@ #include "api2_2x/Draw.h" #include "api2_2x/Object.h" #include "api2_2x/Registry.h" -#include "api2_2x/BPyModule.h" /* for the "bpy" default module */ +#include "api2_2x/bpy.h" /* for the new "bpy" module */ /* for scriptlinks */ #include "DNA_lamp_types.h" @@ -81,7 +81,7 @@ * choose to preserve after they are executed, so user changes can be * restored next time the script is used. Check the Blender.Registry module. */ -//#include "api2_2x/Registry.h" +/*#include "api2_2x/Registry.h" */ /* for pydrivers (ipo drivers defined by one-line Python expressions) */ PyObject *bpy_pydriver_Dict = NULL; @@ -118,7 +118,7 @@ int setup_armature_weakrefs() static struct _inittab BPy_Inittab_Modules[] = { {"Blender", M_Blender_Init}, - {"bpy", M_BPy_Init}, + {"bpy", m_bpy_init}, {NULL, NULL} }; diff --git a/source/blender/python/api2_2x/bpy.c b/source/blender/python/api2_2x/bpy.c new file mode 100644 index 00000000000..31dd261b610 --- /dev/null +++ b/source/blender/python/api2_2x/bpy.c @@ -0,0 +1,85 @@ +/* + * $Id$ + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * This is a new part of Blender. + * + * Contributor(s): Michel Selten, Willian P. Germano, Joseph Gilbert, + * Campbell Barton + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** +*/ + +/* for open, close in Blender_Load */ + +#include "BLI_blenlib.h" +#include "BKE_global.h" +#include "BKE_utildefines.h" +#include "BKE_scene.h" +#include "BKE_main.h" + +#include "DNA_scene_types.h" + +#include "Types.h" + +#include "bpy.h" +#include "bpy_data.h" +#include "bpy_config.h" + +/*****************************************************************************/ +/* Global variables */ +/*****************************************************************************/ +PyObject *g_bpydict; + +/*****************************************************************************/ +/* Function: initBlender */ +/*****************************************************************************/ + +void m_bpy_init(void) +{ + PyObject *module; + PyObject *dict; + + /* G.scene should only aver be NULL if blender is executed in + background mode, not loading a blend file and executing a python script eg. + blender -P somescript.py -b + The if below solves the segfaults that happen when python runs and + G.scene is NULL */ + if(G.background && G.main->scene.first==NULL) { + Scene *sce= add_scene("1"); + /*set_scene(sce);*/ /* causes a crash */ + G.scene= sce; + } + + module = Py_InitModule3("bpy", NULL, "The main bpy module"); + + types_InitAll(); /* set all our pytypes to &PyType_Type */ + + dict = PyModule_GetDict(module); + g_bpydict = dict; + + PyModule_AddObject( module, "config", Config_CreatePyObject() ); + PyDict_SetItemString( dict, "data", Data_Init()); + PyDict_SetItemString( dict, "libraries", Library_Init( ) ); + +} diff --git a/source/blender/python/api2_2x/bpy.h b/source/blender/python/api2_2x/bpy.h new file mode 100644 index 00000000000..668196d8271 --- /dev/null +++ b/source/blender/python/api2_2x/bpy.h @@ -0,0 +1,41 @@ +/* + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * This is a new part of Blender. + * + * Contributor(s): Michel Selten, Willian P. Germano + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** +*/ + +#ifndef EXPP_BPYMOD_H +#define EXPP_BPYMOD_H + +#include <Python.h> + +extern PyObject *g_bpydict; +void m_bpy_init( void ); + +#endif /* EXPP_BPYMOD_H */ diff --git a/source/blender/python/api2_2x/Config.c b/source/blender/python/api2_2x/bpy_config.c index cd081a3a4aa..bdb5e3c3b47 100644 --- a/source/blender/python/api2_2x/Config.c +++ b/source/blender/python/api2_2x/bpy_config.c @@ -32,8 +32,8 @@ /* python types */ #include "DNA_userdef_types.h" -#include "gen_utils.h" -#include "Config.h" +#include "../api2_2x/gen_utils.h" +#include "bpy_config.h" enum conf_consts { /*string*/ diff --git a/source/blender/python/api2_2x/Config.h b/source/blender/python/api2_2x/bpy_config.h index 61580a023b4..979953acd76 100644 --- a/source/blender/python/api2_2x/Config.h +++ b/source/blender/python/api2_2x/bpy_config.h @@ -30,8 +30,8 @@ * ***** END GPL/BL DUAL LICENSE BLOCK ***** */ -#ifndef EXPP_CONFIG_H -#define EXPP_CONFIG_H +#ifndef EXPP_BPY_CONFIG_H +#define EXPP_BPY_CONFIG_H #include <Python.h> @@ -49,4 +49,4 @@ typedef struct { PyObject *Config_CreatePyObject(); -#endif /* EXPP_CONFIG_H */ +#endif /* EXPP_BPY_CONFIG_H */ diff --git a/source/blender/python/api2_2x/BPyModule.c b/source/blender/python/api2_2x/bpy_data.c index 6159fe76f7a..ce7b41700c9 100644 --- a/source/blender/python/api2_2x/BPyModule.c +++ b/source/blender/python/api2_2x/bpy_data.c @@ -30,7 +30,7 @@ * ***** END GPL/BL DUAL LICENSE BLOCK ***** */ -#include "BPyModule.h" +#include "bpy_data.h" #include "MEM_guardedalloc.h" /* for MEM_callocN */ #include "DNA_space_types.h" /* SPACE_VIEW3D, SPACE_SEQ */ @@ -88,7 +88,6 @@ #include "Camera.h" #include "Armature.h" #include "Lamp.h" -/*#include " CurNurb.h" do we need this ? */ #include "Curve.h" #include "NMesh.h" #include "Mesh.h" @@ -107,7 +106,7 @@ #include "Scene.h" #include "Library.h" -#include "Config.h" /* config pydata */ +#include "bpy_config.h" /* config pydata */ /* used only for texts.active */ #include "BIF_screen.h" @@ -796,7 +795,7 @@ PyTypeObject LibBlockSeq_Type = { static char M_BPy_Init_doc[] = "The bpy module"; -void M_BPy_Init( void ) +PyObject * Data_Init( void ) { PyObject *module; PyObject *dict; @@ -806,32 +805,28 @@ void M_BPy_Init( void ) PyType_Ready( &Config_Type ); /*submodule = Py_InitModule3( "Blender.Main", NULL, M_Main_doc );*/ - module = Py_InitModule3( "bpy", NULL, M_BPy_Init_doc ); + module = Py_InitModule3( "bpy.data", NULL, "The bpy.data submodule" ); dict = PyModule_GetDict( module ); - - PyDict_SetItemString( dict, "libraries", Library_Init( ) ); /* Python Data Types */ - PyModule_AddObject( module, "scenes", LibBlockSeq_CreatePyObject(NULL, ID_SCE) ); - PyModule_AddObject( module, "objects", LibBlockSeq_CreatePyObject(NULL, ID_OB) ); - PyModule_AddObject( module, "meshes", LibBlockSeq_CreatePyObject(NULL, ID_ME) ); - PyModule_AddObject( module, "curves", LibBlockSeq_CreatePyObject(NULL, ID_CU) ); - PyModule_AddObject( module, "metaballs", LibBlockSeq_CreatePyObject(NULL, ID_MB) ); - PyModule_AddObject( module, "materials", LibBlockSeq_CreatePyObject(NULL, ID_MA) ); - PyModule_AddObject( module, "textures", LibBlockSeq_CreatePyObject(NULL, ID_TE) ); - PyModule_AddObject( module, "images", LibBlockSeq_CreatePyObject(NULL, ID_IM) ); - PyModule_AddObject( module, "lattices", LibBlockSeq_CreatePyObject(NULL, ID_LT) ); - PyModule_AddObject( module, "lamps", LibBlockSeq_CreatePyObject(NULL, ID_LA) ); - PyModule_AddObject( module, "cameras", LibBlockSeq_CreatePyObject(NULL, ID_CA) ); - PyModule_AddObject( module, "ipos", LibBlockSeq_CreatePyObject(NULL, ID_IP) ); - PyModule_AddObject( module, "worlds", LibBlockSeq_CreatePyObject(NULL, ID_WO) ); - PyModule_AddObject( module, "fonts", LibBlockSeq_CreatePyObject(NULL, ID_VF) ); - PyModule_AddObject( module, "texts", LibBlockSeq_CreatePyObject(NULL, ID_TXT) ); - PyModule_AddObject( module, "sounds", LibBlockSeq_CreatePyObject(NULL, ID_SO) ); - PyModule_AddObject( module, "groups", LibBlockSeq_CreatePyObject(NULL, ID_GR) ); - PyModule_AddObject( module, "armatures", LibBlockSeq_CreatePyObject(NULL, ID_AR) ); - PyModule_AddObject( module, "actions", LibBlockSeq_CreatePyObject(NULL, ID_AC) ); - - /* Other Types */ - PyModule_AddObject( module, "config", Config_CreatePyObject() ); + PyModule_AddObject( module, "scenes", LibBlockSeq_CreatePyObject(NULL, ID_SCE) ); + PyModule_AddObject( module, "objects", LibBlockSeq_CreatePyObject(NULL, ID_OB) ); + PyModule_AddObject( module, "meshes", LibBlockSeq_CreatePyObject(NULL, ID_ME) ); + PyModule_AddObject( module, "curves", LibBlockSeq_CreatePyObject(NULL, ID_CU) ); + PyModule_AddObject( module, "metaballs",LibBlockSeq_CreatePyObject(NULL, ID_MB) ); + PyModule_AddObject( module, "materials",LibBlockSeq_CreatePyObject(NULL, ID_MA) ); + PyModule_AddObject( module, "textures", LibBlockSeq_CreatePyObject(NULL, ID_TE) ); + PyModule_AddObject( module, "images", LibBlockSeq_CreatePyObject(NULL, ID_IM) ); + PyModule_AddObject( module, "lattices", LibBlockSeq_CreatePyObject(NULL, ID_LT) ); + PyModule_AddObject( module, "lamps", LibBlockSeq_CreatePyObject(NULL, ID_LA) ); + PyModule_AddObject( module, "cameras", LibBlockSeq_CreatePyObject(NULL, ID_CA) ); + PyModule_AddObject( module, "ipos", LibBlockSeq_CreatePyObject(NULL, ID_IP) ); + PyModule_AddObject( module, "worlds", LibBlockSeq_CreatePyObject(NULL, ID_WO) ); + PyModule_AddObject( module, "fonts", LibBlockSeq_CreatePyObject(NULL, ID_VF) ); + PyModule_AddObject( module, "texts", LibBlockSeq_CreatePyObject(NULL, ID_TXT) ); + PyModule_AddObject( module, "sounds", LibBlockSeq_CreatePyObject(NULL, ID_SO) ); + PyModule_AddObject( module, "groups", LibBlockSeq_CreatePyObject(NULL, ID_GR) ); + PyModule_AddObject( module, "armatures",LibBlockSeq_CreatePyObject(NULL, ID_AR) ); + PyModule_AddObject( module, "actions", LibBlockSeq_CreatePyObject(NULL, ID_AC) ); + return module; } diff --git a/source/blender/python/api2_2x/BPyModule.h b/source/blender/python/api2_2x/bpy_data.h index 2d8fa2a3684..45600df6471 100644 --- a/source/blender/python/api2_2x/BPyModule.h +++ b/source/blender/python/api2_2x/bpy_data.h @@ -29,8 +29,8 @@ * ***** END GPL/BL DUAL LICENSE BLOCK ***** */ -#ifndef EXPP_BPYMODULE_H -#define EXPP_BPYMODULE_H +#ifndef EXPP_BPYDATA_H +#define EXPP_BPYDATA_H #include <Python.h> #include "DNA_listBase.h" @@ -50,6 +50,6 @@ typedef struct { } BPy_LibBlockSeq; -void M_BPy_Init( void ); +PyObject * Data_Init( void ); -#endif /* EXPP_MAIN_H */ +#endif /* EXPP_BPYDATA_H */ |