0

I have some problems adding multiple feature classes (not only a single one) from a geodatabase to a map file in an ArcGIS Pro project and I'm wondering if someone knows of a solution to this. To be able to add more than just one layer from the gdb I've tried to use ListFeatureClasses in order to select all feature classes before using AddDatafromPath. But this doesn't seem to do the trick either.

Here's the script. I've tried several other solutions as well, and while some of them did not return any errors they still did not add the data to the map file.

arcpy.env.workspace = "path to gdb"
datasets = arcpy.ListDatasets(feature_type='feature')
datasets = [''] + datasets if datasets is not None else []
rootPath_aprx = "path to aprx"
aprx = arcpy.mp.ArcGISProject(rootPath_aprx+ 'Test.aprx')
aprxMap = aprx.listMaps("Map")[0]
for ds in datasets:
 for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
 path = os.path.join(arcpy.env.workspace, ds, fc)
 print(path)
 try:
 aprxMap.addDataFromPath(test)
 print("yeah.")
 except:
 print("gah.")
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jun 19, 2019 at 14:11
3
  • 2
    This looks like you're trying to add layers into a Project (aprx) on disk. I don't see a save. You'll need to save the APRX. And then you're confirming it didn't work by opening the APRX? Or are you trying to add layers into the current project from the Python window in an open session? If that's the case you'll need to use CURRENT for your arcpy.mp.ArcGISProject instead of the path to the APRX file. Commented Jun 19, 2019 at 14:35
  • You try to add data using aprxMap.addDataFromPath(test) but test is never defined. Should you be using aprxMap.addDataFromPath(path) instead? Ie, path instead of test? Commented Jun 20, 2019 at 2:25
  • You should remove the try: and except:! They will be hiding the real error. Run it without the try/except, and then update your post here with the text of the real error. (With the code above, I would expect it to output an error about test being undefined.) Commented Jun 20, 2019 at 2:26

1 Answer 1

-1

The solution was to close down the project, add a save function, and then reopen the project to see that the files had been added. Simple as that.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
answered Jun 20, 2019 at 7:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.