Code Clean-up and Maya/Python Slicing issues - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Code Clean-up and Maya/Python Slicing issues (/thread-20339.html) |
Code Clean-up and Maya/Python Slicing issues - mvvthology - Aug-05-2019 Hello. First time posting in a forum and first time independently coding something, so if this is not the correct place please let me know. I am currently working to create a plug-in for Maya which a part of it needs a cylinder to be generated, an edge loop beveled and moved down to create a platform. I have that code working, but it is long and repetitive. import maya.cmds as cmds def platform(): cmds.polyCylinder() cmds.rename('pCylinder1','platform') cmds.setAttr('platform.scale', 5, .5, 5) cmds.setAttr('platform.translateY', -.5) cmds.polyBevel( 'platform.e[20:39]') cmds.polyMoveEdge('platform.e[21]', t=(0, -.1, 0)) cmds.polyMoveEdge('platform.e[26:27]', t=(0, -.1, 0)) cmds.polyMoveEdge('platform.e[30]', t=(0, -.1, 0)) cmds.polyMoveEdge('platform.e[33]', t=(0, -.1, 0)) cmds.polyMoveEdge('platform.e[36]', t=(0, -.1, 0)) cmds.polyMoveEdge('platform.e[39]', t=(0, -.1, 0)) cmds.polyMoveEdge('platform.e[42]', t=(0, -.1, 0)) cmds.polyMoveEdge('platform.e[45]', t=(0, -.1, 0)) cmds.polyMoveEdge('platform.e[48]', t=(0, -.1, 0)) cmds.polyMoveEdge('platform.e[51]', t=(0, -.1, 0)) cmds.polyMoveEdge('platform.e[54]', t=(0, -.1, 0)) cmds.polyMoveEdge('platform.e[57]', t=(0, -.1, 0)) cmds.polyMoveEdge('platform.e[60]', t=(0, -.1, 0)) cmds.polyMoveEdge('platform.e[63]', t=(0, -.1, 0)) cmds.polyMoveEdge('platform.e[66]', t=(0, -.1, 0)) cmds.polyMoveEdge('platform.e[69]', t=(0, -.1, 0)) cmds.polyMoveEdge('platform.e[72]', t=(0, -.1, 0)) cmds.polyMoveEdge('platform.e[75]', t=(0, -.1, 0)) cmds.polyMoveEdge('platform.e[78]', t=(0, -.1, 0)) platform()I would think that the long list of moveEdge commands can be condensed down into a list since its a range of numbers going by every third, but I can't seem to get the command to work. No matter if I attempt to write it either as the code below, or attempting to create a selection based on the edges, or any other weird combination I have attempted. cmds.polyMoveEdge('platform.e[30:78:3]', t=(0, -.1, 0))Clearly, I'm not doing slicing right but I can't seem to figure out how to do it properly. The error if it helps: My main questions are if there a way to condense down the polyMoveEdge command so that it isn't the same line repeated over and over again? Or is how it is written alright for such a short function?
RE: Code Clean-up and Maya/Python Slicing issues - Yoriz - Aug-05-2019 range can give you the required numbers for number in range(30, 81, 3): print(number) Using an f string to replace the number in a loopfor number in range(30, 81, 3): cmds.polyMoveEdge(f'platform.e[{number}]', t=(0, -.1, 0)) |