Forgot password?

Create an account!

Forum

« back

Python – ***count objects in layers***

Messages

Please log in to write a message.

  • 2. Klaus Vielhaber (Apr 19, 2016 15.56):

    Greetings to Salerno!
    Some days ago, I searched the web for a python script which counts Blender objects. I did not find any solution, but I read your question.
    In the meantime I solved my problem by the following code:

    import bpy

    i = 0                     # current number of objects
    i_max = 0
    L = 3                     # number of the layer (example)
    Count = 0                 # counter for objects in layer L
    while i_max == 0:
        try:
            ob = bpy.data.objects[i]
            i = i+1
            if ob.layers[L] == True:
                count = count+1
        except:                # occurs, when object i does not exist
            i_max = i          # stops the while-loop

    print("layer", L, "contains", count, "objects")

    Probably my proposal comes too late for you, but I hope it will be useful for other users.

    Klaus Vielhaber (from Gerlingen near Stuttgart, Germany)

  • 1. salerno (Jun 22, 2015 14.54):

    Hi All,
    I'm a designer and I'm just starting figured out python world. I already made some easy scripts but now I need something I'm not able to do by myself.
    I need a script that return the count of the objects in a layer.
    Have to verify if there are objects in a layer, if true print with 'pick point' the result , if false have to pass to the next layer.

    can someone help me? thanks in advance

    cheers

Recommend

Why are these buttons gray?