I am using ArcGIS 10.8 and PyCharm. I need something very simple apparently, but I can't do it. I want to add an existing shapefile to my ArcMap project using Python from PyCharm. With my project open in ArcMap, I go to PyCharm and I have tried:

import arcpy

fc = "D:/Shapefiles/regiones.shp"

mxd = arcpy.mapping.MapDocument("D:/proyectos/aftines.mxd")

arcpy.MakeFeatureLayer_management(fc, "regiones")



and I get nothing...

I have looked for the solution on the internet and I have not found it.

  • 3
    What are you expecting to happen? The two applications have no linkage, and your IDE has no map canvas. – Vince Oct 10 '20 at 11:40
  • 1
    As @Vince indicates something running in PyCharm wont necessarily communicate with ArcMap. If you copied and paste your code into the python window in ArcMap it should work as long as you change the MapDocument string to "CURRENT". – Hornbydd Oct 10 '20 at 21:02
  • 2
    You can't do this. If you want to load data into an open ArcMap project, you have to run your code from the ArcMap python window and use mxd = arcpy.mapping.MapDocument("CURRENT"). – user2856 Oct 10 '20 at 21:57
  • Thank you all for the information. Now I see it clear. I have achieved to do it by running the code inside the Python window in ArcMap. – Jota Q Oct 11 '20 at 6:29

Check out this thread, Load shapefile in ArcMap using python script

You might want to try using a df.

Check if the script works within ArcMap.

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.