[Maya-Python] Re: String formatting error for arg in dictionary for use in mel.eval

2019-03-08 Thread kiteh
Adding on, if I tried using `mel.eval('animLayerMerge{"BaseAnimation", 
"%s"}' % my_naming)`, while it seems to work, but it mutes out my_layer and 
instead creates another animation layer called `Merged_Layer`

On Friday, March 8, 2019 at 11:41:29 AM UTC-8, kiteh wrote:
>
> Hi all, I am trying to do a string formatting in which it is in a 
> dictionary format that is to be used in mel command.
>
> This is my mel command - `mel.eval('animLayerMerge{"BaseAnimation", 
> "my_layer"}')`
>
> In my python format, I rewrote as this:
> my_naming = 'my_layer'
> command = '"{"BaseAnimation", "{0}"'.format(my_naming)
>
> However this will results in the following error:
> # Error: "BaseAnimation", "{0}"
> # Traceback (most recent call last):
> #   File "", line 2, in 
> # KeyError: '"BaseAnimation", "{0}"' # 
>
> No matter how I wrote my `.format`, it will definitely errors out as soon 
> as I tried to incorporate in `{ {0} }` and the reason I am doing this is 
> because I would not want to hardcode the value of `my_naming` as it reads 
> from a text field which would means different naming.
>
> Is there a better way that I can perhaps get around this?
>
>

-- 
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 python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/2184c17d-b3da-45bb-8c30-f592420efba3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Maya-Python] Re: String formatting error for arg in dictionary for use in mel.eval

2019-03-08 Thread Robert White
Try:

my_naming = 'my_layer'
command = '"{{"BaseAnimation", "{0}"'.format(my_naming)

I believe the problem is that because you've got the single open { the 
formatting code gets confused. To insert a { into a formatted string you 
just double them up.

On Friday, March 8, 2019 at 1:54:09 PM UTC-6, kiteh wrote:
>
> Adding on, if I tried using `mel.eval('animLayerMerge{"BaseAnimation", 
> "%s"}' % my_naming)`, while it seems to work, but it mutes out my_layer and 
> instead creates another animation layer called `Merged_Layer`
>
> On Friday, March 8, 2019 at 11:41:29 AM UTC-8, kiteh wrote:
>>
>> Hi all, I am trying to do a string formatting in which it is in a 
>> dictionary format that is to be used in mel command.
>>
>> This is my mel command - `mel.eval('animLayerMerge{"BaseAnimation", 
>> "my_layer"}')`
>>
>> In my python format, I rewrote as this:
>> my_naming = 'my_layer'
>> command = '"{"BaseAnimation", "{0}"'.format(my_naming)
>>
>> However this will results in the following error:
>> # Error: "BaseAnimation", "{0}"
>> # Traceback (most recent call last):
>> #   File "", line 2, in 
>> # KeyError: '"BaseAnimation", "{0}"' # 
>>
>> No matter how I wrote my `.format`, it will definitely errors out as soon 
>> as I tried to incorporate in `{ {0} }` and the reason I am doing this is 
>> because I would not want to hardcode the value of `my_naming` as it reads 
>> from a text field which would means different naming.
>>
>> Is there a better way that I can perhaps get around this?
>>
>>

-- 
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 python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/dc713b2d-47e0-4f42-a0b4-f070435644c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Re: String formatting error for arg in dictionary for use in mel.eval

2019-03-08 Thread Justin Israel
https://docs.python.org/2/library/string.html#format-string-syntax

"If you need to include a brace character in the literal text, it can be
escaped by doubling: {{ and }}."

Also it seems like you have a typo in your example where you have an extra
leading double quote character which would be a syntax error. So I'm
assuming that wasn't intentional.

I would expect it to be like:

my_naming = 'my_layer'
command = '{{"BaseAnimation", "{0}"}} '.format(my_naming)

And I would think the Mel command would be like:

animLayerMerge({...})



On Sat, Mar 9, 2019, 8:54 AM kiteh  wrote:

> Adding on, if I tried using `mel.eval('animLayerMerge{"BaseAnimation",
> "%s"}' % my_naming)`, while it seems to work, but it mutes out my_layer and
> instead creates another animation layer called `Merged_Layer`
>
> On Friday, March 8, 2019 at 11:41:29 AM UTC-8, kiteh wrote:
>>
>> Hi all, I am trying to do a string formatting in which it is in a
>> dictionary format that is to be used in mel command.
>>
>> This is my mel command - `mel.eval('animLayerMerge{"BaseAnimation",
>> "my_layer"}')`
>>
>> In my python format, I rewrote as this:
>> my_naming = 'my_layer'
>> command = '"{"BaseAnimation", "{0}"'.format(my_naming)
>>
>> However this will results in the following error:
>> # Error: "BaseAnimation", "{0}"
>> # Traceback (most recent call last):
>> #   File "", line 2, in 
>> # KeyError: '"BaseAnimation", "{0}"' #
>>
>> No matter how I wrote my `.format`, it will definitely errors out as soon
>> as I tried to incorporate in `{ {0} }` and the reason I am doing this is
>> because I would not want to hardcode the value of `my_naming` as it reads
>> from a text field which would means different naming.
>>
>> Is there a better way that I can perhaps get around this?
>>
>> --
> 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 python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/2184c17d-b3da-45bb-8c30-f592420efba3%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1gk-PQJA%3D4Ec4DetbT09WW5UovNsGMVFiVnva1tXUyiA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Re: String formatting error for arg in dictionary for use in mel.eval

2019-03-08 Thread kiteh
Got it, thank you so much all!

I wasn't aware of the double curly brackets for such scenarios. Thanks 
again!

-- 
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 python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/a1d08a6f-1889-4f0a-9dce-8c16b147bb97%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.