+ Reply to Thread
Results 1 to 6 of 6

Thread: adding processed shapefiles to ArcMap automatically

  1. #1
    denise davis
    Join Date
    Apr 2010
    Posts
    117
    Points
    1
    Answers Provided
    1


    0

    Default adding processed shapefiles to ArcMap automatically

    When I run an arcpy script in ArcGIS10 to perform analysis on a shapefile, the shapefile is added to the map automatically. I can't find a way to make this happen in 9.3. I've looked for code corresponding to the "add data" button and can't seem to find anything. I've tried the addLayer but it doesn't seem to work right with a shapefile (although, I could be doing something wrong).

    # Import system modules
    import sys, string, os, arcgisscripting

    # Create the Geoprocessor object
    gp = arcgisscripting.create()

    # Load required toolboxes...
    gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
    gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx")


    # Local variables...
    shapefile_name = "shapefile_name"
    selected_shp = gp.GetParameterAsText(0)
    Output_Feature_Class = gp.GetParameterAsText(1)

    # Process: Select...
    gp.Select_analysis(shapefile_name, selected_shp, "")

    # Process: Dissolve...
    gp.Dissolve_management(selected_shp, Output_Feature_Class, "", "", "MULTI_PART", "DISSOLVE_LINES")

    # Process: Add the shapefile to the map
    gp.AddFeatureLayer(selected_shp,Output_Feature_Class)

    Thanks for any help!

  2. #2
    Mike Hunter
    Join Date
    Apr 2010
    Posts
    68
    Points
    70
    Answers Provided
    11


    0

    Default Re: adding processed shapefiles to ArcMap automatically

    You can try gp.AddOUtputsToMap=True. That works with a arcgisscripting gp object, but not with arcpy. But with arcpy, you can simply write the code to add layers with arcpy.mapping.

    Also, there is a switch in the geoprocessing options to automatically add gp results to the display.

    Mike

  3. #3
    denise davis
    Join Date
    Apr 2010
    Posts
    117
    Points
    1
    Answers Provided
    1


    0

    Default Re: adding processed shapefiles to ArcMap automatically

    Thanks for the input. I'm not able to try it right now, however as soon as I'm able to give it a shot, I will.

  4. #4
    karin weixler
    Join Date
    Dec 2010
    Posts
    25
    Points
    0
    Answers Provided
    0


    0

    Default Re: adding processed shapefiles to ArcMap automatically

    Hello,

    have you tried the AddLayer function of arcpy.mapping? If so, does it work in your code? Because i tried to and i am getting errors.
    With the Python Scirpt i create a FeatureClass in a FileGeodatabase and would like to add the created FeatureClass into my map.

    Karin

  5. #5
    Chris Mathers
    Join Date
    Apr 2010
    Posts
    370
    Points
    14
    Answers Provided
    2


    0

    Default Re: adding processed shapefiles to ArcMap automatically

    You have to create an layer object before you can add it to the map with addLayer. yourLayer=arcpy.Layer('path')

  6. #6
    karin weixler
    Join Date
    Dec 2010
    Posts
    25
    Points
    0
    Answers Provided
    0


    0

    Thumbs up Re: adding processed shapefiles to ArcMap automatically

    Thanks for the hint! That solved the problem.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts