changing name of obj?

suppose that you add object in scene in a loop like plane or cube
it takes a default name of Cube then Cube.001 ect,

is there a way to specify the name wehn adding or in the loop
changing the name to something like p1 , p2 p3 ect,

how can we change the name tp something easy to deal with ?


in the outliner view, ctrl+left click on the object, and type the new name?

sorry not manuall;y in the script’s loop


 from bpy import data, ops, context, types, props

def addcubes():
    ##   assuming this is going to happen in object mode
    ##   bcoz even if you add lots of objects every thing is going to be same
    for each in range(10):
        loc = 3*each
        ##   format the name to show your choice of name
        name = 'MyObject'+str(each+1)
        ops.mesh.primitive_cube_add(location = ( loc , 0 , 0 ))
        ##   here is our boss
        ##   because added object will be the current active one = name

if __name__ == '__main__':

ok nice way to do it

but when adding a primitive like this

myplaneMesh =bpy.ops.mesh.primitive_plane_add(view_align=False, enter_editmode=False, location=(x1, y1, 0), rotation=(0, 0, 0) , layer=[True]+[False]*19)

i guess that i can use your last line = name
and just make my name a little like you did instead of the sequence number 001 or 002 ect
which i find difficult to deal with afterward!

also inside at the end of the loop is there a way to join all the objects created in the loop to make on big object
like join the before last and the last one created

i wish i could show a pic here but not allowed !

i’m dong a meter scale with all the markers so i may get 100 markers which would be nice to have all in one object not 100 !LOL

Thanks & happy 2.5

here is my code for all the major marker and minor markers on scale

sorry not enough space i think to pass all the menu class ect

        for xi in float2_range(minag,maxag-1, step):  #     Big marker beginning
            for xsi in float2_range(xi+step2,xi+maxag1-1, step2):
                print ('rad1=',rad1,'rad2=',rad2,' h2=',h2)
                myplaneMesh =bpy.ops.mesh.primitive_plane_add(view_align=False, enter_editmode=False, location=(x1, y1, 0), rotation=(0, 0, 0) , layer=[True]+[False]*19)
                xdeg=0            #    Angle in degrees
#                ob.rotation_euler = [0,0,xi*pi/180] 
                bpy.context.active_object.rotation_euler = [radians(xdeg),radians(ydeg),radians(zdeg)] 
                bpy.context.active_object.scale = [scalex,scaley,scalez]
                print (' xi=',xi,'deg   xsi=',xsi,'deg   ang1=',ang1,' deg')
            print ()