0
$\begingroup$

I'm currently trying to create a tool, to rename objects in blender, to automatically have lowercase names. I keep however getting the error: TypeError: 'list' object is not callable

My current code is below, can anyone tell me how I can fix this error?

        objs = bpy.context.scene.objects

        #o = old_name l = lowercase
        o = {n.name for n in objs}
        print(o)
        l = [elem.lower() for elem in o]
        count = len(objs)
        i = 0
        print(count)
        while i < count:
            objs[i].name = l()
        i+=1

edit: I want to do more with the name than just make it lowercase, but I keep getting stuck on renaming the objects in the right order so that's what I'm trying to fix here

$\endgroup$
  • $\begingroup$ Hi. l is a list. l() is trying to call the list as if it were a function, which it is not. What were hoping l() would do? $\endgroup$ – Ray Mairlot Jan 17 at 16:00
  • $\begingroup$ I want l to contain the new names of the objects, and assign them as the object name using objs[i].name $\endgroup$ – henry de lange Jan 17 at 16:06
1
$\begingroup$

Currently your script performs several unnecessary operations when your goal is to rename the objects.

  • You're creating a set of object names by using the {} syntax, which isn't necessary since the names are guaranteed to be unique.
  • Unless you intend to re-use the old names, it's not necessary to store them.
  • You likely don't need to store the new lowercase names either, if you perform your action while iterating over the objects.
  • Don't use a while loop when you intend to index elements. Use a for loop instead, especially if the object is iterable.
  • The l is a list of strings, therefore using l() would result in a TypeError, since a list can't be called. It's not a function.

The solution would be to iterate over the objects and rename them one by one.

import bpy


for obj in bpy.context.scene.objects:
    obj.name = obj.name.lower()
    # Perform additional tasks with the renamed object here

If you have to store the lowercase names in a list:

import bpy


names_lowercase = []

for obj in bpy.context.scene.objects:
    name = obj.name.lower()
    obj.name = name
    names_lowercase.append(name)
| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks, this really helped me out $\endgroup$ – henry de lange Jan 20 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.