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 ( |
String |
|
create_parent_folder |
When set to The default value is True. |
Boolean |
|
home_folder |
The If not specified, the default behavior is to set the |
String |
|
default_database |
The full path to a file geodatabase ( If not specified, the default behavior is to create a file geodatabase with the same name as the |
String |
|
default_toolbox |
The full path to an ArcGIS toolbox ( If not specified, the default behavior is to create an ArcGIS toolbox with the same name as the |
String |
Return value
| Data Type | Explanation |
|---|---|
|
ArcGISProject |
An |
Code sample
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}')
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()
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()