AnsweredAssumed Answered

GetParameterAsText() returning only one character in string

Question asked by Kozix125 on May 22, 2020
Latest reply on May 23, 2020 by Kozix125

Hi, I am a beginner and I have been experimenting with Python module in ArcGIS and I'm trying now to create some kind of automative map. I have set of .lyr files, geodatabase with shapefiles and .csv table with list of names of shapefiles in a row. My goal is to apply symbology to layers based on list picked from .csv table. Shapefiles in geodatabase and .lyr files are named accordingly. When I run hardcoded script, it works just fine. When I use arcpy.GetParameterAsText() troubles begin - the first paremeter dosn't seem to work well at all - it just collects the first character of string that I put in it while using script tool. Do you know, where is the problem?

error log:


Traceback (most recent call last):
File "E:\Kursy_Michal\ArcGIS\Proby\Proba1\", line 30, in <module>
arcpy.MakeFeatureLayer_management(ob, fc)
File "c:\program files (x86)\arcgis\desktop10.7\arcpy\arcpy\", line 6986, in MakeFeatureLayer
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Features: Dataset E:\Kursy_Michal\ArcGIS\Proby\Proba1\Geobaza_1.gdb\l does not exist or is not supported
Failed to execute (MakeFeatureLayer).

Failed to execute (Script3).


import arcpy
mxd = arcpy.mapping.MapDocument(r"E:\Kursy_Michal\ArcGIS\Proby\Proba1\Proba1.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
arcpy.env.workspace = r'E:\Kursy_Michal\ArcGIS\Proby\Proba1\Geobaza_1.mdb'

import csv

g = globals()
i = 0
dct = {}

with open('Warianty1.csv', 'r') as csvfile:
    reader = csv.reader(csvfile, delimiter=';')
    for row in reader:
        dct['l_%s' % i] = []
        #Creating dynamic lists named l_0, l_1, etc for each row
        g['l_{0}'.format(i)] = row[:]
        i += 1

#Choosing list by putting its' name to var2
var2 = arcpy.GetParameterAsText(0)
#Delete empty values in list
filter(None, eval(var2))

path1 = arcpy.GetParameterAsText(1)

path2 = arcpy.GetParameterAsText(2)

#Giving symbology to layers created accordingly to names stored in list
for fc in eval(var2):
     ob = path2 + '\\' + fc
     arcpy.MakeFeatureLayer_management(ob, fc)
     arcpy.ApplySymbologyFromLayer_management(fc, path1 + '\\' + fc + '.lyr')