Hi folks:
Once again, working w/Python in Maya, a 3D animation app.
I'm using a potentially time-consuming procedure to generate a list of commands, and I want to store the list in the Maya file.
The best solution I can think of is to convert the list to a string, which I can easily store and convert back to a list when I need it.
The items in the list are enclosed by tildes, which are necessary to define them as commands.
A simple example:
print cmndList
['cmds.sphere(n = "aBall", r = 1)', 'cmds.sphere(n = "aBall", r = 2)', 'cmds.sphere(n = "aBall", r = 3)', 'cmds.sphere(n = "aBall", r = 4)', 'cmds.sphere(n = "aBall", r = 5)', 'cmds.sphere(n = "aBall", r = 6)']
# To Execute:
for cmnd in cmndList:
exec(cmnd)
Looking at this thread:
I used:
cmndsString = " ".join(["%s" % el for el in cmndList]) # which lost the tildes:
print cmndsString
cmds.sphere(n = "aBall", r = 1) cmds.sphere(n = "aBall", r = 2) cmds.sphere(n = "aBall", r = 3) cmds.sphere(n = "aBall", r = 4) cmds.sphere(n = "aBall", r = 5) cmds.sphere(n = "aBall", r = 6)
Also, it seems to me that I need to add an extra character for the split command when converting back to a list?
Suggestion would be appreciated.
Thanks much.