Select to view content in your preferred language

Add Layer to Open ArcGIS Pro Project

297
3
03-25-2024 12:55 PM
kapalczynski
Occasional Contributor III

I am trying to simply bring in a Feature Class from a File Geodatabase into an OPEN arcPro project

Any thoughts?

Error: AttributeError: 'NoneType' object has no attribute 'addLayer'

 

import arcpy
import fileinput
import string
import os
from arcpy import env

# FILE GDB where the feature class to bring in resides
arcpy.env.workspace = r"C:\\Users\\ImportFeatureClass_Pro\\ProToolTest.gdb"

# ArcPRO Project Location of the OPEN ArcPro Project
aprx = arcpy.mp.ArcGISProject(r"C:\\Users\\ImportFeatureClass_Pro\\ImportFeatureClass_Pro.aprx")

aprxMap = aprx.activeMap

# The Feature Class from File GDB that I want brought into the OPEN ArcPro Project
file_location = r"C:\\Users\\ImportFeatureClass_Pro\\ProToolTest.gdb\MasonCliiped"

aprxMap.addLayer(file_location, "TOP")

 

 

 

0 Kudos
3 Replies
RocioRey
New Contributor II

I think is not possible lyrx normally in to  Gdb?

0 Kudos
DanPatterson
MVP Esteemed Contributor

Which of the three options are you using to run your code?

activemap

This property is designed to be run from within the application using a script tool, the Python window, or a Notebook. If a script is run outside of the application, a value of None will always be returned.

ArcGISProject—ArcGIS Pro | Documentation


... sort of retired...
0 Kudos
AlfredBaldenweck
MVP Regular Contributor

addLayer() isn't great since it calls for a layer file or a pre-existing.

Try addDataFromPath() instead to make a new layer from scratch.

0 Kudos