Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6851601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:16:05+00:00 2026-05-27T01:16:05+00:00

I am trying to automate various tasks in ArcGIS Desktop (using ArcMap generally) with

  • 0

I am trying to automate various tasks in ArcGIS Desktop (using ArcMap generally) with Python, and I keep needing a way to add a shape file to the current map. (And then do stuff to it, but that’s another story).

The best I can do so far is to add a layer file to the current map, using the following (“addLayer” is a layer file object):

def AddLayerFromLayerFile(addLayer):
 import arcpy
 mxd = arcpy.mapping.MapDocument("CURRENT")
 df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
 arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE")
 arcpy.RefreshActiveView()
 arcpy.RefreshTOC()
 del mxd, df, addLayer

However, my raw data is always going be shape files, so I need to be able to open them. (Equivantly: convert a shape file to a layer file wiothout opening it, but I’d prefer not to do that).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:16:06+00:00Added an answer on May 27, 2026 at 1:16 am

    Variable “theShape” is the path of the shape file to be added.

    import arcpy
    import arcpy.mapping
    # get the map document 
    mxd = arcpy.mapping.MapDocument("CURRENT")  
    
    # get the data frame 
    df = arcpy.mapping.ListDataFrames(mxd,"*")[0]  
    
    # create a new layer 
    newlayer = arcpy.mapping.Layer(theShape)  
    
    # add the layer to the map at the bottom of the TOC in data frame 0 
    arcpy.mapping.AddLayer(df, newlayer,"BOTTOM")
    
    # Refresh things
    arcpy.RefreshActiveView()
    arcpy.RefreshTOC()
    del mxd, df, newlayer
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying automate a login process to my web application using Selenium-Python Client
I'm trying to automate svnadmin dump using C# ProcessStartInfo. The way I've done it
I'm trying to automate a gdb session using the --command flag. I'm trying to
I am trying to automate functional testing of a server using a realistic frequency
I am trying to automate VC++ build via an addIn written using VB.NEt so
I'm trying to automate the build of a project in Delphi 2009. I'm using
I'm trying to automate menu picks using Microsoft UI Automation. The application that I'm
I'm trying to automate mounting and unmounting of UNC drives with Python on Windows.
I'm trying to automate the download of some data from a webform. I'm using
I'm trying to automate in a WinForm using a WebBrowser control to navigate and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.