I am just getting my feet wet using python in Blender, and have a question regarding strings. First of all, the goal of the first part of the program is to find the names of all objects whose names end in a particular set of characters. For example, I would like to find all objects named XXXXXpOut, where XXXXX = any string.
My thinking for doing this is to create a list of all the objects in the current scene, then test for the name condition.
Now, I would like to find the length of myStr. When I use the following:
myStrLen = len(myStr)
I get:
Traceback (most recent call last):
File “Text.003”, line 9, in ?
TypeError: len() of unsized object
Is there something special about the list created using Blender.Scene.getCurrent().getChildren()? I have tried creating my own list manually, all entries are text strings in quotes, and the logic works fine. I suspect that because each entry in the list that is created using Blender.Scene.getCurrent().getChildren() has imbedded quotes [Object “Lamp”], I will have to do something different, but I’m not sure what.
Well currently you’re just getting the actual objects.
You want to get the object names for what you want to do.
So to create a neat list of all objects in the current scene
objectlist = [ob for ob in Blender.Scene.GetCurrent().getChildren()]
You can now loop through the list, get the names and do whatever you want.
## Loop though
for a in range(len(objectlist)):
## Get the name
name = objectlist[a].getName();
## Get the length of the name
check = len(name);
## Print out the object nr in the list, the name, and it's length
print a, name, check;
So, I tried to back track, taking your info and trying to find documentation for it. I found lots of examples of “ob for ob”, but no documentation. If you have the time, could you please explain what is going on when using:
ob_list = [ ob for ob in Blender.Scene.getCurrent().getChildren() if ob.name.endswith(‘pOut’) ]