Split large database of buildings into seperate buildings, arcgis python

Discussion created by moon47usaco on Jul 23, 2013
I have a large database in MDB format that is exceedingly difficult to work with if all the buildings are in one MDB... I have manually split up a project by building numbers by manually creating seperate empty template folders and using the rt-click on each feature class "Load >>> Load Data" selection... It took about two days...

I would like to automate the process with python and i am almost at a solution but one of my feature classes ('/GeoRef_Buildings.mdb/room_feature_class') has a field that is coming in as all null values...

I am sure this is due to exporting the MDB feature calss to a shp file and having to use the NO-TEST as the schemas do not match...

Is there another way that i can pre select the records that match the [building_num] field to send to the "Append_management" tool without exporting to a shp file...

In other words i want to replace the "Select_analysis" tool with something that retains the schema and data better...

    import arcpy; import os
    from arcpy import env

    #Set working variables
    env.workspace = "C:\Users\MooneyR\Desktop\Building-Break-Test\Data"
    schemaType = "NO-TEST"

    fieldMapping =""
    subtype = ""

    def printline(message):
        print message

    def printerror(message):
        print message

    #Set Feature classes
    FC = ['/GeoRef_Buildings.mdb/floor_feature_class', #floor wide polygons
          '/GeoRef_Buildings.mdb/room_feature_class', #room specific poygons
          '/GeoRef_Buildings.mdb/cad_polyline_feature_class' #cad linework
          '/GeoRef_Buildings.mdb/records_feature_class'] #room specific records table

    #Set Input/Output Variables
    CopyIn = "/Empty - Template" #Empty schema only folder
    SelectIn = "/Full Buildings" #Full buildings directoty containing mxd and mdb
    BldgNums = ["1234", "5678"] #List of building numbers in project scope
    Temp_Feature = "/temp-files/temp.shp" #Temp shp file for select tool
    Temp_Table = "/temp-files/temp" #Temp table for select table tool

    #Copy Loop for Buildings
    for C_BldgPos in BldgNums:

                #Error Handeler

                    #Output location(s) for building specific folders
                    C_OutLoc = "/Building " + C_BldgPos

                    #Process: Copy
                    printline("Copied " + CopyIn + " and created " + C_OutLoc)

                except arcpy.ExecuteError:
                    printerror('\n' + "Copy failed " + C_OutLoc + '\n')

                    printerror("Non-tool error occurred in Copy Loop")

    #Select/Append Loop for Buildings
    for A_BldgPos in BldgNums:

            #Select/Append/Delete Loop for Feature Classes
        for fcPos in FC:

                #Error Handeler

                    S_InString = InLoc + fcPos
                    A_OutString = "/Building " + A_BldgPos + fcPos

                    #Process: Select by building number
                    if fcPos != '/GeoRef_Buildings.mdb/records_feature_class':
                        Temp_File = Temp_Feature
                        arcpy.Select_analysis(S_InString, Temp_File, "[building_num] = '" + A_BldgPos + "'")
                        Temp_File = Temp_Table
                        arcpy.TableSelect_analysis(S_InString, Temp_File,"Left([room_num_id], 4 ) = '" + A_BldgPos + "'")
                        #Need to create condition to check for and get 3 or 4 digit bldg numbers from the BldgNums list... ???
                    printline("Selected " + S_InString + " Into: " + Temp_File)

                    #Process: Append into building folder(s)
                    arcpy.Append_management(Temp_File, A_OutString, schemaType, fieldMapping, subtype)
                    printline("Appended " + A_OutString)

                    #Process: Delete temp select
                    arcpy.Delete_management(Temp_File, "")
                    printline("Deleted " + Temp_File)

                except arcpy.ExecuteError:
                    printerror('\n' + arcpy.GetMessages(2))
                    printerror("Select-Append-Delete failed " + '\n' + S_InString + '\n' + A_OutString + '\n')

                    printerror("Non-tool error occurred in Select-Append Loop")