Back to SDS/2 Parametric Scripts

 

##MemCnt.py Version 1.03 (module 'MemCnt')

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

##All rights reserved.

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

"""

/// Return a list of members with the same piecemark as the argument 'mem'.

/// If argument 'mem' is a member, the first member in the list is the argument member.

/// If argument 'mem' is a string, the list will contain all the members with a piecemark

/// matching string 'mem'.

///

/// Version 1.02 (11/27/06) -   Modify type checking for string and object

///                             Eliminate import types

/// Version 1.03 (1/23/07) -    Eliminate variable 'mi and while loop

///                             Incorporate xrange on MemberAllocated() into a for loop

"""

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

## Return list of members with the same piecemark.

## If argument 'mem' is a member type, the first member in the list is 'mem'.

## Argument 'mem' can be a string (the member piecemark) or member object.

def member_count(mem):

    from member import Member, MemberAllocated

    from param import Warning

    from macrolib.ExceptWarn import formatExceptionInfo

   

    if isinstance(mem, str):

        mem_list = []

        mem_mk = mem

        mem_no = 0

    elif isinstance(mem, object): 

        try:

            mem_mk = mem.piecemark

        except AttributeError, e:

            Warning(formatExceptionInfo())

        mem_list = [mem, ]

        mem_no = mem.number

    else:

        raise TypeError, 'Improper argument type passed to member_count()'

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

        try:

            mem2 = Member(mi)

        except:

            pass

        else:

            if mem2.number != mem_no:

                if mem2.piecemark == mem_mk:

                    mem_list.append(mem2)

    return mem_list

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

def test_member_count():

    from member import Member, MemberLocate

    from param import Dialog, yes_or_no, ResponseNotOK

    from macrolib.ExceptWarn import formatExceptionInfo

    try:   

        mem_mark = Member(1).piecemark

        while 1:

            mem1 = MemberLocate("Determine member mark quantity. Pick a member or RETURN to enter mark.")

            if mem1 == None:

                dlg1 = Dialog("Determine Member Mark Quantity")

                dlg1.entry("mem_mark", mem_mark, "Enter member mark")

                try:

                    dlg1.done()

                except ResponseNotOK:

                    break

                mem1_list = member_count(dlg1.mem_mark)

            else:

                mem1_list = member_count(mem1)

            if len(mem1_list) > 1:

                print "%s Members Counted:" % (len(mem1_list))

            else:

                print "One Member Counted:"

            for i in mem1_list:

                print "Member Number = %s  Piecemark = %s" % (i.number, i.piecemark)

            print "\n"

            if len(mem1_list) > 1:

                _str =  "%s members with piecemark %s were counted. Continue?" % (len(mem1_list), mem1_list[0].piecemark)

            else:

                _str = "One member with piecemark %s was counted. Continue?" % (mem1_list[0].piecemark)

            if not yes_or_no(_str):

                break

    except:

        Warning(formatExceptionInfo())

## END test_member_count() ###########################################################

if __name__ == '__main__':

    try:

        test_member_count()

    finally:

        del test_member_count