Trying the following:
1. Add polygon Layer from gpkg and rename Layer
2. Add Line Layer from gpkg and rename Layer
3. Run Model with Parameters set to added Layers
4. Remove Layers.
Then repeat for the next geocell (many many more)
Problem.
All outputs are the same as the first Layers added. Even though the Layers are removed and new Layers added and I clean out the ScratchGDB all outputs are the same as the first one. If I don't remove the Layers and just keep adding new Layers it works ok. BUT I have hundreds of geopackages and the project gets bloated and ARCGIs runs very very slowly (10x slower) so I really need to remove Layers after each time the Model is run.
Help!
import arcpy
from WorldFPatbx.DeleteScratchGDB import DeleteScratchGDB
from WorldFPatbx.ModelSub01 import ModelSub01
aprx = arcpy.mp.ArcGISProject('CURRENT')
current_map = aprx.activeMap
def ModelMaster_9_3_45__135():
arcpy.AddMessage("Starting Building_9_3_45__135")
current_map.addDataFromPath("D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_3\\World_9_3_45_-135.gpkg\\main.multipolygons")
layer = current_map.listLayers("main.multipolygons")[0]
layer.name = "multipolygons_45__135"
polyLyr=layer
current_map.addDataFromPath("D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_3\\World_9_3_45_-135.gpkg\\main.lines")
layer = current_map.listLayers("main.lines")[0]
layer.name = "lines_45__135"
lineLyr=layer
main_multipolygons = "multipolygons_45__135"
main_lines = "lines_45__135"
Footprints_gpkg = "D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_3\\BuildingFP\\Footprints_9_3_45__135.gpkg"
Buildings = "D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_3\\BuildingFP\\Footprints_9_3_45__135.gpkg\\Buildings"
ModelSub01(Input_Lines=main_lines, Input_polygons=main_multipolygons, FPGeopackage=Footprints_gpkg, GPFootprints=Buildings)
DeleteScratchGDB()
current_map.removeLayer(polyLyr)
current_map.removeLayer(lineLyr)
arcpy.AddMessage("Building_9_3_45__135 Finished")
with arcpy.EnvManager(scratchWorkspace="C:\\ArcGISProjectNXT\\WorldFP\\WorldFP.gdb", workspace="C:\\ArcGISProjectNXT\\WorldFP\\WorldFP.gdb"):
ModelMaster_9_3_45__135()
def ModelMaster_9_3_45__134():
arcpy.AddMessage("Starting Building_9_3_45__134")
current_map.addDataFromPath("D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_3\\World_9_3_45_-134.gpkg\\main.multipolygons")
layer = current_map.listLayers("main.multipolygons")[0]
layer.name = "multipolygons_45__134"
polyLyr=layer
current_map.addDataFromPath("D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_3\\World_9_3_45_-134.gpkg\\main.lines")
layer = current_map.listLayers("main.lines")[0]
layer.name = "lines_45__134"
lineLyr=layer
main_multipolygons = "multipolygons_45__134"
main_lines = "lines_45__134"
Footprints_gpkg = "D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_3\\BuildingFP\\Footprints_9_3_45__134.gpkg"
Buildings = "D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_3\\BuildingFP\\Footprints_9_3_45__134.gpkg\\Buildings"
ModelSub01(Input_Lines=main_lines, Input_polygons=main_multipolygons, FPGeopackage=Footprints_gpkg, GPFootprints=Buildings)
DeleteScratchGDB()
current_map.removeLayer(polyLyr)
current_map.removeLayer(lineLyr)
arcpy.AddMessage("Building_9_3_45__134 Finished")
with arcpy.EnvManager(scratchWorkspace="C:\\ArcGISProjectNXT\\WorldFP\\WorldFP.gdb", workspace="C:\\ArcGISProjectNXT\\WorldFP\\WorldFP.gdb"):
ModelMaster_9_3_45__134()
Code formatting ... the Community Version - Esri Community
line numbers will be useful to those wanting to examine your code
Now just apply that to the code you posted in the original thread
Updated snapshot.
Som progress. but
Your code in your first thread
import arcpy
from WorldFPatbx.DeleteScratchGDB import DeleteScratchGDB
from WorldFPatbx.ModelSub01 import ModelSub01
aprx = arcpy.mp.ArcGISProject('CURRENT')
.... snip ....
Your code after following the thread I posted and using code blocks ( </> )
import arcpy
from WorldFPatbx.DeleteScratchGDB import DeleteScratchGDB
from WorldFPatbx.ModelSub01 import ModelSub01
aprx = arcpy.mp.ArcGISProject('CURRENT')
.....snip....
Not sure what y'all are trying to tell me here Dan. But here's yet another snapshot. Anyway , ignoring the fact I'm not a real developer and write sloppy code, if anyone has any idea why it's not working as desired I sure would appreciate it.
You are posting screen shots
hit ...
then </>
pick your language
paste your code in there
People can copy and paste code from an image, but they can from a code block in a post or response
Thanks.
import arcpy
from MyProjectTwoatbx.DeleteScratchGDB import DeleteScratchGDB
from MyProjectTwoatbx.ModelSub01 import ModelSub01
aprx = arcpy.mp.ArcGISProject('CURRENT')
current_map = aprx.activeMap
def ModelMaster_9_1_45__165():
arcpy.AddMessage("Starting Building_9_1_45__165")
current_map.addDataFromPath("D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_1\\World_9_1_45_-165.gpkg\\main.multipolygons")
layer = current_map.listLayers("main.multipolygons")[0]
layer.name = "multipolygons_45__165"
polyLyr=layer
current_map.addDataFromPath("D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_1\\World_9_1_45_-165.gpkg\\main.lines")
layer = current_map.listLayers("main.lines")[0]
layer.name = "lines_45__165"
lineLyr=layer
arcpy.env.overwriteOutput = True
main_multipolygons = "multipolygons_45__165"
main_lines = "lines_45__165"
Footprints_gpkg = "D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_1\\BuildingFP\\Footprints_9_1_45__165.gpkg"
Buildings = "D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_1\\BuildingFP\\Footprints_9_1_45__165.gpkg\\Buildings"
ModelSub01(Input_Lines=main_lines, Input_polygons=main_multipolygons, FPGeopackage=Footprints_gpkg, GPFootprints=Buildings)
DeleteScratchGDB()
current_map.removeLayer(polyLyr)
current_map.removeLayer(lineLyr)
arcpy.AddMessage("Building_9_1_45__165 Finished")
with arcpy.EnvManager(scratchWorkspace="C:\\ArcGISProjectNXT\\MyProjectTwo\\MyProjectTwo.gdb", workspace="C:\\ArcGISProjectNXT\\MyProjectTwo\\MyProjectTwo.gdb"):
ModelMaster_9_1_45__165()
def ModelMaster_9_1_45__164():
arcpy.AddMessage("Starting Building_9_1_45__164")
current_map.addDataFromPath("D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_1\\World_9_1_45_-164.gpkg\\main.multipolygons")
layer = current_map.listLayers("main.multipolygons")[0]
layer.name = "multipolygons_45__164"
polyLyr=layer
current_map.addDataFromPath("D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_1\\World_9_1_45_-164.gpkg\\main.lines")
layer = current_map.listLayers("main.lines")[0]
layer.name = "lines_45__164"
lineLyr=layer
arcpy.env.overwriteOutput = True
main_multipolygons = "multipolygons_45__164"
main_lines = "lines_45__164"
Footprints_gpkg = "D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_1\\BuildingFP\\Footprints_9_1_45__164.gpkg"
Buildings = "D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_1\\BuildingFP\\Footprints_9_1_45__164.gpkg\\Buildings"
ModelSub01(Input_Lines=main_lines, Input_polygons=main_multipolygons, FPGeopackage=Footprints_gpkg, GPFootprints=Buildings)
DeleteScratchGDB()
current_map.removeLayer(polyLyr)
current_map.removeLayer(lineLyr)
arcpy.AddMessage("Building_9_1_45__164 Finished")
with arcpy.EnvManager(scratchWorkspace="C:\\ArcGISProjectNXT\\MyProjectTwo\\MyProjectTwo.gdb", workspace="C:\\ArcGISProjectNXT\\MyProjectTwo\\MyProjectTwo.gdb"):
ModelMaster_9_1_45__164()