Skip to content
Snippets Groups Projects
add_mesh_beam_builder.py 46.1 KiB
Newer Older
bl_info = {
    "name": "Beam Builder",
    "description": "Creates various types of beams.",
    "author": "revolt_randy",
    "version": (0, 1, 2),
    "blender": (2, 5, 6),
    "location": "View3D > Add > Mesh",
    "warning": "Currently under development.", 
    "wiki_url": "",
    "tracker_url": "",
    "category": "Add Mesh"}
       
# Version History
#
# v0.1 - Script only generates a multi-sided mesh object,
#           initial release for testing. 3/12/11
#
# v0.1.1 - Added 'C'-type beam, updated to work with 
#           api r35499. 3/13/11
#
# v0.1.2 - Totally changed the way beams are created, size
#           is now calculated based off width, length, & height
#           (x,y,z). Added ability to taper beams as well.
#           Add 'L' - type beam
#           Add 'T' - type beam
#           Add 'I' - type beam      

# Creates a rectangluar, or 'C', or 'L' or 'T' or 'I' - type beam.

import bpy
import math
import mathutils
#import space_info

# The following bit of code was taken from spindle.py
# a script by Campbell Barton that creates a spindle mesh.
# The script was found someplace at blender.org
# Code determines the align_matrix to align the new object to 
def align_matrix(context):
    loc = mathutils.Matrix.Translation(context.scene.cursor_location)
    obj_align = context.user_preferences.edit.object_align
    if (context.space_data.type == 'VIEW_3D'
        and obj_align == 'VIEW'):
        rot = context.space_data.region_3d.view_matrix.rotation_part().invert().resize4x4()
    else:
        rot = mathutils.Matrix()
    align_matrix = loc * rot
    return align_matrix


def create_mesh (name, verts, faces, align_matrix):
    # Creates mesh and object
    # name - name of object to create
    # verts - a list of vertex tuples
    # faces - a list of face tuples
    # align_matrix - alignment of the mesh based on user prefs - see above code
    
    # Check if in edit mode, if so, get name of active object and enter object mode
    if bpy.context.mode == 'EDIT_MESH':
        # toggle to object mode
        bpy.ops.object.editmode_toggle()
        # get name of active object
        obj_act = bpy.context.scene.objects.active
        #print ("\n\nTRAP WORKS", "\nactive object =", obj_act)
    else:
        obj_act = False
     
    # Unselect any objects
    bpy.ops.object.select_all(action="DESELECT")
    
    # Actually create mesh and object
    mesh = bpy.data.meshes.new(name)
    obj = bpy.data.objects.new(name, mesh)

    # add verts & faces to object
    mesh.from_pydata(verts, [], faces)
    mesh.update(calc_edges=True)    
    
    # Move object to 3d cursor & align
    #obj.location = bpy.context.scene.cursor_location
    obj.matrix_world = align_matrix
        
    # link object to scene 
    bpy.context.scene.objects.link(obj)

    #print(obj_act, obj)
    
    # Were we in edit mode - if so need to join new mesh to active mesh object
    if obj_act:
        bpy.ops.object.select_all(action="DESELECT")
        # Select first object
        obj_act.select = True
        # Select new object
        obj.select = True  
        # Join objects     
        bpy.ops.object.join()
         
        #print("\n\n2nd TRAP Works")

    else:
        # Not in edit mode, so just make new object active object 
        bpy.context.scene.objects.active = obj
        obj.select = True
        
    # Enter edit mode
    bpy.ops.object.editmode_toggle()
    
    # Recalcuate normals
    bpy.ops.mesh.normals_make_consistent()
    
    # Return to object mode if mesh created in object mode
    if not obj_act:
        bpy.ops.object.editmode_toggle()
    
    return


def create_end_faces(verts_list, thick, debug):
    # Create End Faces
    # verts_list - list of vertices
    # thick - if true object is hollow, so construct loop of end faces
    #           instead of a solid end face
    # debug - if true prints values from this function to console
    
    # returns:
    # faces - a list of tuples defining the end faces
    
    faces = []
    
    num_of_verts = len(verts_list)
    faces_temp = []

    sides = 4 # sides - number of sides to mesh *added because of code re-write
    
    if thick:
        # has thickness, so build end faces            
        num_of_verts = int(num_of_verts / 2)
        
        # Create a list of the front faces
        for index in range(num_of_verts):
            if index == (num_of_verts - 1):
                faces_temp.append(verts_list[index])
                faces_temp.append(verts_list[index-index])
                faces_temp.append(verts_list[index+1])
                faces_temp.append(verts_list[index*2+1])
            else:
                faces_temp.append(verts_list[index])
                faces_temp.append(verts_list[index+1])
                faces_temp.append(verts_list[index+num_of_verts+1])
                faces_temp.append(verts_list[index+num_of_verts])
                        
            faces.append(tuple(faces_temp))
            faces_temp = []                
    else:
        #this code may not be needed, depends upon rewrite...
        if sides > 4:
            # more than 4 sides, so replace last list item (center vert) with first list item 
            # for looping and building faces
            center_vert = verts_list[num_of_verts - 1]
            verts_list[num_of_verts - 1] = verts_list[0]

            for index in range(int(num_of_verts - 1)):
                faces_temp.append(verts_list[index])
                faces_temp.append(verts_list[index + 1])
                faces_temp.append(center_vert)
                faces.append(tuple(faces_temp))
                faces_temp = []
        
        else:
            # create 1 end face
            for index in range(num_of_verts):
                faces_temp.append(verts_list[index])
            faces.append(tuple(faces_temp))               
    
    # print debug info to console
    if debug:
        print("\ncreate_end_faces Function Starts")
        print("\n End Face Verts list :", verts_list)
        print("\n End Faces: ", faces)
        print("\ncreate_end_faces Function Ends\n\n")
            
    return faces


