SetParameterAsText To View Python Tool Results

5538
32
06-08-2016 02:47 PM
DevinUnderwood2
Occasional Contributor

I have the following which I can successfully get my desired results with the input prompt standalone script.  Yet, I prefer that a tool I created to be used and display the results. What am I missing in order to view the results?

#Import Modules
import csv,os,arcpy

#Set variables
ifile  = open('PythonShellSave.csv','r')
reader = csv.reader(ifile)
featureclass = input("Name of the feature class ? ")
#featureclass = arcpy.GetParameterAsText(0)
 
#Set path location of Excel (CSV) file 
path = 'C:\WriteMxdInfoToExcel'
os.chdir(path)

#CSV Module terminology row is horizontal & field is vertical;column is horizontal & row is vertical for excel.
for row in reader:
          for field in row:
              if field == featureclass:
                  print row [4] + " " + featureclass
                 
arcpy.SetParameterAsText(1,row)

#Close Excel (CSV) file
ifile.close()
0 Kudos
32 Replies
DevinUnderwood2
Occasional Contributor

Interesting, I added what you suggested and get

All Mxds associated with fc = view results not defined, this means it is not recognizing the loop statements.

This works fine as a stand alone, so I know the loop syntax works fine. However, the AddMessage is the issue with a loop statement.

0 Kudos
DevinUnderwood2
Occasional Contributor

I have the following and trying to write to file when using tool getparameterastext.  Its not writing though?

#Import Modules
import csv,os,arcpy

#Set path location of Excel (CSV) file 
path = r'C:\Users\dunderwood\Documents\PyScriptTools\Tools\ToolData'
arcpy.env.workspace = path

#Set variables
ifile  = open('PublishedMapsInfo.csv','r')
ofile = open('Results.csv','w')
reader = csv.reader(ifile)
writer = csv.writer(ofile, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
featureclass = arcpy.GetParameterAsText(0)

#CSV Module terminology row is horizontal & field is vertical;column is horizontal & row is vertical for excel
for row in reader:
          for field in row:
              if field == featureclass:
                  final = (row[4] + " " + featureclass)
                  writer.writerow([final])
                  
                                                   
#arcpy.AddMessage('All Mxds associated with fc = {}'.format(viewmessage))
#Close Excel (CSV) file
ifile.close()
ofile.close()
0 Kudos
DanPatterson_Retired
MVP Emeritus

your incarnation of the script keeps changing sometimes reflecting comments and sometimes not.  Currently you are printing a list in line 20.  This is new.  Your print statements are now gone.  This is also new.  All I know is that the file isn't printing and you have not reported any errors.  So presumably, your files have been created and are empty since you can open them and close them.  The only thing I can suggest is you move the source file to a new location and see if a new empty destination file is created.  If so, then you know that the file is being created but nothing is being written to it.  Without further print statements, this would narrow down the error to somewhere between lines 13 and 20

0 Kudos