Search and Replace with Python

416 views
Skip to first unread message

Félix CT

unread,
Sep 18, 2015, 3:38:08 PM9/18/15
to Python Programming for Autodesk Maya
What is the faster way for search and replace with python?

I know that exist: 

import maya.mel as mel
mel.eval(' searchReplaceNames "side_limb" "L_arm" "all" ')

but here I can't replace the 'L' with a variable.


Saludos!

Kurian O.S

unread,
Sep 18, 2015, 3:50:18 PM9/18/15
to python_in...@googlegroups.com
import maya.mel as mel
newName = "L_arm"
mel.eval('searchReplaceNames "pSphere1" "%s" "all"' % newName)


On Fri, Sep 18, 2015 at 12:38 PM, Félix CT <felix...@gmail.com> wrote:
searchReplaceNames "side_limb" "L_arm" "all"




--
--:: Kurian ::--

Mark Stewart

unread,
Sep 18, 2015, 4:11:07 PM9/18/15
to python_in...@googlegroups.com
Yup or even more modular;
import maya.mel as mel
side = "L"
mel.eval('searchReplaceNames "pSphere1" "%s_arm" "all"' % side)

the other cool thing about string formatting this way, is you can do padded numbers from integers
eg; 
'rendername.%04d.png' %12  will result in 
'rendername.0012.png'

more info here https://docs.python.org/2/library/stdtypes.html

M. 

P.S. Hi Kurian!


--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CANEMyhOnWsMyLt%2BFWkTrL1Yb71wDxyCcBS3oL%2BGbYB%3Dsmga5bg%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--

Félix CT

unread,
Sep 18, 2015, 4:52:01 PM9/18/15
to Python Programming for Autodesk Maya
Gracias!!!

Rémi Deletrain

unread,
Sep 21, 2015, 3:01:18 AM9/21/15
to Python Programming for Autodesk Maya
Hi,

You can do this with Python:

toto = 'L_Arm'
toto.replace('L_', 'R_')
Reply all
Reply to author
Forward
0 new messages