def create_side_faces(front_verts, back_verts, debug):
    # Create side faces - simple bridging of front_verts & back_verts vertices,
    #                     both front_verts & back_verts must be ordered in same direction
    #                     with respect to y-axis
    # front_verts - a list of front face vertices
    # back_verts - a list of back face vertices
    # debug - if true prints values from this function to console
    
    # returns:
    # new_faces - a list of tuples defining the faces bridged between front_verts & back_verts
    
    # Number of faces to create
    num_of_faces = (len(front_verts))
    new_faces = []
    
    # add first value to end of lists for looping
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373
    front_verts.append(front_verts[0])
    back_verts.append(back_verts[0])
    
    # Build the new_faces list with tuples defining each face    
    for index in range(num_of_faces):
        facestemp = (front_verts[index], front_verts[index+1], back_verts[index+1], back_verts[index])
        new_faces.append(facestemp)
    
    # print debug info to console
    if debug:
        print("\ncreate_side_faces Function Starts") 
        print("\n Number of faces to create: ", num_of_faces)
        print("\n New faces :", new_faces)
        print("\ncreate_side_faces Function Ends\n\n")

    return new_faces


def calc_end_verts(size, y_off, thick, debug):
    # Calculates vertex location for end of mesh
    
    # size - tuple of x,y,z dimensions of mesh to create
    # y_off - y offset, lets function know where to create verts on y-axis
    # thick - thickness, if not zero this is the thickness of a hollow mesh
    #         with the inner faces inset from size dimensions
    # debug - if true prints values from this function to console
    
    # returns:
    # verts - a list of tuples of the x,y,z location of each vertex
    
    verts = []
    
    if debug:
        print ("\ncalc_end_verts Function Starts\n")
    
    print("\nsize = ",size)
    print("y_off = ",y_off)
        
    # Create vertices by calculation 
    x_pos = 0 + size[0]/2
    z_pos = 0 + size[2]/2
    verts.append((x_pos, y_off, z_pos))

    x_pos = 0 - size[0]/2
    z_pos = 0 + size[2]/2
    verts.append((x_pos, y_off, z_pos))
    
    x_pos = 0 - size[0]/2
    z_pos = 0 - size[2]/2
    verts.append((x_pos, y_off, z_pos)) 
    
    x_pos = 0 + size[0]/2
    z_pos = 0 - size[2]/2
    verts.append((x_pos, y_off, z_pos))   
         
    if thick:
        # has thickness, so calculate inside vertices
        #### not too sure about this, but it does work the way the 
        #### solidify modifier works, so leaving as is for now
        x_pos = size[0] - (thick * 2)
        z_pos = size[2] - (thick * 2)
        size = (x_pos, y_off, z_pos)
        
        # Create vertices by calculation 
        x_pos = 0 + size[0]/2
        z_pos = 0 + size[2]/2
        verts.append((x_pos, y_off, z_pos))

        x_pos = 0 - size[0]/2
        z_pos = 0 + size[2]/2
        verts.append((x_pos, y_off, z_pos))
    
        x_pos = 0 - size[0]/2
        z_pos = 0 - size[2]/2
        verts.append((x_pos, y_off, z_pos)) 
    
        x_pos = 0 + size[0]/2
        z_pos = 0 - size[2]/2
        verts.append((x_pos, y_off, z_pos))          
            
    if debug:
        print ("verts :", verts)
        print ("\ncalc_end_verts Function Ends.\n\n")
    
    return verts


def adjust_c_beam_verts(verts, taper, debug):
    # Adjusts verts produced to correct c beam shape
    # verts - a list of tuples of vertex locations for one end of beam
    # taper - % to taper outside verts by
    # debug - if true values are printed to console for debugging
    
    # returns:
    # verts - the corrected list of tuples of the adjustec vertex locations
    
    # This function corrects vertex locations to properly shape the
    # beam, because creating a c beam uses the same code as the 
    # create_multi_side_box function does. Therefore the 5th & 6th
    # vertice's z location needs to be changed to match the 1st & 2nd
    # vertice's z location.

    vert_orig = verts[0]
    
    # get 3rd value, the z location
    vert_z = vert_orig[2] 
    # get 1st value, the x location, for vert taper calcs    
    vert_x = vert_orig[0]
  
    # vert_z has the z value to be used in the 5th & 6th verts
    # get value of 5th vert 
    vert_temp = verts[4]
    
    print ("vert_orig = ",vert_orig[0])
    print ("vert_x = ",vert_x)
    
    # calculate the amount of taper, updating vert_x
    # with the new value calculated.
    vert_x = calc_taper(vert_orig[0], vert_temp[0], taper)
    
    vert_new = (vert_x,vert_temp[1],vert_z)
    
    if debug:
        print("vert_temp =",vert_temp)
        print("vert_new =",vert_new)

    # update 5th vert with new value
    verts[4] = vert_new
    
    vert_orig = verts[1]
    
    # get 3rd value, the z location
    vert_z = vert_orig[2] 
    # get 1st value, the x location, for vert taper calcs    
    vert_x = vert_orig[0]
    # vert_z has the z value to be used in the 5th & 6th verts
    # get value of 5th vert 
    vert_temp = verts[5]
    
    print ("vert_orig = ",vert_orig[0])
    print ("vert_x = ",vert_x)
    
    # calculate the amount of taper, updating vert_x
    # with the new value calculated.
    vert_x = calc_taper(vert_orig[0], vert_temp[0], taper)
    
    vert_new = (vert_x,vert_temp[1],vert_z)
    
    if debug:
        print("vert_temp =",vert_temp)
        print("vert_new =",vert_new)
    
    # update 6th vert with new value
    verts[5] = vert_new    
    
    if debug:
        print("\n adjust_c_beam_verts function ending")
        print("verts =", verts)
        
    return verts        


