Something like this?


funcDict = dict(   __amn__attributeOne : func1,
   __amn__attributeTwo : func2,
   ...
)

noop = lambda *x : None

object = pm.ls()
for obj in objects:
    for attr in obj.listAttr(string="__amn__*"):
        func = funcDict.get(attr.plugAttr(), noop)
        func()



I'm curious though if this indeed boosts performance. The dictionary look-up
should be faster than multiple if statements...



- Ofer
www.mrbroken.com


On Sat, Jul 18, 2009 at 2:33 AM, King <[email protected]> wrote:

>
> I have written a custom scene file exporter.
>  All the geometrical object can have n number of custom attributes out
> of 46 attributes. When looping through all the objects in the scene I
> have to use if-elif to check if attribute is present or not. If it's
> present, executed the related code.
>
> This is slow (3000 objects * 46 attributes = 138000 if-elif
> conditions)
>
> It seems python can offer something here although I am not sure.
>
> Create a dictionary of {attribute:code_to_execute}
> All the custom attributes have prefix "__amn__". I can get all the
> attributes on the object start with some prefix in one go. Iterate on
> attributes found and execute the code related to it.
>
> I need some advise over here. It will be little tricky but I think
> python can achieve this.
>
>
> Prashant
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/python_inside_maya
-~----------~----~----~----~------~----~------~--~---

Reply via email to