##  Mem_Weight_By_Seq.py Version 1.00

##  Copyright (c) 2007 Bruce Vaughan, BV Detailing & Design, Inc.

##  NOT FOR SALE. The software is provided "as is" without any warranty.

############################################################################

"""

Tabulate the total weight of members by sequence.

Sample usage:

dd = memWeightBySeq(['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16'])

'dd' is a dictionary compiled with the weights of sequences 1 through 16.

"""

from mtrl_list import MtrlLocate

from member import Member, MemberLocate, MemberAllocated

import re

def mem_mtrl_list(mem):

ml = []

i = 0

while 1:

try:

m = mem.material(i)

ml.append(m)

i += 1

except:

return ml

def mem_weight(mtrl_list):

return sum([m.weight for m in mtrl_list])

def memWeightBySeq(seq_list=['1', ]):

memList = []

# p = re.compile(r'%s' % '|'.join(seq_list))

for mi in xrange(1, MemberAllocated()):

try:

mem = Member(mi)

except:

pass

else:

# if p.match(mem.sequence):

if mem.sequence in seq_list:

memList.append(mem)

memDict = dict.fromkeys(['%03s' % s for s in seq_list], 0.0)

for mem in memList:

memDict['%03s' % mem.sequence] += mem_weight(mem_mtrl_list(mem))

return memDict

dd = memWeightBySeq(['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16'])

keyList = dd.keys()

keyList.sort()

for key in keyList:

print 'Sequence %s weight = %0.0f' % (key, dd[key])

mem_weight = sum([dd[key] for key in dd])

print '\nTotal weight of members is %0.2f' % (mem_weight)