<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: ArcPy standalone automation script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-standalone-automation-script/m-p/1581933#M73704</link>
    <description>&lt;P&gt;I'm not sure I understand the desired workflow, but here is a script I use to make a total copy of an existing Project (aprx, gdb, and atbx).&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os

# Define paths and names for the new project
new_project_folder = r"path to folder that will contain new project"
new_project_name = "ProjectName.aprx"
new_gdb_name = "ProjectName.gdb"
new_tbx = "ProjectName.atbx"
new_project_path = os.path.join(new_project_folder, new_project_name)
new_gdb_path = os.path.join(new_project_folder, new_gdb_name)
new_tbx_path = os.path.join(new_project_folder, new_tbx)

# Open the original, existing template project
old_project_folder = r"path to folder containing old project"
old_project_name = "TemplateProject.aprx"
old_gdb_name = "TemplateProject.gdb"
old_tbx = "TemplateProject.atbx"
old_project_path = os.path.join(old_project_folder, old_project_name)
old_gdb_path = os.path.join(old_project_folder, old_gdb_name)
old_tbx_path = os.path.join(old_project_folder, old_tbx)
old_project = arcpy.mp.ArcGISProject(old_project_path)

# Create the folder if necessary
if not os.path.exists(new_project_folder):
    os.makedirs(new_project_folder)
    
# Copy GDB and tbx
arcpy.management.Copy(old_gdb_path, new_gdb_path)    
arcpy.management.Copy(old_tbx_path, new_tbx_path)    

# Update data sources
old_project.updateConnectionProperties(old_gdb_path,new_gdb_path)
for map_ in old_project.listMaps():
    for layer in map_.listLayers():
        if layer.supports("dataSource"):
            layer.updateConnectionProperties(old_gdb_path, new_gdb_path)
            
# Update project defaults
old_project.defaultGeodatabase = new_gdb_path
old_project.defaultToolbox = new_tbx_path
old_project.homeFolder = new_project_folder

# Save a copy of the aprx
old_project.saveACopy(new_project_path)&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 04 Feb 2025 19:00:18 GMT</pubDate>
    <dc:creator>BrennanSmith1</dc:creator>
    <dc:date>2025-02-04T19:00:18Z</dc:date>
    <item>
      <title>ArcPy standalone automation script</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-standalone-automation-script/m-p/1579574#M73660</link>
      <description>&lt;P&gt;I was wondering if there is any repository or anything available online or something someone has that can run outside of ArcGIS pro which will create a map&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2025 16:36:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-standalone-automation-script/m-p/1579574#M73660</guid>
      <dc:creator>YahyaMasri</dc:creator>
      <dc:date>2025-01-28T16:36:51Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy standalone automation script</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-standalone-automation-script/m-p/1579587#M73661</link>
      <description>&lt;P&gt;Something basic like this,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy

# Set the paths for the project, layer, and template
new_project_path = r"C:\Temp\new_project.aprx"
layer_path = r"C:\Temp\R36131012A4_Parcel.shp"  #path to the shapefile
template_project_path = r"C:\Temp\template.aprx" 

# Create a new project by copying the template
aprx = arcpy.mp.ArcGISProject(template_project_path)
aprx.saveACopy(new_project_path)

# Open the newly created project
new_aprx = arcpy.mp.ArcGISProject(new_project_path)

# Get the first map from the project
try:
  first_map = new_aprx.listMaps()[0] 
  first_map.addDataFromPath(layer_path)
  print(f"Layer '{layer_path}' added to map in new project at: {new_project_path}")
except IndexError:
  print("No maps found in the template project. Could not add layer.")