def calc_taper(outer_vert, inner_vert, taper):
    # Calculate tapered edges of beam - inner vert is moved towards
    #    outer vert based upon percentage value in taper
    # outer_vert - the outside vertex
    # inner_vert - the inside vertex to be moved
    # taper - percentage to move vert
    
    # returns:
    # adjusted_vert - the calculated vertex

    #print("outer_vert =",outer_vert,"inner_vert",inner_vert)
    
    # taper values range from 0 to 100 for UI, but for calculations
    # this value needs to be flipped, ranging from 100 to 0
    taper = 100 - taper
    
    # calcuate taper & adjust vertex
    vert_delta = inner_vert - outer_vert
    adjusted_vert = outer_vert + ((vert_delta/100) * taper)    
    
    #print("adjusted_vert =", adjusted_vert)    
    return adjusted_vert

    
def create_rectangular_beam(size, thick, debug):
    # Creates a rectangular beam mesh object
    # size - tuple of x,y,z dimensions of box
    # thick - thickness, if not zero this is the thickness of a hollow 
    #         box with inner faces inset from size dimensions
    # debug - if true prints values from this function to console
    
    # returns: 
    # verts_final - a list of tuples of the x, y, z, location of each vertice
    # faces_final - a list of tuples of the vertices that make up each face  
    
    # Create temporarylists to hold vertices locations
    verts_front_temp=[]
    verts_back_temp=[]
    
    #calculate y offset from center for front vertices
    y_off = size[1]/2 
      
        
    # Create front vertices by calculation
    verts_front_temp = calc_end_verts(size, y_off, thick, debug)
    
    # re-calculate y offset from center for back vertices
    y_off = 0 - y_off
    
    # Create back vertices by calculation
    verts_back_temp = calc_end_verts(size, y_off, thick, debug)
    
    # Combine all vertices into a final list of tuples
    verts_final = verts_front_temp + verts_back_temp   
           
    # Print debug info to console
    if debug:
        print("\ncreate_multi_side_box Function Start")
        print("\n Front vertices :", verts_front_temp)
        print("\n Back vertices:", verts_back_temp)
        print("\n All vertices:", verts_final)
                      
    # Create front face
    faces_front_temp = []
    verts_front_list = []
    numofverts = len(verts_front_temp)
    
    # Build vertex list
    for index in range(numofverts):
        verts_front_list.append(index)
       
    faces_front_temp = create_end_faces(verts_front_list, thick, debug) 
    
    # Create back face
    faces_back_temp = []
    verts_back_list = []
    numofverts = len(verts_back_temp)
    
    # Build vertex list
    for index in range(numofverts):
        verts_back_list.append(index + len(verts_back_temp))
        
    faces_back_temp = create_end_faces(verts_back_list, thick, debug)

    # Create side faces
    faces_side_temp = []
    
    # better code needed here???
    if thick:
        # Object has thickness, create list of outside vertices
        numofverts = len(verts_front_list)
        verts_front_temp = verts_front_list[0:int(numofverts/2)]
        verts_back_temp = verts_back_list[0:int(numofverts/2)]
        
        faces_side_temp = create_side_faces(verts_front_temp, verts_back_temp, debug)
        
        # Create list of inside vertices
        verts_front_temp = verts_front_list[int(numofverts/2):numofverts]
        verts_back_temp = verts_back_list[int(numofverts/2):numofverts]
        
        faces_side_temp += create_side_faces(verts_front_temp, verts_back_temp, debug)            
    else:
        # Create list of only outside faces
        faces_side_temp = create_side_faces(verts_front_list, verts_back_list, debug)
    
    # Combine all faces 
    faces_final = faces_front_temp + faces_back_temp + faces_side_temp
    
    # print debug info to console   
    if debug:
        print("\ncreate_multi_side_box Function")
        print("\nAll faces :",faces_final)
        print("\ncreate_multi_side_box Function Ends\n\n")
    
    return verts_final, faces_final


def create_U_beam(size, thick, taper, debug):
    # Creates a C or U shaped mesh beam object 
    # size - tuple of x,y,z dimensions of beam
    # thick - thickness, the amount the inner faces will be
    #           inset from size dimensions
    # taper - % to taper outside edges by
    # debug - if true prints values from this function to console
    
    # returns: 
    # verts_final - a list of tuples of the x, y, z, location of each vertice
    # faces_final - a list of tuples of the vertices that make up each face
    
    # print debug info to console
    if debug:
        print ("\ncreate_U_beam - function called")

    # Get y offset of vertices from center
    y_off = size[1] / 2
    print("\n y_off =",y_off)
    
    # Create temporarylists to hold vertices locations
    verts_front_temp=[]
    verts_back_temp=[]
    
    # Create front vertices by calculation
    verts_front_temp = calc_end_verts(size, y_off, thick, debug)
    # Additional adjustment to the verts needed - 5th & 6th verts
    # needed because the calc_end_verts creates a rectangluar beam
    # the insides are inset, for a U channel we need the inside
    # verts on the open end to match the z-loc of the outside verts 
    verts_front_temp = adjust_c_beam_verts(verts_front_temp, taper, 1)
    print("\n front verts =",verts_front_temp)       
    
    # recalculate y_off for other end vertices
    y_off = 0 - y_off
    print("\n y_off =",y_off)
    
    # Create back vertices by calculation
    verts_back_temp = calc_end_verts(size, y_off, thick, debug)
    # Additional adjustment to the verts needed - the z location
    verts_back_temp = adjust_c_beam_verts(verts_back_temp, taper, debug)
    print("\n back verts =",verts_back_temp)  
    
    # Combine all vertices into a final list of tuples
    verts_final = verts_front_temp + verts_back_temp   
  
    # Print debug info to console
    if debug:
        print("\ncreate_U_beam function start")
        print("\n Front vertices :", verts_front_temp)
        print("\n Back vertices:", verts_back_temp)
        print("\n All vertices:", verts_final)
    
    # Create front face
    faces_front_temp = []
    verts_front_list = []
    numofverts = len(verts_front_temp)
    
    # Build vertex list
    for index in range(numofverts):
        verts_front_list.append(index)
    # problem area   
    faces_front_temp = create_end_faces(verts_front_list, thick, debug) 
    # Remove 1st face - only 3 end faces needed
    faces_front_temp = faces_front_temp[1:4]
        
    # Create back face
    faces_back_temp = []
    verts_back_list = []
    numofverts = len(verts_back_temp)
    
    # Build vertex list
    for index in range(numofverts):
        verts_back_list.append(index + len(verts_back_temp))
      
    faces_back_temp = create_end_faces(verts_back_list, thick, debug)
    # Remove 1st face - only 3 end faces needed
    faces_back_temp = faces_back_temp[1:4]

    # Create list of outside vertices for the 3 outside faces
    numofverts = (len(verts_front_list))
    verts_front_temp = verts_front_list[0:int(numofverts/2)]
    verts_back_temp = verts_back_list[0:int(numofverts/2)]
        
    faces_side_temp = create_side_faces(verts_front_temp, verts_back_temp, debug)
    # create_side_faces creates 4 outside faces, we only want 3
    # so remove the 1st face
    faces_side_temp  = faces_side_temp[1:]
    
    # Create list of inside vertices for the 3 inside faces
    verts_front_temp = verts_front_list[int(numofverts/2):numofverts]
    verts_back_temp = verts_back_list[int(numofverts/2):numofverts]
        
    faces_side_temp += create_side_faces(verts_front_temp, verts_back_temp, debug)
    # create_side_faces creates 4 outside faces, we only want 3
    # so remove the 1st face
    faces_side_temp  = faces_side_temp[0:3] + faces_side_temp[4:]
    
    # fill in top two faces
    faces_side_temp.append((0, 4, 12, 8))
    faces_side_temp.append((5, 1, 9, 13))    
    
    # Combine all faces 
    faces_final = faces_front_temp + faces_back_temp + faces_side_temp

    # Print debug info to console
    if debug:
        print("\ncreate_U_beam function") 
        print("\nAll faces =", faces_final)
        print("\ncreate_c_beam function ending")
         
    return verts_final, faces_final


