Back to SDS/2 Parametric Scripts

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

## All rights reserved.

## Member_Attributes.py Version 1.02

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

"""

Display all available member and material attributes

Version 1.01 (11/11/06)

Version 1.02 (9/24/07)

"""

# startup code begin

from member import Member, MemberLocate

import types

from param import dim_print, Units, ClearSelection

from point import Point, PointLocate

from mtrl_list import MtrlLocate, HoleLocate

# Units("metric")

Units("feet")

# startup code end

def run_script():

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

    def mtrl_UV(m):

        pt2 = m.pt1 + m.translate(m.work_pt_dist, 0.0, 0.0)

        return Point((pt2.x-m.pt1.x)/m.work_pt_dist, (pt2.y-m.pt1.y)/m.work_pt_dist, (pt2.z-m.pt1.z)/m.work_pt_dist)

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

    #mem1 = Member(50)

    ClearSelection()

    mem1 = MemberLocate("Select a MEMBER")

    if mem1.type == 'Misc':

        print 'dir(mem1) =', dir(mem1)

        print 'type(mem1) =', type(mem1)

        misc_att_list = ['type', 'number', 'piecemark', 'plan_rotation', 'slope', 'sequence', 'left.location', 'right_location',\

                         'translate', 'trans_to_local', 'trans_to_global', 'main_mtrl', 'detail_quantity']

        misc_att_list.sort()

        print "Known Misc member attributes and built-in methods:"

        for i in misc_att_list:

            try:

                eval('mem1.' + i)

            except:

                print "'mem1.%s' is not a valid attribute for this material." % (i)

            else:

                print "'mem1.%s' = %s" % (i, eval('mem1.' + i))

        print "\nDistance between mem1.left.location and mem1.right.location = %0.4f" % (mem1.left.location.dist(mem1.right.location))

        try:

            print "\nMisc member unit vector: %s" % (mtrl_UV(mem1.main_mtrl()))

        except:

            print "\nThere is no main material on the selected miscellaneous member."

    else:

        # print mem1.__members__

        memberside_list = []

        method_list = []

        print "Member attributes listed by dir(mem1):"

        print "mem1.number =", mem1.number

        for i in range(len(dir(mem1))):

            try:

                eval('mem1.' + dir(mem1)[i])

            except:

                print "'" + dir(mem1)[i] + "'", "is not a valid attribute or method for this member type."

            else:

                _value_ = eval('mem1.' + dir(mem1)[i])

                if isinstance(_value_, types.FloatType):

                    print 'mem1.' + dir(mem1)[i], "=", _value_

                elif isinstance(_value_, types.IntType):

                    print 'mem1.' + dir(mem1)[i], "=", _value_

                elif isinstance(_value_, types.StringType):

                    print 'mem1.' + dir(mem1)[i], "=", _value_

                elif isinstance(_value_, types.BuiltinMethodType) or isinstance(_value_, types.BuiltinFunctionType):

                    method_list.append(dir(mem1)[i])

                else:

                    memberside_list.append(dir(mem1)[i])

                   

        if len(memberside_list) > 0:

            print "\nMember 'memberside' attributes listed by dir(mem1):"

            side_att_list = []

            for i in range(len(memberside_list)):

                for j in range(len(dir(eval('mem1.' + memberside_list[i])))):

                    side_att_list.append('mem1.' + memberside_list[i] + "." + dir(eval('mem1.' + memberside_list[i]))[j])

            for i in side_att_list:

                try:

                    eval(i)

                except:

                    print i , "is not a valid attribute or method for this member type"

                else:

                    print i, "=", eval(i)

                   

        if len(method_list) > 0:

            print "\nMember built-in methods listed by dir(mem1):"

            meth_att_list = []

            for i in range(len(method_list)):

                meth_att_list.append('mem1.' + method_list[i])

            for i in meth_att_list:

                try:

                    eval(i)

                except:

                    print i , "is not a valid attribute or method for this member type"

                else:

                    print i, "is a", eval(i)

 

        print "\nMember 'material()' attributes and built-in methods listed by dir(mem1.material()):"

        print 'mem1.material().piecemark =', mem1.material().piecemark

        try:

            dir(mem1.material())

        except:

            print "There are no material() attributes or methods for", mem1.type, "members."

        else:

            for i in dir(mem1.material()):

                try:

                    _value_ = eval('mem1.material().' + i)

                except:

                    print 'mem1.material().' + i, "is not a valid attribute or method for this member type."

                else:

                    print 'mem1.material().' + i, "=", _value_

                   

        print "\nMember 'main_mtrl()' attributes and built-in methods listed by dir(mem1.main_mtrl()):"

        print 'mem1.main_mtrl().piecemark =', mem1.main_mtrl().piecemark

        try:

            dir(mem1.main_mtrl())

        except:

            print "There are no main_mtrl() attributes or methods for", mem1.type, "members."

        else:

            for i in dir(mem1.main_mtrl()):

                try:

                    _value_ = eval('mem1.main_mtrl().' + i)

                except:

                    print 'mem1.main_mtrl().' + i, "is not a valid attribute or method for this member type."

                else:

                    print 'mem1.main_mtrl().' + i, "=", _value_

 

        print "\nMember 'shape()' attributes and built-in methods listed by dir(mem1.shape()):"

        try:

            dir(mem1.shape())

        except:

            print "There are no shape() attributes or methods for", mem1.type, "members."

        else:

            for i in dir(mem1.shape()):

                try:

                    _value_ = eval('mem1.shape().' + i)

                except:

                    'mem1.shape().' + i, "is not a valid attribute or method for this member type."

                else:

                    print 'mem1.shape().' + i, "=", _value_

                   

        print "\nAttempting to access member 'add()' and 'rotate()' attributes is not recommended and can cause problems."

           

        print "\nMaterials found on member", mem1.piecemark + ", member number", str(mem1.number) + ":"

        i = 0

        mem_weight = 0.0

        while 1:

            try:

                mem1.material(i)

            except:

                #if sys.exc_info()[1].__dict__['args'][0] == 'Cannot find material':

                    #print "Invalid material index"

                #print sys.exc_info()[0]

                #print sys.exc_info()[1]

                #print sys.exc_info()[2]

                #print_tb(sys.exc_info()[2])

                break

            else:

                print "Material index         =", i

                print "Material object        =", mem1.material(i)

                print "Material description   =", mem1.material(i).description

                print "Material piecemark     =", mem1.material(i).piecemark

                print "Material mtrl_type     =", mem1.material(i).mtrl_type

                print "Material WP (pt1)      =", dim_print(mem1.material(i).pt1.x) + ",", dim_print(mem1.material(i).pt1.y) + ",", dim_print(mem1.material(i).pt1.z)

                print "Material pt1           =", mem1.material(i).pt1

                print "Calculated pt2         =", mem1.material(i).pt1 + mem1.material(i).translate(mem1.material(i).work_pt_dist, 0.0, 0.0)

                print "Unit Vector pt1pt2     =", mtrl_UV(mem1.material(i))

                print "Material setback_left  =", mem1.material(i).setback_left

                print "Material setback_right =", mem1.material(i).setback_right

                print "Material work_pt_dist  =", mem1.material(i).work_pt_dist

                print "Material length        =", mem1.material(i).length

                print "Material weight        =", mem1.material(i).weight

                print "Material grade         =", mem1.material(i).grade

                print "Material finish        =", mem1.material(i).finish, "\n"

                mem_weight += mem1.material(i).weight

                i = i+1

        print "Member total weight = %0.4f" % (mem_weight)

 

    mtrl_att_list = ['pt1', 'pt2', 'section_size', 'description', 'grade', 'centered', 'origin', 'top_oper_left', 'top_length_left', 'top_cope_left',\

                            'top_oper_right', 'top_length_right', 'top_cope_right', 'bottom_oper_left', 'bottom_length_left', 'bottom_cope_left', 'bottom_oper_right',\

                            'bottom_oper_right', 'bottom_length_right', 'bottom_cope_right', 'llv', 'toe_io', 'rolling_op', 'width', 'thick', 'field_weld_prep_left',\

                            'field_weld_prep_right', 'reent_hole_dist_left', 'reent_hole_dist_right', 'cut_radius_left', 'cut_radius_right', 'top_clip_left', 'top_clip_right',\

                            'web_setback_left', 'web_setback_right', 'angle_of_twist', 'mid_ordinate',\

                            'bend_angle', 'bend_radius', 'rolled_offset', 'work_pt_dist', 'setback_left', 'setback_right', 'web_cut_angle_left', 'web_cut_angle_right',\

                            'flange_cut_left', 'flange_cut_right', 'end_cut_left', 'end_cut_right', 'length', 'mtrl_type', 'finish', 'ref_pt_offset', 'translate',\

                            'to_local', 'to_global', 'trans_to_local', 'trans_to_global', 'mtrl_usage', 'depth', 'category_defs', 'piecemark', 'weight']

    print "\nKnown member main material attributes and built-in methods:"

    print 'mem1.main_mtrl()', "=", mem1.main_mtrl()

    mtrl_att_list.sort()

    mtrl_pt2 = mem1.main_mtrl().pt1 + mem1.main_mtrl().translate(mem1.main_mtrl().work_pt_dist, 0.0, 0.0)

    for i in mtrl_att_list:

        try:

            eval('mem1.main_mtrl().' + i)

        except:

            if i == 'pt2':

                print "'mem1.main_mtrl().pt2' is not valid. Calculated pt2 =", mtrl_pt2

            else:

                print "'mem1.main_mtrl()." + i + "' is not a valid attribute for this material."

        else:

            print 'mem1.main_mtrl().' + i + " =", eval('mem1.main_mtrl().' + i)

    print "\nThe member main material attributes and built-in methods listed above are available for 'gen_mtrl' objects."

    #print "There is no access to mem1.main_mtrl().add() or mem1.main_mtrl().rotate() methods."

    #print sys.stdin

    #print sys.stdout

    #print sys.stderr

## END run_script() ################################

if __name__ == '__main__':

    try:

        run_script()

    finally:

        ClearSelection()

        del run_script