[Bf-python] __del__ hook
Rettig, Frank AGTHZA-DAE
rettifan at schaeffler.com
Fri Aug 28 09:04:45 CEST 2009
I 'am working on a way to export 3D data to Blender. My application generates a python script that builds up the scene in Blender. The problem is that I can't force my application to write the last line of code. This last line would be something like "myModel.setup()". Since I couldn't generate the last setup call, the idea was to let python do the job by using the __del__ hook. I see that a expicit call to a setup method would be the best solution, but since this isn't possible the only thing that came to my mind was the __del__ hook.
Frank
-----Ursprüngliche Nachricht-----
Von: bf-python-bounces at blender.org [mailto:bf-python-bounces at blender.org] Im Auftrag von Martin Poirier
Gesendet: Donnerstag, 27. August 2009 17:00
An: Blender Foundation Python list
Betreff: Re: [Bf-python] __del__ hook
datetime is being removed from the global namespace before your instance is.
As a rule, __del__ methods should never have dependencies outside of the instance itself and its class.
In any case, relying on __del__ for actions that you explicitly want to happen is bad for several reasons outline in the python doc.
http://docs.python.org/reference/datamodel.html#basic-customization
Can you elaborate more on why you wanted to use this method instead of a more explicit method call?
Martin
--- On Thu, 8/27/09, Rettig, Frank AGTHZA-DAE <rettifan at schaeffler.com> wrote:
> From: Rettig, Frank AGTHZA-DAE <rettifan at schaeffler.com>
> Subject: [Bf-python] __del__ hook
> To: bf-python at blender.org
> Received: Thursday, August 27, 2009, 9:19 AM
>
>
>
>
>
> Dear
> list,
> I'am working on a
> import script for blender. The idea is to use the __del__ hook to
> complete the import. The following script works fine on my python
> interpreter, but if I use it from Blender I get:
>
> Exception NameError:
> "global name 'datetime' is not defined"
> in <bound method X.
> __del__ of
> <__main__.X instance at 0x01FAD440>>
> ignored
>
> Any idea why the
> code doesn't run with blender?
>
> Best
> regards,
> Frank
>
>
> import
> datetime
> import time
>
>
> class X:
> def
> __init__(self):
>
> self._job_begin_time =
> datetime.datetime.now()
>
> print "My job has started at %s " %
> self._job_begin_time
>
> def
> __del__(self):
>
> self._job_end_time =
> datetime.datetime.now()
>
> print "My job has ended at %s " %
> self._job_end_time
> print
> "Job took this much time: %s" %
> (self._job_end_time
> -
>
>
> self._job_begin_time )
>
> def
> waste_some_time(self):
> pass
>
> print "Starting job X"
> myX = X()
> myX.waste_some_time()
> print
> "Ending job X"
>
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> Bf-python mailing list
> Bf-python at blender.org
> http://lists.blender.org/mailman/listinfo/bf-python
>
__________________________________________________________________
Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites. Download it now
http://ca.toolbar.yahoo.com.
_______________________________________________
Bf-python mailing list
Bf-python at blender.org
http://lists.blender.org/mailman/listinfo/bf-python
More information about the Bf-python
mailing list