I am having an issue with a recent script/toolbox I have developed. My aim is to perform some tasks (copy features, then add them to the map then symbolise them). The majority of the tasks complete successfully, however, only the last feature layer adds to the map. I think the error is being generated as the "arcpy.SetParameter" function is not a global variable, therefore it only works on the last feature layer.
import arcpy
import os
from arcpy.mp import *
from arcpy import env
arcpy.env.addOutputsToMap = True
# User input feature
GDB_Store = arcpy.GetParameterAsText(0)
# Define the name of the project (long and clunky process -so could be improved)
aprox = arcpy.mp.ArcGISProject("CURRENT")
username = os.getlogin()
# Field Points that will be used
ISOs = r'C:\Users\{}\xxx\xxx\Collector Template.gdb\Artefact_Data\ISOs'.format(username)
New_Site_Boundary = r"C:\Users\{}\xxx\xxx\Collector Template.gdb\Collector Template.gdb\Heritage_Site_Boundary\Site_Boundary".format(username)
NEW_Feature_Polygon = r"C:\Users\{}\xxx\xxx\Collector Template.gdb\Collector Template.gdb\Features\NEW_Feature_Polygon".format(username)
NEW_Feature_Point = r"C:\Users\{}\xxx\xxx\Collector Template.gdb\Collector Template.gdb\Features\NEW_Feature_Point".format(username)
NEW_Feature_Line = r"C:\Users\{}\xxx\xxx\Collector Template.gdb\Collector Template.gdb\Features\NEW_Feature_Line".format(username)
Sample_Salvage_Squares = r"C:\Users\{}\xxx\xxx\Collector Template.gdb\Collector Template.gdb\Artefact_Data\Sample_Salvage_Squares".format(username)
New_Artefact_Point = r"C:\Users\{}\xxx\xxx\Collector Template.gdb\Collector Template.gdb\Artefact_Data\Artefact_Point".format(username)
New_Site_Boundary_Point = r"C:\Users\{}\xxx\xxx\Collector Template.gdb\Collector Template.gdb\Heritage_Site_Boundary\Site_Boundary_Points".format(username)
#set symbology paths
ISOs_Sym = r"C:\Users\{}\xxx\xxx\Collector Template.gdb\Symbology\ISOs.lyrx".format(username)
New_Site_Boundary_Sym = r"C:\Users\{}\xxx\xxx\Collector Template.gdb\Symbology\New Site Boundary.lyrx".format(username)
NEW_Feature_Polygon_Sym = r"C:\Users\{}\xxx\xxx\Collector Template.gdb\Symbology\NEW_Feature_Polygon.lyrx".format(username)
NEW_Feature_Point_Sym = r"C:\Users\{}\xxx\xxx\Collector Template.gdb\Symbology\New Feature Points.lyrx".format(username)
NEW_Feature_Line_Sym = r"C:\Users\{}\xxx\xxx\Collector Template.gdb\Symbology\NEW_Feature_Line.lyrx".format(username)
Sample_Salvage_Squares_Sym = r"C:\Users\{}\xxx\xxx\Collector Template.gdb\Symbology\Sample - Salvage Squares.lyrx".format(username)
New_Artefact_Point_Sym = r"C:\Users\{}\xxx\xxx\Collector Template.gdb\Symbology\Artefact Point.lyrx".format(username)
New_Site_Boundary_Point_Sym =r"C:\Users\{}\xxx\xxx\Collector Template.gdb\Symbology\New Site Boundary Points.lyrx".format(username)
# Create static layer lists
static_layers = [ISOs, New_Site_Boundary, NEW_Feature_Polygon, NEW_Feature_Point, NEW_Feature_Line, Sample_Salvage_Squares, New_Artefact_Point, New_Site_Boundary_Point]
static_layers_sym = [ISOs_Sym, New_Site_Boundary_Sym, NEW_Feature_Polygon_Sym, NEW_Feature_Point_Sym, NEW_Feature_Line_Sym, Sample_Salvage_Squares_Sym, New_Artefact_Point_Sym, New_Site_Boundary_Point_Sym]
static_layer_name = ["ISOs", "New Site Boundary", "NEW Feature Polygon", "NEW Feature Point", "NEW Feature Line", "Sample Salvage Squares", "New Artefact Point", "New Site Boundary Point"]
static_layer_name_store = ["ISOs", "New_Site_Boundary", "NEW_Feature_Polygon", "NEW_Feature_Point", "NEW_Feature_Line", "Sample_Salvage_Squares", "New_Artefact_Point", "New_Site_Boundary_Point"]
# define model for static layers
def Model1(static_layers, static_layer_name, static_layer_name_store, static_layers_sym): # Model1
# Define location and name of feature layers
feature_path = GDB_Store + "\\" + static_layer_name_store
# Copy the feature layers
arcpy.management.CopyFeatures(in_features=static_layers, out_feature_class=feature_path, config_keyword="", spatial_grid_1=None, spatial_grid_2=None, spatial_grid_3=None)
# Process: Make Feature Layer (Make Feature Layer) (management)
layer_e = static_layer_name
arcpy.management.MakeFeatureLayer(in_features=feature_path, out_layer=layer_e, where_clause="", workspace="", field_info="OBJECTID OBJECTID VISIBLE NONE;SHAPE SHAPE VISIBLE NONE;Art_ID Art_ID VISIBLE NONE;Type Type VISIBLE NONE;Notes Notes VISIBLE NONE")
# Add layers to map
arcpy.SetParameter(1, static_layer_name)
# Process: Apply Symbology From Layer (Apply Symbology From Layer) (management)
arcpy.management.ApplySymbologyFromLayer(in_layer=layer_e, in_symbology_layer=static_layers_sym, symbology_fields=[], update_symbology="DEFAULT")[0]
# Run feature layers
if __name__ == '__main__':
with arcpy.EnvManager(scratchWorkspace=GDB_Store, workspace=GDB_Store):
for r, x, y, z in zip(static_layers, static_layer_name, static_layer_name_store, static_layers_sym):
Model1(r, x, y, z)
I have attempted to add the "SetParamaterAsText" function outside of the function, but this has had limited success. Any suggestions would be greatly appreciated.