Iterating on items() doesn't seem to be needed unless you are trying to
trap each possible keyword argument that may be passed. This works as well:

import maya.cmds as mc

win = mc.window()

def frame(**kwargs):
    frame_layout = mc.frameLayout()
    mc.frameLayout(frame_layout, edit=1, **kwargs)

frame(label='foo', borderStyle='etchedIn')
frame(label='bar', borderStyle='etchedIn')
frame(label='zed', borderStyle='etchedOut')

mc.showWindow(win)


Ed Caspersen


On Wed, May 29, 2013 at 12:10 PM, Adam Mechtley <[email protected]>wrote:

> You can actually pack your keyword args into a dictionary and pass it into
> the command like:
>
> kw = {flag: value}
> mc.frameLayout(self.frame, **kw)
>
>
> On Wed, May 29, 2013 at 2:06 PM, ynedelin <[email protected]> wrote:
>
>> hey guys
>> I have this piece of code working fine, but us there a nicer way to do
>> this without pre-building the string for eval?
>>
>> def frame(self, **kwargs):
>>   self.frame = mc.frameLayout()
>>     for flag, value in kwargs.iteritems():
>>       try:
>>         if type(value) is int or type(value) is float:
>>           cmd = "mc.frameLayout('%s', edit=1, %s=%f)"%(self.frame, flag,
>> value)
>>         elif type(value) is str:
>>           cmd = "mc.frameLayout('%s', edit=1, %s='%s')"%(self.frame,
>> flag, value)
>>         eval(cmd)
>>        except:
>>          traceback.print_exc()
>>
>> Yury
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Python Programming for Autodesk Maya" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to