Also, more likely to get responses with code question if you use the code editor to insert code into the post.
- I couldn't see the code editor first time around but that looks much more accessible now, thanks!
Can just select stuff in one model, copy, paste into the other and connect them.
- When I'm in the model builder and I can't directly connect Model4 to any process as it isn't a variable. For reference, it doesn't seem to me that the function from Model4 is being used in the code for Model3. I'm not sure how I can signal to Model Builder that in essence I would like the function from Model4 to run prior to the function created for Model3.
This is perhaps due to my lack of knowledge of how the arcpy.EnvManger parameters work - if anyone has any tips on that it would be appreciated.
Model3:
# -*- coding: utf-8 -*-
"""
Generated by ArcGIS ModelBuilder on : 2022-05-11 12:46:03
"""
import arcpy
import os
from Default.Model4 import Model4
from sys import argv
def FeatureClassGenerator(workspace, wild_card, feature_type, recursive) :
with arcpy.EnvManager(workspace = workspace):
dataset_list = [""]
if recursive:
datasets = arcpy.ListDatasets()
dataset_list.extend(datasets)
for dataset in dataset_list:
featureclasses = arcpy.ListFeatureClasses(wild_card, feature_type, dataset)
for fc in featureclasses:
yield os.path.join(workspace, dataset, fc), fc
def Model3(test_poly="test_poly"): # Model 3
# To allow overwriting outputs change overwriteOutput option to True.
arcpy.env.overwriteOutput = False
Model_Variables = "C:\\Users\\Scar\\Documents\\landCharges\\landCharges\\Model_Variables"
for AssetsCV_shp, Name in FeatureClassGenerator(Model_Variables, "", "", "NOT_RECURSIVE"):
# Process: Add Field (Add Field) (management)
AssetsCV_shp_2_ = arcpy.management.AddField(in_table=AssetsCV_shp, field_name="Reference", field_type="TEXT", field_precision=None, field_scale=None, field_length=100, field_alias="", field_is_nullable="NULLABLE", field_is_required="NON_REQUIRED", field_domain="")[0]
# Process: Model 4 (Model 4) (Default)
Model4(test_poly=test_poly)
if __name__ == '__main__':
# Global Environment settings
with arcpy.EnvManager(outputCoordinateSystem="PROJCS["British_National_Grid",GEOGCS["GCS_OSGB_1936",DATUM["D_OSGB_1936",SPHEROID["Airy_1830",6377563.396,299.3249646]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",400000.0],PARAMETER["False_Northing",-100000.0],PARAMETER["Central_Meridian",-2.0],PARAMETER["Scale_Factor",0.9996012717],PARAMETER["Latitude_Of_Origin",49.0],UNIT["Meter",1.0]]", scratchWorkspace=r"C:\Users\Scar\Documents\landCharges\landCharges\Default.gdb", workspace=r"C:\Users\Scar\Documents\landCharges\landCharges\Default.gdb"):
Model3(*argv[1:])
Model4:
# -*- coding: utf-8 -*-
"""
Generated by ArcGIS ModelBuilder on : 2022-05-11 12:46:26
"""
import arcpy
from sys import argv
def # NOT IMPLEMENTED# Function Body not implemented
def Model4(test_poly): # Model 4
# To allow overwriting outputs change overwriteOutput option to True.
arcpy.env.overwriteOutput = False
arcpy.ImportToolbox(r"c:\program files\arcgis\pro\Resources\ArcToolbox\toolboxes\Conversion Tools.tbx.tbx")
Input_Map = "Layers"
Model_Variables_2_ = "C:\\Users\\Scar\\Documents\\landCharges\\landCharges\\Model_Variables"
for OUTPUT_LAYER, Name, Output_Layer_Type, Workspace_or_Format_Type in # NOT IMPLEMENTED(Input_Map, "", ["FeatureLayer"], [], [], [], "ALL", "ALL", "RECURSIVE"):
# Process: Select Layer By Location (Select Layer By Location) (management)
AssetsCV, Output_Layer_Names, Count = arcpy.management.SelectLayerByLocation(in_layer=[OUTPUT_LAYER], overlap_type="INTERSECT", select_features=test_poly, search_distance="", selection_type="NEW_SELECTION", invert_spatial_relationship="NOT_INVERT")
# Process: Feature Class To Shapefile (Feature Class To Shapefile) (conversion)
Model_Variables = arcpy.conversion.FeatureClassToShapefile(Input_Features=[OUTPUT_LAYER], Output_Folder=Model_Variables_2_)[0]
if __name__ == '__main__':
# Global Environment settings
with arcpy.EnvManager(outputCoordinateSystem="PROJCS["British_National_Grid",GEOGCS["GCS_OSGB_1936",DATUM["D_OSGB_1936",SPHEROID["Airy_1830",6377563.396,299.3249646]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",400000.0],PARAMETER["False_Northing",-100000.0],PARAMETER["Central_Meridian",-2.0],PARAMETER["Scale_Factor",0.9996012717],PARAMETER["Latitude_Of_Origin",49.0],UNIT["Meter",1.0]]", scratchWorkspace=r"C:\Users\Scar\Documents\landCharges\landCharges\Default.gdb", workspace=r"C:\Users\Scar\Documents\landCharges\landCharges\Default.gdb"):
Model4(*argv[1:])
Thanks for taking a look!