[Bf-python] Re: Request for adding a proposed new feature
Ken Hughes
khughes at pacific.edu
Wed Dec 20 19:33:57 CET 2006
Eric-Olivier Le Bigot wrote:
> Hello everybody,
>
> How about using the Python no-brainer
>
> del obj
>
> In fact, the intended behavior is to completely get rid of the object,
> which is what is meant by "del". The implementation of the __del__
> method would imply unlinking the object from any scene it is in.
I just double-checked before replying and this did what I though it
would do: "del obj" calls the object deallocation function
Object_dealloc(), so there's no way to distinguish this from the normal
object deallocation.
> Furthermore, in
>
> scn.objects.remove([ob1, ob2...],delete=True)
>
> what happens when the object is linked to many scenes? I guess that
> "scn" is a specific scene: the semantics of the above call is not
> totally transparent, as a method on a single scene would destroy objects
> in many scenes.
That's the case: scn.objects.remove() only handles the object within the
context of this scene, and "delete=True" further specifies that if this
was the last user of the object, completely delete the object.
If we need a method to delete an object from all scenes, that's
something which probably should be added as a function, like
Object.Delete().
Two other comments though:
(1) did we decide during the Sunday morning meeting a few weeks ago to
use objects.remove() instead of .unlink()? Or did Cam or I misquote the
method earlier?
(2) I was looking into adding the "delete=True" support this morning
when I remembered that it doesn't matter whether the objects are created
by Object.New(), Object.Get() or scn.objects: since they're all
BPy_Objects all objects get their user count incremented, so the nice
new scene.objects API isn't going to fix that problem :-(
Ken
> Please forgive me if the remarks above are naive or misguided: I'm new
> to Blender and its Python module :)
>
> EOL
>
> On Tue, 19 Dec 2006, Ken Hughes wrote:
>
>> Campbell Barton wrote:
>>> How about we allow
>>>
>>> scn.objects = []
>>>
>>> Other possibilities are...
>>>
>>> scn.objects.remove([ob1, ob2...])
>>
>> I was thinking more about making complete deletion optional per object
>> (or group of objects):
>>
>> #remove from scene, but don't delete when user count = 0
>> scn.objects.remove([ob1, ob2...])
>> #remove from scene, delete objects with user count = 0
>> scn.objects.remove([ob1, ob2...],delete=True)
>>
>> Maybe some scripters don't want to delete the object when they become
>> zero (the current behavior).
>>
>> The reason I suggest adding it here and not in the Object module is
>> the nastiness we added earlier where Object.Get() and Object.New()
>> become users of the object. It makes deleting the object a bit of a
>> pain when you're also a user of it. Can fakeUser take care of that
>> old problem now so we don't have to mess with the user count?
>>
>>> Ken Hughes wrote:
>>>> The more the merrier... so I'm cc'ing Campbell:
>>>>
>>>> This is not hard to do, but should be done in a way which doesn't
>>>> break backward compatibility. I think this would be something to
>>>> consider adding to the Scene.objects sequence type, maybe with an
>>>> optional parameter to specify completely deleting the object.
>>>>
>>>> Might be a good idea to run this through the BPy mailing list since
>>>> we should decide ASAP before the CVS freeze.
>>>>
>>>> Ken
>>>>
>>>> Tom M wrote:
>>>>> I think this is already doable, ccing ken because i think he added it.
>>>>>
>>>>> (...)
>>>>>
>>>>> LetterRip
>>>>>
>>>>> On 12/19/06, Eric-Olivier Le Bigot
>>>>> <Eric.Le.Bigot at spectro.jussieu.fr> wrote:
>>>>>> Hello,
>>>>>>
>>>>>> I'd like to propose a feature for the Python API, and I would like
>>>>>> to know
>>>>>> whether I can get modification rights on
>>>>>> http://mediawiki.blender.org/index.php/BlenderDev/DesignIssues in
>>>>>> order to
>>>>>> add this feature to the list.
>>>>>>
>>>>>> In fact, as far as I understand, it is not currently possible to
>>>>>> remove an
>>>>>> object in the same way as the deletion in the 3D window does.
>>>>>> Many people on
>>>>>> Blender Artists have run into this problem, which is particularily
>>>>>> acute for
>>>>>> me.
>>>>>>
>>>>>> I need to run a script that create 1000s of objects after emptying
>>>>>> the
>>>>>> current scene; the problem is that this "emptying" is only done
>>>>>> with unlinks:
>>>>>> even though the first run is very fast, subsequent runs are
>>>>>> extremely slow
>>>>>> (maybe because of memory issues, or because the objects created
>>>>>> during the
>>>>>> second run have names that clash with those of the unlinked
>>>>>> objects?).
>>>>>>
>>>>>> It would be very useful for me if the deletion command "x" of the
>>>>>> 3D window
>>>>>> could have a Blender Python equivalent (as the "x" command does
>>>>>> remove the
>>>>>> objects from memory, if this is possible).
>>>>>>
>>>>>> Best wishes,
>>>>>>
>>>>>> EOL
>>>>>>
>>>>>> --
>>>>>> Dr Eric-Olivier LE BIGOT (EOL) CNRS Associate
>>>>>> Researcher
>>>>>> ~~~o~o~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~o~o~~~
>>>>>> Kastler Brossel Laboratory (LKB)
>>>>>> Université P. & M. Curie and Ecole Normale Supérieure, Case 74
>>>>>> 4 place Jussieu 75252 Paris CEDEX 05
>>>>>> France
>>>>>> ~~~o~o~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~o~o~~~
>>>>>> office : (+33) 1 44 27 73 67 fax: (+33) 1 44 27
>>>>>> 38 45
>>>>>> ECR room: (+33) 1 44 27 47 12 x-ray room: (+33) 1 44 27
>>>>>> 63 00
>>>>>> home: (+33) 1 73 74 61 87
>>>>>> http://dirac.spectro.jussieu.fr/index_en.html
>>
More information about the Bf-python
mailing list