##  JoistMtrl.py Version 1.04

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

##  All rights reserved.

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

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

 

## Version 1.01 (8/5/07) -  Add ClearSelection() to work in SDS/2 7.1xx

## Version 1.02 (10/5/07) - Add dialog box, encapsulate in run_script()

##                          Material file browse

##                          Add bottom chord extensions

##                          Save default values

## Version 1.03 (10/7/07) - Convert web_dia to float in dd1

## Version 1.04 (10/8/07) - Make correction to web_dia assignment

 

###### THIS VERSION WILL NOT WORK IN SDS/2 VERSIONS PRIOR TO 7.105 ####

 

# Add joist web and chord material

from member import Member, MemberLocate

from param import *

from point import Point, PointLocate

from rnd_bar import RndBar

from rolled_section import RolledSection

from math import *

import os

# from macrolib.MemCnt import member_count

from macrolib.MemSelection import mem_select

from macrolib.FileDefaults import import_data, export_data

 

def run_script():

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

    ## Variables section

    # system path for defaults file

    default_file_path = os.path.join(os.getcwd(), "macro", "Defaults")

 

    # defaults file name

    def_file = "JoistMtrl.txt"

 

    web_diaList = ['0','1/4','3/8','1/2','5/8','3/4','7/8','1']

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

    ## Defaults section

    web_dia = 0.5

    # ["None", "Red Oxide", "Yellow Zinc", "Gray Oxide", "Sandblasted", "Blued Steel", "Galvanized"]

    web_finish = "Yellow Zinc"

    web_grade = 'A36'

    chord_mtrl = 'L1 1/2x1 1/2x3/16'

    chord_grade = 'A36'

    chord_finish = "Gray Oxide"

    chord_extend = 4.0

    bc_ext_left = 'No'

    bc_set_left = 4.5

    bc_ext_right = 'No'

    bc_set_right = 4.5

 

    def add_web(mem, pt, dist, a):

        rb1 = RndBar()

        rb1.member = mem

        rb1.pt1 = pt

        rb1.pt2 = pt + mem.translate(dist, 0.0, 0.0)

        rb1.grade = web_grade

        rb1.centered = "Yes"

        rb1.bar_diameter = web_dia

        rb1.work_pt_dist = dist

        rb1.length = dist

        rb1.mtrl_type = "Round bar"

        rb1.mtrl_usage = 'Joist Web'

        rb1.finish = web_finish

        rb1.ref_pt_offset = (0, 0, 0)

        rb1.add()

        rb1.rotate(rb1.member, (0.000000, 0.000000, a))

 

    def add_chord(mem, pt1, pt2, toe_dir, a):

        rl1 = RolledSection()

        rl1.member = mem

        rl1.pt1 = pt1

        rl1.pt2 = pt2

        rl1.section_size = chord_mtrl

        rl1.grade = chord_grade

        rl1.centered = 'No'

        rl1.llv = 'HZ.'

        rl1.toe_io = toe_dir

        rl1.work_pt_dist = pt1.dist(pt2)

        rl1.end_cut_left = "Standard Cut"

        rl1.end_cut_right = "Standard Cut"

        rl1.length = pt1.dist(pt2)

        rl1.mtrl_type = 'Angle'

        rl1.finish = chord_finish

        rl1.mtrl_usage = 'Joist Chord'

        rl1.ref_pt_offset = (0.000000, 0.000000, 0.000000)

        rl1.add()

        rl1.rotate(rl1.member, (a, 0.000000, 0.000000))

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

    ## Import default values

    dd0 = import_data(os.path.join(default_file_path, def_file))

    if dd0:

        for key, value in dd0.items():

            exec "%s = %s" % (key, repr(value)) in None

 

    while True:

        ClearSelection()

        jst_list = mem_select("Select a JOIST", ['Joist', ], ['All', ])

        mem = jst_list[0]

       

        ## DIALOG BOX 1 #################################

        dlg1 = Dialog("Joist Material")

        dlg1.group_title("Materials")

        dlg1.mtrl_browse( 'chord_mtrl', ("Angle",), chord_mtrl, "Chord material size" )

        dlg1.menu("web_dia", web_diaList, dim_print(web_dia), "Diameter of web members")

        dlg1.group_title("Bottom Chord Extensions")

        dlg1.menu("bc_ext_left", ['Yes', 'No'], bc_ext_left, "Extend BC left end")

        dlg1.entry("bc_set_left", dim_print(bc_set_left), "Left end setback")

        dlg1.menu("bc_ext_right", ['Yes', 'No'], bc_ext_right, "Extend BC right end")

        dlg1.entry("bc_set_right", dim_print(bc_set_right), "Left end setback")

        try:

            dd1 = dlg1.done()

        except ResponseNotOK:

            break

 

        # When fraction is selected from menu in dialog box, 'str' type is retained.

        # Convert 'str' to 'float' using 'param.dim'

       

        dd1["web_dia"] = dim(dd1["web_dia"])

       

        for key, value in dd1.items():

            exec "%s = %s" % (key, repr(value)) in None

 

        export_data(os.path.join(default_file_path, def_file), dd1)

 

        # series = mem.series # 'K'

        # mem.left.conn_setback

        for mem in jst_list:

            ## ADD WEB MATERIAL ###############################

            rise = mem.depth-1

            run = mem.left.location.dist(mem.right.location)-12-mem.left.setback-mem.right.setback

            panels = int(run/(rise*2))

            panel_width = (run/panels)

 

            ptWP = mem.left.location + mem.translate(mem.left.setback+6.0, -0.5, 0.0)

            ptListTop = [ptWP+mem.translate(panel_width*i, 0.0, 0.0) for i in range(panels)]

            ptListBott = [ptWP+mem.translate(panel_width*i+panel_width/2, -rise, 0.0) for i in range(panels)]

                        

            diag = (rise**2 + (panel_width/2)**2)**0.5

            angle_deg = atan2(rise, (panel_width/2)) * 180.0 / pi

 

            if web_dia > 0.0:

                for pt in ptListTop:

                    add_web(mem, pt, diag, -angle_deg)

 

                for pt in ptListBott:

                    add_web(mem, pt, diag, angle_deg)

               

            ## ADD CHORD MATERIAL #############################

            ptWP1 = mem.left.location + mem.translate(mem.left.setback-mem.left.conn_setback, 0.0, web_dia/2)

            ptWP2 = mem.right.location + mem.translate(-mem.right.setback+mem.right.conn_setback, 0.0, web_dia/2)

            ptWP3 = mem.left.location + mem.translate(mem.left.setback-mem.left.conn_setback, 0.0, -web_dia/2)

            ptWP4 = mem.right.location + mem.translate(-mem.right.setback+mem.right.conn_setback, 0.0, -web_dia/2)

 

            if bc_ext_left == 'Yes':

                ptListBott[0] = mem.left.location + mem.translate(chord_extend + bc_set_left, -rise - 0.5, 0.0)

            if bc_ext_right == 'Yes':

                ptListBott[-1] = mem.right.location + mem.translate(-chord_extend - bc_set_right, -rise - 0.5, 0.0)

           

            ptWP5 = ptListBott[0] + mem.translate(-chord_extend, -0.5, -web_dia/2)

            ptWP6 = ptListBott[-1] + mem.translate(chord_extend, -0.5, -web_dia/2)

            ptWP7 = ptListBott[0] + mem.translate(-chord_extend, -0.5, web_dia/2)

            ptWP8 = ptListBott[-1] + mem.translate(chord_extend, -0.5, web_dia/2)

 

            add_chord(mem, ptWP1, ptWP2, 'In', 0.0)

            add_chord(mem, ptWP3, ptWP4, 'Out', 0.0)

            add_chord(mem, ptWP5, ptWP6, 'In', 180.0)

            add_chord(mem, ptWP7, ptWP8, 'Out', 180.0)

 

            ClearSelection()       

 

        if not yes_or_no('Select another joist?'):

            break

 

## end run_script() #########################################################

if __name__ == '__main__':

    try:

        run_script()

    finally:

        ClearSelection()

        del run_script