Select to view content in your preferred language

How to add geodatabase to aprx with arcpy?

277
3
Jump to solution
08-12-2024 05:27 AM
JörgEbert
Occasional Contributor

Hello everybody,


I have a script tool and I want to add the output file geodatabase from my script to aprx databases. But arcpy.mp.ArcGISProject.databases is a read-only property.

Is there a way with arcpy or via CIM or calling ArcGIS Pro SDK in arcpy?

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
JörgEbert
Occasional Contributor

Sorry,

I missed the method arcpy.mp.ArcGISProject.updateDatabases(databases, {validate})

View solution in original post

3 Replies
JörgEbert
Occasional Contributor

Sorry,

I missed the method arcpy.mp.ArcGISProject.updateDatabases(databases, {validate})

Alex_gis
Emerging Contributor

Hi,

I'm struggling at the same step. I "just" want to add my gdb to my current project.

I do not find the documentation on it. I tried your example but I'm missing one parameters

 

gdb = r"*\MyGDB.gdb"
arcpy.env.workspace = gdb

arcpy.mp.ArcGISProject.updateDatabases(gdb)
aprx.save()
del aprx

 


But I get:

 
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
      6 arcpy.env.workspace = gdb
      7 
----> 8 arcpy.mp.ArcGISProject.updateDatabases(gdb)
      9 aprx.save()
     10 del aprx

TypeError: updateDatabases() missing 1 required positional argument: 'databases'


Can you give a code example with parameters ?

Thanks,

Alex

0 Kudos
JörgEbert
Occasional Contributor

Sorry,
the database parameter of the updateDatabases method requires a list of Python dictionaries, but not a string/path of a geodatabase. This is well documented here.

aprx = arcpy.mp.ArcGISProject('Current')
gdbs = aprx.databases
# change the list of Python dictionaries
# gdbs.append({'databasePath': '<A local or UNC path to a database>', 'isDefaultDatabase': False})
aprx.updateDatabases(gdbs)
aprx.save()

0 Kudos