[Bf-python] Dynamic Ipo Object Instantiation

Dave Jarvis dave.jarvis at gmail.com
Fri Mar 30 09:06:09 CEST 2007


Hi,

The following set of classes have a New method:

Camera, Lamp, Material, Object, Texture, World

Unfortunately, the New method is not consistent across all classes. It 
would be nice if they were made consistent. For example, I was trying to 
be tricky:

IPO_TYPE_NAMES = \
   ['Camera', 'Lamp', 'Material', 'Object', 'Texture', 'World']

IPO_OBJECTS = {
   IPO_TYPE_NAMES[ 0 ]: Camera.New,
   IPO_TYPE_NAMES[ 1 ]: Lamp.New,
   IPO_TYPE_NAMES[ 2 ]: Material.New,
   IPO_TYPE_NAMES[ 3 ]: Object.New,
   IPO_TYPE_NAMES[ 4 ]: Texture.New,
   IPO_TYPE_NAMES[ 5 ]: World.New }

def __createIpoObject( self ):
   ipoTypeName = self.getIpoTypeName() # 'Lamp', 'Material', etc.
   return self.IPO_OBJECTS[ ipoTypeName ]( ipoTypeName )

Unfortunately, this code doesn't work because the API for New is 
different across these objects.

Is there another way to dynamically create Ipo objects?

Dave



More information about the Bf-python mailing list