# Save the new project
new_aprx.save()
print(f"New project created and saved successfully at: {new_project_path}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2025 17:35:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-standalone-automation-script/m-p/1579587#M73661</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2025-01-28T17:35:30Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy standalone automation script</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-standalone-automation-script/m-p/1579604#M73662</link>
      <description>&lt;P&gt;what happens to the .gdb when creating a new project from a template? do i need to programmatically copy it over -- i dont want to have to use the template gdb -- i assume i need to use the new projects gdb and atbx etc&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2025 17:31:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-standalone-automation-script/m-p/1579604#M73662</guid>
      <dc:creator>YahyaMasri</dc:creator>
      <dc:date>2025-01-28T17:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy standalone automation script</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-standalone-automation-script/m-p/1579612#M73663</link>
      <description>&lt;P&gt;You could add some code to create a database in the .aprx folder.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;# Directory of the new project
new_project_dir = os.path.dirname(new_project_path)

# Create a new file geodatabase in .aprx directory
gdb_name = "new_project.gdb"  # Name of the geodatabase
gdb_path = os.path.join(new_project_dir, gdb_name)

if not os.path.exists(gdb_path):  # Check if the GDB already exists
    arcpy.CreateFileGDB_management(new_project_dir, gdb_name)
    print(f"File geodatabase created at: {gdb_path}")
else:
    print(f"File geodatabase already exists at: {gdb_path}")&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 28 Jan 2025 17:41:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-standalone-automation-script/m-p/1579612#M73663</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2025-01-28T17:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy standalone automation script</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-standalone-automation-script/m-p/1581387#M73693</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/801294"&gt;@YahyaMasri&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;When you say "create a map", do you mean create a Map in ArcGIS Pro (aprx) or create a Map by exporting a Layout to PDF for example.&amp;nbsp;&lt;/P&gt;&lt;P&gt;To create a new Map in an existing .aprx you can use the below code snippet.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

## the path to the existing aprx
aprx_path = r"C:\path\to\my\Project.aprx"

## get the aprx as an ArcGISProject object
aprx = arcpy.mp.ArcGISProject(aprx_path=aprx_path)

## create the new Map object
new_map = aprx.createMap(name="NEW_MAP",map_type="Map")

## do what you want with the new_map, add layers and tables for example

## save the aprx
aprx.save()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Feb 2025 17:20:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-standalone-automation-script/m-p/1581387#M73693</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2025-02-03T17:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy standalone automation script</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-standalone-automation-script/m-p/1581933#M73704</link>
      <description>&lt;P&gt;I'm not sure I understand the desired workflow, but here is a script I use to make a total copy of an existing Project (aprx, gdb, and atbx).&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os

# Define paths and names for the new project
new_project_folder = r"path to folder that will contain new project"
new_project_name = "ProjectName.aprx"
new_gdb_name = "ProjectName.gdb"
new_tbx = "ProjectName.atbx"
new_project_path = os.path.join(new_project_folder, new_project_name)
new_gdb_path = os.path.join(new_project_folder, new_gdb_name)
new_tbx_path = os.path.join(new_project_folder, new_tbx)

# Open the original, existing template project
old_project_folder = r"path to folder containing old project"
old_project_name = "TemplateProject.aprx"
old_gdb_name = "TemplateProject.gdb"
old_tbx = "TemplateProject.atbx"
old_project_path = os.path.join(old_project_folder, old_project_name)
old_gdb_path = os.path.join(old_project_folder, old_gdb_name)
old_tbx_path = os.path.join(old_project_folder, old_tbx)
old_project = arcpy.mp.ArcGISProject(old_project_path)

# Create the folder if necessary
if not os.path.exists(new_project_folder):
    os.makedirs(new_project_folder)
    
# Copy GDB and tbx
arcpy.management.Copy(old_gdb_path, new_gdb_path)    
arcpy.management.Copy(old_tbx_path, new_tbx_path)    

# Update data sources
old_project.updateConnectionProperties(old_gdb_path,new_gdb_path)
for map_ in old_project.listMaps():
    for layer in map_.listLayers():
        if layer.supports("dataSource"):
            layer.updateConnectionProperties(old_gdb_path, new_gdb_path)
            
# Update project defaults
old_project.defaultGeodatabase = new_gdb_path
old_project.defaultToolbox = new_tbx_path
old_project.homeFolder = new_project_folder

# Save a copy of the aprx
old_project.saveACopy(new_project_path)&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 04 Feb 2025 19:00:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-standalone-automation-script/m-p/1581933#M73704</guid>
      <dc:creator>BrennanSmith1</dc:creator>
      <dc:date>2025-02-04T19:00:18Z</dc:date>
    </item>
  </channel>
</rss>

