this works fine
import bpy, math
def returnTorusMesh (r1,r2,s1,s2):
bpy.ops.mesh.primitive_torus_add(major_radius=r1, minor_radius=r2, major_segments=s1, minor_segments=s2, use_abso=False, abso_major_rad=1, abso_minor_rad=0.5, view_align=False, location=(0, 0, 0), rotation=(0, -0, 0))
ob = bpy.context.active_object
me = ob.data
bpy.ops.object.delete()
return me
bpy.ops.object.select_all(action='DESELECT') # Deselect all other objects.
bpy.ops.object.select_name(name="Cube",extend=True ) # Select the object.
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.remove_doubles(limit=10000) # Try to make the existing mesh a single vertex mesh.
bpy.ops.object.editmode_toggle()
ob = bpy.data.objects["Cube"] # Fetch the object.
ob.data.name = "zz_garbage" # Rename the remove_doubles mesh to garbage, it is being discarded.
me = returnTorusMesh(2,0.3,16,16) # Get a new mesh to link to this object.
me.name = "me_torus" # Name this mesh.
ob.data = me # Assign the new mesh to the old C
now i got 2 others things but not certain when to use or not and why ?
Remove data Block1
import bpy
class RemoveDatablocksOperator(bpy.types.Operator):
bl_idname = 'world.remove_redundant_datablocks'
bl_label = 'Remove Redundant Datablocks'
@classmethod
def poll(cls, context):
return True
def execute(self, context):
data_blocks = ['actions',
'armatures',
'brushes',
'cameras',
'curves',
'fonts',
'groups',
'images',
'lamps',
'lattices',
'materials',
'meshes',
'metaballs',
'objects',
'particles',
'scenes',
'texts',
'textures',
'worlds']
for item in data_blocks:
db = getattr(bpy.data, item)
for i in db:
if i.users <= 0:
db.remove(i)
return {'FINISHED'}
if __name__ == '__main__':
bpy.ops.world.remove_redundant_datablocks()
and this one
mod = bpy.data.objects['Cube'].modifiers.new(name='decimate', type='DECIMATE')
mod.ratio = 0.5
mod.realtime = True
happy 2.5