|
POST
|
Thank you for taking the time to further explain. Will this work in a script that I am using with a tool I created? To automatically display message to results? I tested out the function but it is not automatic when run and seen in python shell. However, as mentioned, my actual goal is to use it as a tool. I will take a look at the Blog, thanks.
... View more
06-09-2016
09:44 AM
|
0
|
5
|
3037
|
|
POST
|
Thank you for the input. However I am not familiar enough with the time module nor what the % means. I am not aware of .format either. As you can see I am beginner and I am just learning and attempting to properly use the Add Message, which I am still working on.
... View more
06-09-2016
07:57 AM
|
0
|
7
|
3037
|
|
POST
|
Yes equivalent of a print statement within arcmap. I just want to view results. I will take a look about AddMessage, thank you.
... View more
06-08-2016
03:03 PM
|
0
|
10
|
3037
|
|
POST
|
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()
... View more
06-08-2016
02:47 PM
|
0
|
32
|
11667
|
|
POST
|
I broke the code apart into 2 separate parts. Part 1) Looped the mxds and successfully printed the feature classes Part 2) Using Search Cursor works fine on a shapefile but not a feature class. The problem is accessing a feature class in an sde environment is what I conclude. It cannot open the feature class. I will keep testing why is this the case, I may need to recheck how I set path using sde feature classes and their connection, may need special set up .
... View more
05-31-2016
04:14 PM
|
0
|
0
|
548
|
|
POST
|
I would see the "print out" (results) in the python shell which would be written to the csv file also.
... View more
05-31-2016
01:33 PM
|
0
|
2
|
1977
|
|
POST
|
Thank you for the advice. I went ahead and changed according to your code, yet still get the same code error. I would not want the layer names, but rather the feature class name. I want the fullpath which has the mxd name. Ultimately, the print out would have the mxd name and feature class name. There are subfolders and group layers.
... View more
05-31-2016
10:45 AM
|
0
|
4
|
1977
|
|
POST
|
Yes, that is exactly what I am trying to do. It seems like I am trying something that is difficult or not possible to do. At least I know it isn't just me being a beginner.
... View more
05-31-2016
06:59 AM
|
0
|
0
|
1977
|
|
POST
|
Does this mean I need to restructure the loop syntax of the mxds to connection files first then mxd path ?
... View more
05-27-2016
02:24 PM
|
0
|
8
|
1977
|
|
POST
|
I changed it to just read the lyr_source yet still same error.
... View more
05-27-2016
12:51 PM
|
0
|
0
|
1977
|
|
POST
|
I want both so I get the mxd name and feature class path fullpath is C:\Users\dunderwood\Documents\MY_TEMPLATES\CityWorks\CW_ENV_FMSE_EDIT.mxd lyr_source is Database Connections\CW_ENV_uCW_ENV_vCW_ENV.sde\PW.EnvironmentalCompliance\PW.ServiceEstablishments I am not sure SDE vs regular file path.
... View more
05-27-2016
11:46 AM
|
0
|
2
|
2737
|
|
POST
|
# Import Modules
import arcpy,os,csv
#Set folder space
folder = r'C:\MY_TEMPLATES\CW'
#Loop All Mxd's in a folder and print out Info.
for filename in os.listdir(folder):
fullpath = os.path.join(folder, filename)
if os.path.isfile(fullpath):
basename, extension = os.path.splitext(fullpath)
if extension.lower() == ".mxd":
mxd = arcpy.mapping.MapDocument(fullpath)
dfs = arcpy.mapping.ListDataFrames(mxd)
for df in dfs:
layers = arcpy.mapping.ListLayers(mxd, "", df)
for layer in layers:
if layer.isFeatureLayer:
lyr_source = layer.dataSource
lyr_name = layer.name.encode("utf8", "replace")
s = (fullpath + lyr_source)
print s
with open('TEST.csv', 'w') as csvfile:
csvwriter = csv.writer(csvfile, delimiter=',', lineterminator='\n')
fields = ['*']
with arcpy.da.SearchCursor(s, fields) as s_cursor:
for row in s_cursor:
csvwriter.writerow(row)
#Close Excel File
csvfile.close()
print "Closed or Not: ",csvfile.closed Run Script: (I get the following which I want looped to write to csv, but the cursor currently retrieves fields) C:\MY_TEMPLATES\CW\CW_ENV_FMSE_EDIT.mxdDatabase Connections\CW_ENV_uCW_ENV_vCW_ENV.sde\PW.EnvironmentalCompliance\PW.ServiceEstablishments Traceback (most recent call last): File "C:\Users\dunderwood\Desktop\LoopMXDListLayers.py", line 30, in <module> with arcpy.da.SearchCursor(s, fields) as s_cursor: RuntimeError: cannot open 'C:\MY_TEMPLATES\CW\CW_ENV_FMSE_EDIT.mxdDatabase Connections\CW_ENV_uCW_ENV_vCW_ENV.sde\PW.EnvironmentalCompliance\PW.ServiceEstablishments'
... View more
05-27-2016
10:52 AM
|
0
|
14
|
2737
|
|
POST
|
I have been looking at how to post code in geo net and building paths correctly. (Thanks Blake) I have only successfully formatted my original posting and still looking at building paths correctly. I always use the raw as a path r'C:\...'
... View more
05-27-2016
09:34 AM
|
0
|
16
|
2737
|
|
POST
|
Traceback (most recent call last): File "C:\Users\dunderwood\Desktop\LoopMXDListLayers.py", line 39, in <module> with arcpy.da.SearchCursor(s, fields) as s_cursor: RuntimeError: cannot open 'C:\...
... View more
05-27-2016
09:02 AM
|
0
|
18
|
2737
|
|
POST
|
I have the following and choose a random field name that is in one of the many feature classes I need returned. I still have the error. with open('TEST.csv', 'w') as csvfile:
csvwriter = csv.writer(csvfile, delimiter=',', lineterminator='\n')
fields = ['APN']
with arcpy.da.SearchCursor(s, fields) as s_cursor:
for row in s_cursor:
csvwriter.writerow(fields)
... View more
05-27-2016
08:40 AM
|
0
|
21
|
2737
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 11-03-2016 06:52 AM | |
| 1 | 05-10-2016 10:27 AM | |
| 1 | 02-06-2017 01:22 PM | |
| 1 | 05-01-2018 07:23 AM | |
| 1 | 03-03-2017 02:46 PM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:24 AM
|