I am creating my first python tool to export a list of fieldnames to excel. I have the following bits of code:
import arcpyclass Tool(object):def __init__(self): self.label = "Tool" self.description = "Export Fields to Excel" self.canRunInBackground = Falsedef getParameterInfo(self): param0 = arcpy.Parameter( displayName="Shapefile", name="shapefile", datatype="GPShapefile", parameterType="Required", direction="Input") param1 = arcpy.Parameter( displayName="Excel file", name="excelfile", datatype="DETable", parameterType="Required", direction="Input") params = [param0, param1] return paramsdef isLicensed(self): return Truedef updateParameters(self, parameters): returndef updateMessages(self, parameters): returndef execute(self, parameters, messages): fields = arcpy.listfields(shapefile) spreds = open (excelfile, 'w') for f in fields: spreds.write(f.name + "\n") spreds.close() returnFirstly, actual execution part of the code works fine as I have tested it. Im not sure whats wrong when I convert to a .pyt file.
Once I have got this working, is there anyway to create a parameter within the tool to create a new excel/dbf file, and run the script with that information, rather than having to create one first, before running the script. I hope that makes sense.
أكثر...
import arcpyclass Tool(object):def __init__(self): self.label = "Tool" self.description = "Export Fields to Excel" self.canRunInBackground = Falsedef getParameterInfo(self): param0 = arcpy.Parameter( displayName="Shapefile", name="shapefile", datatype="GPShapefile", parameterType="Required", direction="Input") param1 = arcpy.Parameter( displayName="Excel file", name="excelfile", datatype="DETable", parameterType="Required", direction="Input") params = [param0, param1] return paramsdef isLicensed(self): return Truedef updateParameters(self, parameters): returndef updateMessages(self, parameters): returndef execute(self, parameters, messages): fields = arcpy.listfields(shapefile) spreds = open (excelfile, 'w') for f in fields: spreds.write(f.name + "\n") spreds.close() returnFirstly, actual execution part of the code works fine as I have tested it. Im not sure whats wrong when I convert to a .pyt file.
Once I have got this working, is there anyway to create a parameter within the tool to create a new excel/dbf file, and run the script with that information, rather than having to create one first, before running the script. I hope that makes sense.
أكثر...