## MemReducedFlg.py Version 1.01

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

## All rights reserved.

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

"""

/// Make flange cuts to produce a reduced flange width.

///

/// Given 3 non-collinear points, define a plane and create a list of points about

/// point 1 and between points 2 and 3 to be used to make a radiused material cut.

/// User can be in any model orientation.

/// Developed by Bruce Vaughan, BV Detailing & Design, Inc. (October 2006)

/// URL: www.bvdetailing.com

/// Credit Paul Bourke for 'Rotate A Point About An Arbitrary Axis (3D)' (August 2002) and

/// 'Equation of a plane' (March 1989))

///

/// Version History:

///     Version 0.99 -   Test version

///     Version 1.00 (11/7/07) - Incorporate dimensions a, b, c

///     Version 1.01 (11/8/07) - Create function make_cut() to consolidate repetitive code

///                              Eliminate variable 'spaces'

///

/// Script will fail if the radius cut included angle is 180 degrees or greater

///

///

/// Go to 'Variables section to edit default values file path and file name

///

"""

# startup code begin

from macrolib.MemSelection import mem_select                # memAreaSelect

from macrolib.P3D import Plane3D

from macrolib.FileDefaults import import_data, export_data

from macrolib.ExceptWarn import formatExceptionInfo

from macrolib.PolarPt import PolarPt3D

from macrolib.PrintPtList import formatPtList

import types

import os

from math import floor, ceil, pi, sqrt

from param import yes_or_no, Dialog, dim_print, ClearSelection, ResponseNotOK

from mtrl_list import MtrlLocate, HoleLocate

from point import Point, PointLocate

from mtrl_cut import MtrlCut

 

# This will error in SDS/2 7.0:

from view import View

 

# startup code end

 

def run_script():

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

    ## Variables section

    # system path for defaults file

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

    # default values file

    def_file = "MemReducedFlg.txt"

    # no images in this version

    # image_path = os.path.join(os.getcwd(), "macro", "Images")

    # default to enable or disable the importing and exporting of dialog dictionary variables "Enable" "Disable"

    enable_default_import_export = "Enable"    

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

    ## Defaults Section

    # number of vertices along the cut

    no_spa = 32

    # distance from end of flange to start of radius cut

    dim_a = 12.0

    # radius cut length

    dim_b = 24.0

    # radius cut depth

    dim_c = 1.5

    # ['Left', 'Right', 'Both']

    which_end = 'Left'

    # cons_color = "Cyan"

    ## End variables and defaults section

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

    def radius_cut(mem, ptList, rot=(90.0,0,0)):

        #try:

        # mtrl cut begin

        mcut1 = MtrlCut()

        mcut1.mtrl = [mem.main_mtrl(), ]

        mcut1.rotate = rot

        for pt in ptList:

            mcut1.pts.append((pt, 0.0))

        mcut1.cut("Layout")

        return True

        #except:

            #Warning(formatExceptionInfo())

            #return False

        # mtrl cut end

 

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

    def make_cut(pt1, pt2, pt3, no_spa):

        b = Plane3D(pt1, pt3, pt2)

        b.three_pt_circle()

        a = Plane3D(b.M, pt1, pt2)

        actual_spa = a.pp/no_spa

        dst = actual_spa

        pt_list = [pt1, ]

        # Compile a list of points determined by the arc length

        # divided by the number of spaces

        for i in range(no_spa):

            pt_list.append(a.PointRotate3D(pt1, dst/a.Ra))

            dst += actual_spa

        pt_list.extend([b.M, pt1])

        # print formatPtList("Selected point list:", [pt1, pt2, pt3])

        # print formatPtList("Cut point list:", pt_list)

        radius_cut(bm, pt_list)

 

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

    ## import defaults data if enabled

    if enable_default_import_export == "Enable":

        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

    ## Main program

    while True:

        ClearSelection()

        # Select beam member

        bm_list = mem_select("Select a WF BEAM member", ['Beam',], ["W flange",])

        if bm_list is None:

            break

 

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

        dlg1 = Dialog("Radius Material Cut Options")

        dlg1.menu("print_doc", ("Yes", "No"), "No", "Print documentation only")

        dlg1.menu("which_end", ['Left', 'Right', 'Both'], which_end, "Cut which end of beam                               ")

        dlg1.entry("no_spa", no_spa, "Number of vertices                               ")

        dlg1.entry("dim_a", dim_print(dim_a), "Distance from end of flange to start of radius cut")

        dlg1.entry("dim_b", dim_print(dim_b), "Length of radius cut")

        dlg1.entry("dim_c", dim_print(dim_c), "Depth of radius cut")

        try:

            dd1 = dlg1.done()

        except ResponseNotOK:

            break

       

        for key, value in dd1.items():

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

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

        ## END DIALOG BOX 1 ------------------------------#

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

        if print_doc == "Yes":

            print __doc__

            break

       

        # Export defaults to disk if enabled

        if enable_default_import_export == "Enable":

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

       

        for bm in bm_list:

            if which_end in ['Left', 'Both']:

                #### CUT FLANGE LEFT END, NS

                pt1 = bm.left.location + bm.translate(bm.left.setback+dim_a+dim_b, 0.0, bm.bf/2)

                pt2 = pt1 + bm.translate(-dim_b, 0.0, 0.0)

                pt3 = pt2 + bm.translate(dim_b/2, 0.0, -dim_c)

                make_cut(pt1, pt2, pt3, no_spa)

 

                #### CUT FLANGE LEFT END, FS

                pt1 = bm.left.location + bm.translate(bm.left.setback+dim_a+dim_b, 0.0, -bm.bf/2)

                pt2 = pt1 + bm.translate(-dim_b, 0.0, 0.0)

                pt3 = pt2 + bm.translate(dim_b/2, 0.0, dim_c)

                make_cut(pt1, pt2, pt3, no_spa)

               

            if which_end in ['Right', 'Both']:

                #### CUT FLANGE RIGHT END, NS

                pt1 = bm.right.location + bm.translate(-(bm.right.setback+dim_a+dim_b), 0.0, bm.bf/2)

                pt2 = pt1 + bm.translate(dim_b, 0.0, 0.0)

                pt3 = pt2 + bm.translate(-dim_b/2, 0.0, -dim_c)

                make_cut(pt1, pt2, pt3, no_spa)

 

                #### CUT FLANGE RIGHT END, FS

                pt1 = bm.right.location + bm.translate(-(bm.right.setback+dim_a+dim_b), 0.0, -bm.bf/2)

                pt2 = pt1 + bm.translate(dim_b, 0.0, 0.0)

                pt3 = pt2 + bm.translate(-dim_b/2, 0.0, dim_c)

                make_cut(pt1, pt2, pt3, no_spa)

               

            v = View()

            v.member = bm           

            v.add("TOP FLANGE VIEW")

           

        if not yes_or_no("Cut more beams?"):

            break

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

if __name__ == '__main__':

    try:

        run_script()

    finally:

        ClearSelection()

        del run_script