System spec: ArcInfo 10.1

I have performed a search on an indexed file geodatabase, looking for feature classes with the word "building" in their name.

I either need to add all of these to a blank map, or copy/export them all to a new location. I was hoping that after performing the search I would be able to select all of the returned results and add them to the map, but it appears that I have to add them one at a time. There's thousands of feature classes returned, so adding them one by one isn't really an option.

Am I missing something really simple? Or is there a better way to do this?

  • How are you performing the search? – artwork21 Dec 17 '13 at 13:58
  • Using the search tab function in ArcMap desktop – Dan_h_b Dec 17 '13 at 14:00
  • By the "search tab function" do you mean the Search window? – PolyGeo Dec 17 '13 at 22:36

I would suggest to use arcpy/python for this task. The workflow would go something like this:

  1. Iterate through geodatabase and do a wildcard search for all features with name "building"
  2. Loop through the returned list from step one and add each found case to a map (Add Layer).
  3. Then, save the map e.g. mxd.saveACopy(r"C:\Project\Project2.mxd")

Working from @artwork21's suggestion I made this, however I'm having issues adding the FC to the TOC >1 *edited to account for duplicates For some reason cannot name the layer the same as the fc...perhaps someone can help with this?

import arcpy
from arcpy import env
import sys
import traceback

#Set path to geodatabase
#Path to your mxd
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
#wildcard the query only list feature classes that contain it
fclist = arcpy.ListFeatureClasses("*building*")
#print all feature classes containing building
print fclist
counter = 0

    for fc in fclist:
    #if this fc already exists then rename       
        if arcpy.Exists(fc) in df:
            print fc +  "Exists in dataframe"
            counter =+1
            string = str(fc) + "_" + str(counter)
            arcpy.MakeFeatureLayer_management(fc, string)
            layer = arcpy.mapping.Layer(string)
            counter =+1
            string = str(fc) + "_" + str(counter)
            print string + "does not exist"
            arcpy.MakeFeatureLayer_management(fc, string)
            layer = arcpy.mapping.Layer(string)
            layers = arcpy.mapping.ListLayers (mxd)

    print ("Error occurred")
    tb = sys.exc_info()[2]
    tbinfo = traceback.format_tb(tb)[0]
    pymsg = "PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n    " + \
        str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n"
    msgs = "GP ERRORS:\n" + arcpy.GetMessages(2 )+ "\n"
    print (pymsg)
    print (msgs)
  • +1 for attempting to Answer but w.r.t. "For some reason cannot name the layer the same as the fc...perhaps someone can help with this?", I recommend that you research/ask this as a separate question rather than asking a "question within an Answer". – PolyGeo Dec 17 '13 at 22:35
  • @PolyGeo Thanks, that's a good point. I was hoping it would be enough for OP and if not someone could adjust. I looked around and couldn't find much on the subject, for now adding a number to the end of the name works. I will edit if I can find more information today. – GISKid Dec 18 '13 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.