Select to view content in your preferred language

How to add geodatabase to aprx with arcpy?

180
3
Jump to solution
4 weeks ago
Labels (2)
JörgEbert
New Contributor III

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
New Contributor III

Sorry,

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

View solution in original post

3 Replies
JörgEbert
New Contributor III

Sorry,

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

Alex_gis
New Contributor II

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
New Contributor III

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