def create_L_beam(size, thick, taper, debug):
    # Creates a L shaped mesh beam object
    # size - tuple of x,y,z dimensions of beam
    # thick - thickness, the amount the inner faces will be
    #           inset from size dimensions
    # taper - % to taper outside edges by
    # debug - if true prints values from this function to console
    
    # returns:
    # verts_final - a list of tuples of the x, y, z, location of each vertice
    # faces_final - a list of tuples of the vertices that make up each face
    
    if debug:
        print("\ncreate_L_beam function starting")

    # Get offset of vertices from center
    x_off = size[0] / 2
    y_off = size[1] / 2
    z_off = size[2] / 2
    
    # Create temporarylists to hold vertices locations
    verts_front_temp=[]
    verts_back_temp=[]
    
    # Create front vertices by calculation
    verts_front_temp = [(0 - x_off, 0 - y_off, z_off), \
        (0 - (x_off - thick), 0 - y_off, z_off), \
        (0 - (x_off - thick), 0 - y_off, 0 - (z_off - thick)), \
        (x_off, 0 - y_off, 0 - (z_off - thick)), \
        (x_off, 0 - y_off, 0 - z_off), \
        (0 - x_off, 0 - y_off, 0 - z_off)]
    
    # Adjust taper
    vert_outside = verts_front_temp[0]
    vert_inside = verts_front_temp[1]
    verts_front_temp[1] = [(calc_taper(vert_outside[0], vert_inside[0], taper)), vert_inside[1],vert_inside[2]]
   
    vert_outside = verts_front_temp[4]
    vert_inside = verts_front_temp[3]
    verts_front_temp[3] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]
    
    # Create back vertices by calculation
    verts_back_temp = [(0 - x_off, y_off, z_off), \
        (0 - (x_off - thick), y_off, z_off), \
        (0 - (x_off - thick), y_off, 0 - (z_off - thick)), \
        (x_off, y_off, 0 - (z_off - thick)), \
        (x_off, y_off, 0 - z_off), \
        (0 - x_off, y_off, 0 - z_off)]

    # Adjust taper
    vert_outside = verts_back_temp[0]
    vert_inside = verts_back_temp[1]
    verts_back_temp[1] = [(calc_taper(vert_outside[0], vert_inside[0], taper)), vert_inside[1],vert_inside[2]]   
    
    vert_outside = verts_back_temp[4]
    vert_inside = verts_back_temp[3]
    verts_back_temp[3] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))] 
    
    verts_final = verts_front_temp + verts_back_temp
    
    if debug:
        print("\n verts_front_temp =", verts_front_temp)
        print("\n verts_back_temp =", verts_back_temp)
        print("\n verts_final =", verts_final)
    
    # define end faces, only 4 so just coded
    faces_front_temp = []
    faces_back_temp = []
    faces_side_temp = []
    
    faces_front_temp = [(0, 1, 2, 5), (2, 3, 4, 5)]
    faces_back_temp = [(6, 7, 8, 11), (8, 9, 10, 11)]
    
    verts_front_list = []
    verts_back_list = []
    num_of_verts = len(verts_front_temp)
    
    # build lists of back and front verts for create_side_faces function
    for index in range(num_of_verts):
        verts_front_list.append(index)
    for index in range(num_of_verts):
        verts_back_list.append(index  + 6)
    
    faces_side_temp = create_side_faces(verts_front_list, verts_back_list, debug)
        
    faces_final = faces_front_temp + faces_back_temp + faces_side_temp
    
    if debug:
        print("\n faces_front_temp =", faces_front_temp)
        print("\n faces_back_temp =", faces_back_temp)
        print("\n faces_side_temp =", faces_side_temp)
        print("\n faces_final =", faces_final)
        print("\ncreate_L_beam function ending")
        
    return verts_final, faces_final



