Hi;
I am trying to create a new Pro Project from a previous template.
I have a couple questions:
- When I update the default toolbox, it gets added to the project as default but the old toolbox is still there referenced. Is there any way to remove it in Python without deleting it?
- Similar to above, when I updated the Home Folder, it gets added but the old folder is still there. Is there any way to remove it in Python without deleting it?
- My main concern, when I update the default database, it does not show initially and is not added automatically to the list of databases. Is there anyway to add it via Python and remove the old one, without deleting it? When I add the new default database connection manually it does show it is the default gdb.
I have included a couple screenshots of the Pro Project Catalog Pane after the script is completed and then once I manually add the new gdb connection.
I have also pasted my code below. I removed file paths as these are not pertinent for the issue.
Any help would be appreciated!
import arcpy
import os
import shutil
# Main Downloads
downloads_fol = r'C:\Users\rossch\Downloads'
# ArcGIS Prp template to copy
pro_template = r'FULL PATH TO PRO APRX TEMPLATE'
# Specify the ArcGIS Pro reference
pro_temp_aprx = arcpy.mp.ArcGISProject(pro_template)
# Ask the user for the Pro project name; set the new project path and save a copy
pro_name = input('Enter the name of the ArcGIS Pro folder and project to create: ')
# Specify the folder name and if it doesn't exist, create it
pro_prj_fol = os.path.join(downloads_fol, f'{pro_name}')
if not os.path.exists(pro_prj_fol):
os.mkdir(pro_prj_fol)
# Specify the new project name
new_pro_prj = os.path.join(pro_prj_fol, f'{pro_name}.aprx')
# Save a copy of the template ArcGIS Pro project
pro_temp_aprx.saveACopy(new_pro_prj)
# Clean up the original template ArcGIS Pro project
del pro_temp_aprx
# Set the new copied project as the ArcGIS Pro reference
main_aprx = arcpy.mp.ArcGISProject(new_pro_prj)
# Set the home folder
main_aprx.homeFolder = pro_prj_fol
# Create a new file geodatabase and make that the default gdb for the project
prj_gdb = os.path.join(pro_prj_fol, f'{pro_name}.gdb')
arcpy.CreateFileGDB_management(pro_prj_fol, f'{pro_name}.gdb')
main_aprx.defaultGeodatabase = prj_gdb
# Copy the template toolbox and make the default for the project
orig_tbx = r'FULL PATH TO TOOLBOX'
new_pro_tbx = os.path.join(pro_prj_fol, f'{pro_name}.atbx')
shutil.copy(orig_tbx, new_pro_tbx)
main_aprx.defaultToolbox = new_pro_tbx
# Save the project
main_aprx.save()
# Start the copied ArcGIS Pro project
os.startfile(new_pro_prj)