class in general

when you make a class and create from this several objects alike

is there a way to make a list of the created objects with their name

so that you know how many have been created with this class?

Thanks

Well you could add the objects to a list as you create them, then you can find out the size of the list…

any particular reason?

just wondering if there was a way
i mean when you create theses new objects

in blender there is always some sort of master list automatically done if i remember well

so i was wondering if there was one for new cfass!

Thanks

ah but making an object of a class is a language specific thing rather than blender. so take an OO language (object orientated), i have a class called foo, I make an instance of it ( an object) called bar, unless you tell blender about it, blender does not know about it.

Class attributes could be one way, but how Blender’s Python handle this, I don’t know:

class objectA(object):
  def __init__(self):
    if hasattr(objectA,"count"):
      objectA.count+=1
    else:
      objectA.count=1

A1=objectA()
A2=objectA()
A3=objectA()
print objectA.count # prints "3"

what you could do is in your class have get and set methods. One of which could be an ID, the biggest ID would tell you how many there are, but a list could be easier…

where did you see theses get an set method

don’t remember theses ones!

i knew about this trick and having a counter inside the class

but have the feeling like there must a way outiside of the class
to count theses newly created objects

like in blender when you make a list of objects
you can find theses objects count them ect…

Thanks

Hello RickyBlender.

I had written the following code for one of the Python lectures i took at work. Hope it helps you. I was doing something very similar to what you are wanting to do.

http://sites.google.com/site/satishgoda/programming/python/tutorials/classes/shapes3-py

Hope it helps.

Greetings from India :slight_smile:

  • Satish.

@iluvblender

very interesting way to make class
and several methods i did not really use before

is there a place where this is explain in more details how this is working?

so looks like the only way to get a count of objects with python is to have a class counter inside the class itself
before the init or inside the init methods so it remembers how many have been created or deleted!

and nothing that might be readable may be from inside the dict of python if there is one!

now i got to look at what is sort of global vars in the class and what is local to the functions or methods!

Thanks

This is fairly often the case, and it is one of the Python’s design paradigms: Let there be one way to do things, and only one.

If you are interested, as a curiosity, you even find a “Zen of Python” listing when you write “import this” in the Python command prompt:

$ python
Python 2.5.1 (r251:54863, Jul 31 2008, 23:17:43)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
>>>    

Yes did not know there was this little ZEN thinking about python
but nice and fun to know it
you’v got to have a good sense of humour to include this!LOL

may be we should have one like that for python scripting in blender

like
don’t drink and Blender
don’t blender underwater
don’t leave home without blender

LOL

@iluvblender

i’m trying to test the first shape script but i guess this was written a long time ago
in pyton 2.0 serie i guess and is not working in blender 2.5 script

do you have modified working 3.0 py file for theses little scripts of yours

like shape shape1 and shape2 just to test theses in python 3.0 and 2.5

i like theses little examples for class inheritance to study how to do theses

Thanks