def create_T_beam(size, thick, taper, debug):
    # Creates a T shaped mesh beam object
    # size - tuple of x,y,z dimensions of beam
    # thick - thickness, the amount the inner faces will be
    #           inset from size dimensions
    # taper - % to taper outside edges by
    # debug - if true prints values from this function to console
    
    # returns:
    # verts_final - a list of tuples of the x, y, z, location of each vertice
    # faces_final - a list of tuples of the vertices that make up each face
    debug = 0
    
    if debug:
        print("\ncreate_T_beam function starting")

    # Get offset of vertices from center
    x_off = size[0] / 2
    y_off = size[1] / 2
    z_off = size[2] / 2
    thick_off = thick / 2

    # Create temporarylists to hold vertices locations
    verts_front_temp=[]
    verts_back_temp=[]
    
    # Create front vertices by calculation
    verts_front_temp = [(0 - x_off, 0 - y_off, z_off), \
        (0 - thick_off, 0 - y_off, z_off), \
        (thick_off, 0 - y_off, z_off), \
        (x_off, 0 - y_off, z_off), \
        (x_off, 0 - y_off, z_off - thick), \
        (thick_off, 0 - y_off, z_off - thick), \
        (thick_off, 0 - y_off, 0 - z_off), \
        (0 - thick_off, 0 - y_off, 0 - z_off), \
        (0 - thick_off, 0 - y_off, z_off - thick), \
        (0 - x_off, 0 - y_off, z_off - thick)]

    # Adjust taper
    vert_outside = verts_front_temp[0]
    vert_inside = verts_front_temp[9]
    verts_front_temp[9] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]

    vert_outside = verts_front_temp[3]
    vert_inside = verts_front_temp[4]
    verts_front_temp[4] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]  

    # Adjust taper of bottom of beam, so 0 the center
    # now becomes vert_outside, and vert_inside is calculated
    # 1/2 way towards center
    vert_outside = (0, 0 - y_off, 0 - z_off)
    vert_inside = verts_front_temp[6]
    verts_front_temp[6] = [(calc_taper(vert_outside[0], vert_inside[0], taper)), vert_inside[1], vert_inside[2]]  

    vert_outside = (0, 0 - y_off, 0 - z_off)
    vert_inside = verts_front_temp[7]
    verts_front_temp[7] = [(calc_taper(vert_outside[0], vert_inside[0], taper)), vert_inside[1], vert_inside[2]]

    # Create fack vertices by calculation
    verts_back_temp = [(0 - x_off, y_off, z_off), \
        (0 - thick_off, y_off, z_off), \
        (thick_off, y_off, z_off), \
        (x_off, y_off, z_off), \
        (x_off, y_off, z_off - thick), \
        (thick_off, y_off, z_off - thick), \
        (thick_off, y_off, 0 - z_off), \
        (0 - thick_off, y_off, 0 - z_off), \
        (0 - thick_off, y_off, z_off - thick), \
        (0 - x_off, y_off, z_off - thick)]

    # Adjust taper
    vert_outside = verts_back_temp[0]
    vert_inside = verts_back_temp[9]
    verts_back_temp[9] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]

    vert_outside = verts_back_temp[3]
    vert_inside = verts_back_temp[4]
    verts_back_temp[4] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]
    
    # Adjust taper of bottom of beam, so 0 the center
    # now becomes vert_outside, and vert_inside is calculated
    # 1/2 way towards center
    vert_outside = (0, 0 - y_off, 0 - z_off)
    vert_inside = verts_back_temp[6]
    verts_back_temp[6] = [(calc_taper(vert_outside[0], vert_inside[0], taper)), vert_inside[1], vert_inside[2]]  

    vert_outside = (0, 0 - y_off, 0 - z_off)
    vert_inside = verts_back_temp[7]
    verts_back_temp[7] = [(calc_taper(vert_outside[0], vert_inside[0], taper)), vert_inside[1], vert_inside[2]]
        
    verts_final = verts_front_temp + verts_back_temp
    
    
    # define end faces, only 8 so just coded
    faces_front_temp = []
    faces_back_temp = []
    faces_side_temp = []
    
    faces_front_temp = [(0, 1, 8, 9), (1, 2, 5, 8), \
        (2, 3, 4, 5), (5, 6, 7, 8)]
        
    faces_back_temp = [(10, 11, 18, 19), (11, 12, 15, 18), \
        (12, 13, 14, 15), (15, 16, 17,  18)]

    verts_front_list = []
    verts_back_list = []
    num_of_verts = len(verts_front_temp)
    
    # build lists of back and front verts for create_side_faces function
    for index in range(num_of_verts):
        verts_front_list.append(index)
    for index in range(num_of_verts):
        verts_back_list.append(index  + 10)
    
    faces_side_temp = create_side_faces(verts_front_list, verts_back_list, debug)
    
    faces_final = faces_front_temp + faces_back_temp + faces_side_temp

    if debug:
        print("\ncreate_T_beam function ending")    
        
    return verts_final, faces_final


