Skip to main content

CreateArcGISProject

Summary

The CreateArcGISProject function creates a new project (.aprx) at a specific file location.

Discussion

Once the ArcGISProject is generated, there are a number of operations that could be performed. For example, you might want to add folder connections, database connections, toolboxes, or styles. Another example might be automating the creation of project items such as layouts or maps.

Note:

The CreateArcGISProject function parameters are validated before the project is created. If any of the paths or connections are invalid, the function will error and the project will not be created.

Syntax

CreateArcGISProject(project_path, project_name, {create_parent_folder}, {home_folder}, {default_database}, {default_toolbox})

Parameter Explanation Data Type

project_path

The path to the folder location where the project will be created.

String

project_name

The name of the project. The (.aprx) extension will be added automatically.

String

create_parent_folder

When set to True, the project will be created in a parent folder with the same name as the project_name property value. When set to 'False', all project related files will be generated in the project_path location.

The default value is True.

Boolean

home_folder

The home_folder can be set to an existing folder location. The home folder is the location where project related items get saved such as the project index, backup copies and geoprocessing messages.

If not specified, the default behavior is to set the home_folder to the location the project is created. This value can be changed later using the homeFolder property or the updateFolderConnections method on the ArcGISProject class.

String

default_database

The full path to a file geodatabase (.gdb), mobile geodatabase (.geodatabase), or an enterprise geodatabase (.sde).

If not specified, the default behavior is to create a file geodatabase with the same name as the project_name and in the same location the project is created. This value can be changed later using defaultDatabase property or the updateDatabases method on the ArcGISProject class.

String

default_toolbox

The full path to an ArcGIS toolbox (.atbx), a Python toolbox (.pyt), or a legacy toolbox (.tbx).

If not specified, the default behavior is to create an ArcGIS toolbox with the same name as the project_name and in the same location the project is created. This value can be changed later using the defaultToolbox property or the updateToolboxes method on the ArcGISProject class.

String

Return value

Data Type Explanation

ArcGISProject

An ArcGISProject object. The ArcGISProject object provides access to project properties and methods.

Code sample

CreateArcGISProject example 1

The following script creates a new project and sets the default_database and default_toolbox parameters using non-default locations. The script then prints the newly created project's home folder, default geodatabase and default toolbox values.

import arcpy
aprx = arcpy.mp.CreateArcGISProject(project_path=r"C:\Projects",
                                    project_name="OlympicMountainsNP",
                                    default_database=r"C:\Projects\Base_Data\Parksdata.gdb",
                                    default_toolbox=r"C:\Projects\ParksToolbox.atbx")
print(f'Home folder: {aprx.homeFolder}')
print(f'Default geodatabase: {aprx.defaultGeodatabase}')
print(f'Default toolbox: {aprx.defaultToolbox}')
CreateArcGISProject example 2

The following script creates a new project and adds a folder connection and a custom style file.

import arcpy
aprx = arcpy.mp.CreateArcGISProject(r"C:\Projects", "MtRainierNP")

#Add a folder connection
fcList = aprx.folderConnections
newFC = {'connectionString':r'C:\Projects\Base_Data', 'alias':'Project Base Data', 'isHomeFolder':False}
fcList.append(newFC)
aprx.updateFolderConnections(fcList)

#Add a style file
styleList = aprx.styles
styleList.append(r"C:\Projects\ParksStyleFile.stylx")
aprx.updateStyles(styleList)

aprx.save()
CreateArcGISProject example 3

The following script converts a personal geodatabase to a file geodatabase. Next it creates a new project and imports a map document that references the personal geodatabase. Finally, the data sources in the project are updated from the personal geodatabase to the file geodatabase.

import arcpy

mxd = r"C:\Projects\MtStHelens\MtStHelens.mxd"
pGDB = r"C:\Projects\MtStHelens\MtStHelens.mdb"
fGDB = r"C:\Projects\MtStHelens\MtStHelens.gdb"
projFld = r"C:\Projects\MtStHelens"
projName = "MtStHelens"

#Convert the pGDB to a fGDB
arcpy.conversion.ConvertPersonalGeodatabase(pGDB, projFld, projName, 'FILE_GDB')

#Create new project and import MXD
aprx = arcpy.mp.CreateArcGISProject(projFld, projName, False)
aprx.importDocument(mxd)

#Update datasources from pGDB to fGDB
aprx.updateConnectionProperties(pGDB, fGDB)

aprx.save()