2.5 re naming object




for ob in bpy.data.objects:
if ob.name == “Cube”:

print all of MyObject’s vertex coordinates

for vert in ob.data.verts:

if ob.selected:
print ( “End of vert list”)

i tried this little script to change the name of selected cube
it works with no errors but does not change the name of the selected object (cube)

your second if was align with the first one
and works fine !
what’s the difference here ?


It does actually change the name of the cube to “newcube”, when I test it. No idea why it isn’t working for you.
By the way, when you post code on the forum, try to use the code tags. It helps to preserve indentation.

# cube

for ob in bpy.data.objects:
    if ob.name == "Cube":
        # print all of MyObject's vertex coordinates
        for vert in ob.data.verts:

    if ob.selected:
    print ( "End of vert list")

You use it like this (just remove the asterisk *) :

def foo():

i can see the new cube added but it is called Mesh

i was able to make the outliner longer and can see the new Mesh name
for new cube but not with newcube name?

how can we make the panel longer i tried with the mouse to bring it down but not working ?

sorry cannot put pic here ! i could load up one with URL

the name was not changed?

there is already a cube by default in scene called "Cube?
and i also added a curve bezier but that should not influence the naming!

tested your script and it works fine

what was wrong with the way i wrote mine ?


The script I posted is the one you posted, I just added proper indentation. So that’s probably what is wrong in yours.
If you don’t have the last block of code (if ob.selected: etc.) indented, it will only be run once: for the last object in the scene. If that isn’t your newly added object, there will be no re-naming.

About making a window longer: just drag the devision line between two windows. You can also maximize a window by pressing Ctrl+Up (just like in 2.4x).

ok i had this


i tried to pass or even with Ctrl-V the indentation does not work
dont’ know why

like i said the 2 IF
where align in your script
but in mine they where not

the second if was align witht he For
which is supposed to be independant of the for - i tough
but seems that’s not the same thing!

see pic here



The code in your pic explains what goes wrong.

In the default scene there already is a cube present, named ‘Cube’. When you add a new mesh (another cube), it’s automatically called ‘Cube.001’
After that you start iterating over all the objects in the scene but only do something if the object is called ‘Cube’. This is the orginal cube that was already in the scene, not the newly created one. Unfortunately the original cube isn’t selected anymore, because when you added the new cube, blender automatically set that cube to be the only selected object. So the last ‘if’ statement (original cube being selected) will never be true, hence there’ll be no renaming.

this selection of object is the problem

i tough that ounce you go trhough all the objects as soon as it goget the Cube one
the IF inside the foor loop would recognise it
but does not seems to do that for my original script

but the same is true with yours how can the" if" find it outside of the for loop
the second cube as already been added and selected ?

and what is stange as i said the second cube was not named Cube.001 it was called “Mesh”?

i hope we can get a better way to select objects in 2.5

this does not make sense!