def create_I_beam(size, thick, taper, debug):
    # Creates a T shaped mesh beam object
    # size - tuple of x,y,z dimensions of beam
    # thick - thickness, the amount the inner faces will be
    #           inset from size dimensions
    # taper - % to taper outside edges by
    # debug - if true prints values from this function to console
    
    # returns:
    # verts_final - a list of tuples of the x, y, z, location of each vertice
    # faces_final - a list of tuples of the vertices that make up each face
    debug = 0
    
    if debug:
        print("\ncreate_I_beam function starting")

    # Get offset of vertices from center
    x_off = size[0] / 2
    y_off = size[1] / 2
    z_off = size[2] / 2
    thick_off = thick / 2

    # Create temporarylists to hold vertices locations
    verts_front_temp=[]
    verts_back_temp=[]
    
    # Create front vertices by calculation
    verts_front_temp = [(0 - x_off, 0 - y_off, z_off), \
        (0 - thick_off, 0 - y_off, z_off), \
        (thick_off, 0 - y_off, z_off), \
        (x_off, 0 - y_off, z_off), \
        (x_off, 0 - y_off, z_off - thick), \
        (thick_off, 0 - y_off, z_off - thick), \
        (thick_off, 0 - y_off, 0 - z_off + thick), \
        (x_off, 0 - y_off, 0 - z_off + thick), \
        (x_off, 0 - y_off, 0 - z_off), \
        (thick_off, 0 - y_off, 0 - z_off), \
        (0 - thick_off, 0 - y_off, 0 - z_off), \
        (0 - x_off, 0 - y_off, 0 - z_off), \
        (0 - x_off, 0 - y_off, 0 -z_off  + thick), \
        (0 - thick_off, 0 - y_off, 0 - z_off + thick), \
        (0 - thick_off, 0 - y_off, z_off - thick), \
        (0 - x_off, 0 - y_off, z_off - thick)]
    
    # Adjust taper
    vert_outside = verts_front_temp[0]
    vert_inside = verts_front_temp[15]
    verts_front_temp[15] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]
    
    vert_outside = verts_front_temp[3]
    vert_inside = verts_front_temp[4]
    verts_front_temp[4] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]
    
    vert_outside = verts_front_temp[8]
    vert_inside = verts_front_temp[7]
    verts_front_temp[7] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]
    
    vert_outside = verts_front_temp[11]
    vert_inside = verts_front_temp[12]
    verts_front_temp[12] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]

    # Create back vertices by calculation
    verts_back_temp = [(0 - x_off, y_off, z_off), \
        (0 - thick_off, y_off, z_off), \
        (thick_off, y_off, z_off), \
        (x_off, y_off, z_off), \
        (x_off, y_off, z_off - thick), \
        (thick_off, y_off, z_off - thick), \
        (thick_off, y_off, 0 - z_off + thick), \
        (x_off, y_off, 0 - z_off + thick), \
        (x_off, y_off, 0 - z_off), \
        (thick_off, y_off, 0 - z_off), \
        (0 - thick_off, y_off, 0 - z_off), \
        (0 - x_off, y_off, 0 - z_off), \
        (0 - x_off, y_off, 0 -z_off  + thick), \
        (0 - thick_off, y_off, 0 - z_off + thick), \
        (0 - thick_off, y_off, z_off - thick), \
        (0 - x_off, y_off, z_off - thick)]

    # Adjust taper
    vert_outside = verts_back_temp[0]
    vert_inside = verts_back_temp[15]
    verts_back_temp[15] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]
    
    vert_outside = verts_back_temp[3]
    vert_inside = verts_back_temp[4]
    verts_back_temp[4] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]
    
    vert_outside = verts_back_temp[8]
    vert_inside = verts_back_temp[7]
    verts_back_temp[7] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]
    
    vert_outside = verts_back_temp[11]
    vert_inside = verts_back_temp[12]
    verts_back_temp[12] = [vert_inside[0], vert_inside[1], (calc_taper(vert_outside[2], vert_inside[2], taper))]       
 
    verts_final = verts_front_temp + verts_back_temp


# define end faces, only 7 per end, so just coded
    faces_front_temp = []
    faces_back_temp = []
    faces_side_temp = []
    
    faces_front_temp = [(0, 1, 14, 15), (1, 2, 5, 14), \
        (2, 3, 4, 5), (6, 7, 8, 9), \
        (6, 9, 10, 13), (12, 13, 10, 11), \
        (5, 6, 13, 14)]
        
    faces_back_temp = [(16, 17, 30, 31), (17, 18, 21, 30), \
        (18, 19, 20, 21), (22, 23, 24, 25), \
        (22, 25, 26, 29), (28, 29, 26, 27), \
        (21, 22, 29, 30)]
        
    verts_front_list = []
    verts_back_list = []
    num_of_verts = len(verts_front_temp)
    
    # build lists of back and front verts for create_side_faces function
    for index in range(num_of_verts):
        verts_front_list.append(index)
    for index in range(num_of_verts):
        verts_back_list.append(index  + 16)
    
    faces_side_temp = create_side_faces(verts_front_list, verts_back_list, debug)
    
    faces_final = faces_front_temp + faces_back_temp + faces_side_temp   
    
    if debug:
        print("\ncreate_I_beam function ending")
    
    return verts_final, faces_final

        

# Define "Add_Rectangular_Beam" operator
########### Needs Work ###############        
class Add_Rectangular_Beam(bpy.types.Operator):
    
    bl_idname = "mesh.primitive_rectangle_add"
    bl_label = "Add Rectangluar Beam"
    bl_description = "Create a Rectangular Beam mesh."
    bl_options = {'REGISTER', 'UNDO'}
        
    mesh_z_size = bpy.props.FloatProperty(name = "Height(z)",
        description = "Height (along the z-axis) of mesh",
        min = 0.01,
        max = 100,
        default = 1)
        
    mesh_x_size = bpy.props.FloatProperty(name = "Width(x)",
        description = "Width (along the x-axis) of mesh",
        min = 0.01,
        max = 100,
        default = .5)
        
    mesh_y_size = bpy.props.FloatProperty(name = "Length(y)",
        description = "Length (along y-axis) of mesh",
        min = 0.01,
        max = 100,
        default = 2)
            
    thick_bool = bpy.props.BoolProperty(name = "Hollow",
        description = "Create a hollow mesh with a defined thickness",
        default = True)

    thick = bpy.props.FloatProperty(name = "Thickness",
        description = "Thickness of hollow mesh",
        min = 0.01,
        max = 1,
        default = 0.1)
        
    align_matrix = mathutils.Matrix()

    # Define tool parameter layout
    def draw(self, context):
        layout = self.layout
        layout.prop(self, 'mesh_z_size')
        layout.prop(self, 'mesh_x_size')
        layout.prop(self, 'mesh_y_size')
        layout.prop(self, 'thick_bool')
        layout.prop(self, 'thick')
                
    def execute(self, context):
        # debug flag - True prints debug info to console
        debug = 0
        
        size = (self.mesh_x_size, self.mesh_y_size, self.mesh_z_size)
        if self.thick_bool is True:
            thick = self.thick
        else:
            thick = 0
                        
        verts, faces = create_rectangular_beam(size, thick, debug)
            
        if debug:
            print("\nCreated Verts:", verts)
            print("\nCreated Faces:", faces)
                
        create_mesh("Rectangular Beam", verts, faces, self.align_matrix)
        
        return {'FINISHED'}

    def invoke(self, context, event):
        self.align_matrix = align_matrix(context)
        self.execute(context)
        return {'FINISHED'}    


