# Operation with list elements

 08 August 2014 kiryha Expert   portfolio Kiryha Krysko 3D artist USA Operation with list elements With for loop we get construction like: ``````take 1 element from list do operation A repeat for next elements`````` How to achieve with pyMel this: ``````take 1 element from list do operation A take 2 element from list do operation B take 3 element from list do operation C repeat for next elements`````` __________________ 3D animation blog share quote
 08 August 2014 Borgfriend portfolio Neal Bürger Ludwigs Maximilians Universität Munich, Germany You probably should read up on the basics of Python: https://docs.python.org/2/tutorial/datastructures.html `````` for i in list: foo(i) def foo(item): #do something`````` __________________ www.lost-triangle.com share quote
 08 August 2014 kiryha Expert   portfolio Kiryha Krysko 3D artist USA >You probably should read up on the basics of Python: Well, since its 100% true your answer does not helps too much __________________ 3D animation blog Last edited by kiryha : 08 August 2014 at 01:30 PM. share quote
 08 August 2014 haggi Expert 3d freelancer Something like this? `````` ml = [1,2,3,4,5,6,7,8,9,10, 11, 12] for l in range(0, len(ml), 6): value = ml[l] doSomethingWithOneValue(value) twoValueList = ml[l+1:l+3] doSomethingTwoOneValue(twoValueList ) threeValueList = ml[l+3:l+6] doSomethingTwoOneValue(threeValueList )`````` __________________ www.renderwiki.com - www.openmaya.net share quote
 08 August 2014 djx Where's my pony?   David Johnson vfx & creature td Melbourne, Australia I would have suggested either using a dictionary or a 2nd list, even though I'm unclear what you are trying to achieve. ``````elementList = ['e1', 'e2', 'e3'] def opA(e): print 'A',e def opB(e): print 'B',e def opC(e): print 'C',e # either dictionary operators = {0:opA, 1:opB, 2:opC} for i,element in enumerate(elementList): operators[i](element) # or 2nd list operators = [opA, opB, opC] for op, element in zip(operators, elementList): op(element)`````` David __________________ http://www.djx.com.au share quote
 08 August 2014 kiryha Expert   portfolio Kiryha Krysko 3D artist USA Well, i think not quite. This code ``````ml = [1,2,3,4,5,6,7,8,9,10, 11, 12] for l in range(0, len(ml), 6): value = ml[l] print 'A' + str( value) twoValueList = ml[l+1:l+3] print 'B' + str(twoValueList) threeValueList = ml[l+3:l+6] print 'C' + str (threeValueList)`````` produce ``````A1 B[2, 3] C[4, 5, 6] A7 B[8, 9] C[10, 11, 12]`````` I need to get ``````A [1,2,3] B [4,5,6] C [7,8,9] D [10, 11, 12]`````` __________________ 3D animation blog share quote
 08 August 2014 kiryha Expert   portfolio Kiryha Krysko 3D artist USA Im writing script for automatic creation of object IDs for Arnold Here what i have working — for each selected object or group i create AOV, create attribute on object, make this attribute white and feed this color to AOV. I cant get how to build it to use 3 color instead of 1, which will reduce quantity of IDs 3 times. ``````import pymel.core as pm import mtoa.aovs as aovs # set rebder to Arnold renderSet = pm.PyNode('defaultRenderGlobals') renderSet.ren.set('arnold') def checkID(*args): if pm.objExists('aiAOV_objectID_*'): pm.select('aiAOV_objectID_*') exist = pm.ls(sl = True)[-1] exist = exist.split('_')[2] pm.select (d = True) else: exist = 0 return exist def addAOV( index ): # Creates AOV render pass aovName = 'objectID_' + str(index) aovs.AOVInterface().addAOV( aovName ) return aovName def addColor(index): #create color attribute colorAttrName = 'mask_' + str(index) colorAttrNameLong = 'mtoa_constant_' + str(colorAttrName) pm.addAttr( longName= colorAttrNameLong , niceName = colorAttrName , usedAsColor=True, attributeType='float3' ) pm.addAttr( longName='R' + str(colorAttrName), attributeType='float', parent=colorAttrNameLong ) pm.addAttr( longName='G' + str(colorAttrName), attributeType='float', parent=colorAttrNameLong ) pm.addAttr( longName='B' + str(colorAttrName), attributeType='float', parent=colorAttrNameLong ) return colorAttrNameLong def createID(index): # create AOV and plug aiUserDatacolor mskObjectMat = pm.shadingNode('aiUserDataColor', asShader=True, name = 'catchMask_' + str('%02d' % index) ) mskObjectMat.colorAttrName.set('mask_' + str('%02d' % index)) objectID = addAOV ('%02d' % index) objectIDFull = 'aiAOV_' + str(objectID) ID = pm.PyNode(objectIDFull) mskObjectMat.outColor >> ID.defaultValue sel = pm.ls(sl = 1) #select jbject for object IDs index = float(checkID()) + 1 for i in sel: createID(index) pm.select(i) pm.runtime.SelectHierarchy() selShapes = pm.ls(sl = 1, shapes = True) pm.select(selShapes) msk = addColor('%02d' %index) for e in selShapes: #set mask color to white attr = str(e) + '.mtoa_constant_mask_' + str('%02d' % index) pm.setAttr(attr, [1,1,1]) index += 1`````` __________________ 3D animation blog share quote
 08 August 2014 djx Where's my pony?   David Johnson vfx & creature td Melbourne, Australia ``````elementList = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17] def opA(e): print 'A',e def opB(e): print 'B',e def opC(e): print 'C',e operators = {0:opA, 1:opB, 2:opC} for i,element in enumerate(elementList): operators[i/3%3](element)`````` David __________________ http://www.djx.com.au share quote

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off CGSociety Society of Digital Artists www.cgsociety.org Powered by vBulletinCopyright ©2000 - 2006, Jelsoft Enterprises Ltd.