# Define "Add_C_Beam" operator        
class Add_C_Beam(bpy.types.Operator):
    
    bl_idname = "mesh.primitive_c_beam_add"
    bl_label = "Add C or U Channel"
    bl_description = "Create a C or U channel mesh."
    bl_options = {'REGISTER', 'UNDO'}
    
        
    mesh_z_size = bpy.props.FloatProperty(name = "Height(z)",
        description = "Height (along the z-axis) of mesh",
        min = 0.01,
        max = 100,
        default = 1)
        
    mesh_x_size = bpy.props.FloatProperty(name = "Width(x)",
        description = "Width (along the x-axis) of mesh",
        min = 0.01,
        max = 100,
        default = .5)
        
    mesh_y_size = bpy.props.FloatProperty(name = "Length(y)",
        description = "Length (along y-axis) of mesh",
        min = 0.01,
        max = 100,
        default = 2)

    thick = bpy.props.FloatProperty(name = "Thickness",
        description = "Thickness of mesh",
        min = 0.01,
        max = 1,
        default = 0.1)

    taper = bpy.props.IntProperty(name = "Taper",
        description = "Percentage to taper outside edges, 0 = no taper, 100 = full taper",
        min = 0,
        max = 100,
        default = 0)        

    type = bpy.props.BoolProperty(name = "U-shaped",
        description = "Create the beam in a U orientation rather than the defualt C orientation", 
        default = False)
                
    align_matrix = mathutils.Matrix()

    # Define tool parameter layout
    def draw(self, context):
        layout = self.layout
        layout.prop(self, 'mesh_z_size')
        layout.prop(self, 'mesh_x_size')
        layout.prop(self, 'mesh_y_size')
        layout.prop(self, 'thick')
        layout.prop(self, 'taper')
        layout.prop(self, 'type')
                
    def execute(self, context):
        # debug flag - True prints debug info to console
        debug = 0
        
        # if type == true beam is U chanel, otherwise it's a C
        if self.type:
            size = (self.mesh_x_size, self.mesh_y_size, self.mesh_z_size)
        else:
            size = (self.mesh_z_size, self.mesh_y_size, self.mesh_x_size)
            
        verts, faces = create_U_beam(size, self.thick, self.taper, debug)      
            
        if debug:
            print("\nCreated Verts:", verts)
            print("\nCreated Faces:", faces)
                
        create_mesh("C Beam", verts, faces, self.align_matrix)
        
        if not self.type:
        # C-type beam is actually created as a u-type beam
        # so rotate 90 degrees on y-axis to make a c-type
        # and apply rotation & location to reset those values
        # and reset object origin to 3d cursor if self.type is false.
        # if self.type is true, do nothing as beam is alreay u-type.
        # rotation value is in radians
            bpy.ops.transform.rotate(value=[1.570796], constraint_axis=[False, True, False])
            bpy.ops.object.rotation_clear()
            bpy.ops.object.location_clear()
            bpy.ops.object.origin_set(type="ORIGIN_CURSOR")
        # The above code might not work right if rotation set to view 
        # Need to test further!
        
        return {'FINISHED'}

    def invoke(self, context, event):
        self.align_matrix = align_matrix(context)
        self.execute(context)
        return {'FINISHED'}
    

# Define "Add_L_Beam" operator    
class Add_L_Beam(bpy.types.Operator):
    
    bl_idname = "mesh.primitive_l_beam_add"
    bl_label = "Add L Beam"
    bl_description = "Create a L shaped mesh."
    bl_options = {'REGISTER', 'UNDO'}

    mesh_z_size = bpy.props.FloatProperty(name = "Height(z)",
        description = "Height (along the z-axis) of mesh",
        min = 0.01,
        max = 100,
        default = 1)
        
    mesh_x_size = bpy.props.FloatProperty(name = "Width(x)",
        description = "Width (along the x-axis) of mesh",
        min = 0.01,
        max = 100,
        default = .5)
        
    mesh_y_size = bpy.props.FloatProperty(name = "Length(y)",
        description = "Length (along y-axis) of mesh",
        min = 0.01,
        max = 100,
        default = 2)

    thick = bpy.props.FloatProperty(name = "Thickness",
        description = "Thickness of mesh",
        min = 0.01,
        max = 1,
        default = 0.1)

    taper = bpy.props.IntProperty(name = "Taper",
        description = "Percentage to taper outside edges, 0 = no taper, 100 = full taper",
        min = 0,
        max = 100,
        default = 0)

    align_matrix = mathutils.Matrix()

    # Define tool parameter layout
    def draw(self, context):
        layout = self.layout
        layout.prop(self, 'mesh_z_size')
        layout.prop(self, 'mesh_x_size')
        layout.prop(self, 'mesh_y_size')
        layout.prop(self, 'thick')
        layout.prop(self, 'taper')

    def execute(self, context):
        # debug flag - True prints debug info to console
        debug = 0 
        
        size = (self.mesh_x_size, self.mesh_y_size, self.mesh_z_size)
                           
        verts, faces = create_L_beam(size, self.thick, self.taper, debug)
        
        if debug:
            print("\nCreated Verts:", verts)
            print("\nCreated Faces:", faces)
                
        create_mesh("L Beam", verts, faces, self.align_matrix) 
        
        return {'FINISHED'}

    def invoke(self, context, event):
        self.align_matrix = align_matrix(context)
        self.execute(context)
        return {'FINISHED'}
    
    
# Define "Add_T_Beam" operator    
class Add_T_Beam(bpy.types.Operator):
    
    bl_idname = "mesh.primitive_t_beam_add"
    bl_label = "Add T Beam"
    bl_description = "Create a T shaped mesh."
    bl_options = {'REGISTER', 'UNDO'}    

    mesh_z_size = bpy.props.FloatProperty(name = "Height(z)",
        description = "Height (along the z-axis) of mesh",
        min = 0.01,
        max = 100,
        default = 1)
        
    mesh_x_size = bpy.props.FloatProperty(name = "Width(x)",
        description = "Width (along the x-axis) of mesh",
        min = 0.01,
        max = 100,
        default = .5)
        
    mesh_y_size = bpy.props.FloatProperty(name = "Length(y)",
        description = "Length (along y-axis) of mesh",
        min = 0.01,
        max = 100,
        default = 2)

    thick = bpy.props.FloatProperty(name = "Thickness",
        description = "Thickness of mesh",
        min = 0.01,
        max = 1,
        default = 0.1)

    taper = bpy.props.IntProperty(name = "Taper",
        description = "Percentage to taper outside edges, 0 = no taper, 100 = full taper",
        min = 0,
        max = 100,
        default = 0)

    align_matrix = mathutils.Matrix()

    # Define tool parameter layout
    def draw(self, context):
        layout = self.layout
        layout.prop(self, 'mesh_z_size')
        layout.prop(self, 'mesh_x_size')
        layout.prop(self, 'mesh_y_size')
        layout.prop(self, 'thick')
        layout.prop(self, 'taper')

    def execute(self, context):
        # debug flag - True prints debug info to console
        debug = 0
        
        size = (self.mesh_x_size, self.mesh_y_size, self.mesh_z_size)
                           
        verts, faces = create_T_beam(size, self.thick, self.taper, debug)
        
        if debug:
            print("\nCreated Verts:", verts)
            print("\nCreated Faces:", faces)
                
        create_mesh("T Beam", verts, faces, self.align_matrix) 
        
        return {'FINISHED'}

    def invoke(self, context, event):
        self.align_matrix = align_matrix(context)
        self.execute(context)
        return {'FINISHED'}
    
    
# Define "Add_I_Beam" operator    
class Add_I_Beam(bpy.types.Operator):
    
    bl_idname = "mesh.primitive_i_beam_add"
    bl_label = "Add I Beam"
    bl_description = "Create a I shaped mesh."
    bl_options = {'REGISTER', 'UNDO'}    

    mesh_z_size = bpy.props.FloatProperty(name = "Height(z)",
        description = "Height (along the z-axis) of mesh",
        min = 0.01,
        max = 100,
        default = 1)
        
    mesh_x_size = bpy.props.FloatProperty(name = "Width(x)",
        description = "Width (along the x-axis) of mesh",
        min = 0.01,
        max = 100,
        default = .5)
        
    mesh_y_size = bpy.props.FloatProperty(name = "Length(y)",
        description = "Length (along y-axis) of mesh",
        min = 0.01,
        max = 100,
        default = 2)

    thick = bpy.props.FloatProperty(name = "Thickness",
        description = "Thickness of mesh",
        min = 0.01,
        max = 1,
        default = 0.1)

    taper = bpy.props.IntProperty(name = "Taper",
        description = "Percentage to taper outside edges, 0 = no taper, 100 = full taper",
        min = 0,
        max = 100,
        default = 0)

    align_matrix = mathutils.Matrix()
    
    # Define tool parameter layout
    def draw(self, context):
        layout = self.layout
        layout.prop(self, 'mesh_z_size')
        layout.prop(self, 'mesh_x_size')
        layout.prop(self, 'mesh_y_size')
        layout.prop(self, 'thick')
        layout.prop(self, 'taper')

    def execute(self, context):
        # debug flag - True prints debug info to console
        debug = 0
        
        size = (self.mesh_x_size, self.mesh_y_size, self.mesh_z_size)
                           
        verts, faces = create_I_beam(size, self.thick, self.taper, debug)
        
        if debug:
            print("\nCreated Verts:", verts)
            print("\nCreated Faces:", faces)
                
        create_mesh("I Beam", verts, faces, self.align_matrix) 
        
        return {'FINISHED'}

    def invoke(self, context, event):
        self.align_matrix = align_matrix(context)
        self.execute(context)
        return {'FINISHED'}    


# Register all operators and define menus

class INFO_MT_mesh_beambuilder_add(bpy.types.Menu):
    # Define the "Beam Builder" menu
    bl_idname = "INFO_MT_mesh_beambuilder_add"
    bl_label = "Beam Builder"
    
    def draw(self, context):
        layout = self.layout  
        layout.operator_context = 'INVOKE_REGION_WIN'
        layout.operator("mesh.primitive_rectangle_add", text = "Rectangluar Beam")  
        layout.operator("mesh.primitive_c_beam_add", text = "C or U Channel")
        layout.operator("mesh.primitive_l_beam_add", text = "L Shaped Beam")
        layout.operator("mesh.primitive_t_beam_add", text = "T Shaped Beam")
        layout.operator("mesh.primitive_i_beam_add", text = "I Shaped Beam")
        
        
    
# Define menu    
def menu_func(self, context):
    self.layout.menu("INFO_MT_mesh_beambuilder_add", icon='PLUGIN')


# Add     
def register():
    bpy.utils.register_module(__name__)
    
    # Add BeamBuilder menu to the 'Add Mesh' menu
    bpy.types.INFO_MT_mesh_add.append(menu_func)

 
# Remove 
def unregister():
    bpy.utils.unregister_module(__name__)
    
    # Remove BeamBuilder menu from 'Add Mesh' menu
    bpy.types.INFO_MT_mesh_add.remove(menu_func)

 
if __name__ == "__main__":
    register()