|
POST
|
I modified with arcpy.da.SearchCursor(inputTable, fields) as s_cursor: to with arcpy.da.SearchCursor(s,"") as s_cursor: I don't want field names and the s is a variable I set for all feature classes/paths for mxds in a specified folder. I get the following error when I run my script cannot open 'C:\CW\...... Does anyone know why? Thanks for your help in advance.
... View more
05-27-2016
08:24 AM
|
0
|
23
|
8542
|
|
POST
|
Yes, I am still trying csv module. I realize I have been going back and forth in a different post, for trying to find the easiest way.
... View more
05-27-2016
08:16 AM
|
0
|
0
|
8542
|
|
POST
|
Yes, thank you for clarifying. I am trying this out and realizing that I can easily read an existing file and write to another, but my returned featureclass results requires something else. I set a variable and I would get unusual results like you posted, vertically one character per cell,etc. I will read up on Search Cursor and I am one step closer to what I need. I thought Search Cursor is only to return field names of feature classes and tables, which I want the feature class name and path. To be cont...
... View more
05-27-2016
07:40 AM
|
0
|
2
|
8542
|
|
POST
|
The variable represents mxd/path/feaure class name, for all in a specified folder. Example: C:\Users\me\Documents\xxxxx.mxdDatabaseConnections\PW_vCW_uCW.sde\PW.WDistribution\PW.wControlValve I assigned a variable and trying to write it to csv file. You mentioned I need to read it. Is search cursor what I need or do I read it another way?
... View more
05-26-2016
01:04 PM
|
0
|
4
|
8542
|
|
POST
|
I have multiple lines but only one is written to the csv file. What am I missing from an except of my code. s = (fullpath + lyr_source)
with open('TEST.csv', 'w') as writeexcel:
a = csv.writer(writeexcel)
for line in :
a.writerow ([line])
... View more
05-26-2016
11:57 AM
|
0
|
31
|
21117
|
|
POST
|
I went ahead and arrived at this, using built in python. This performs perfect as a test. However, I have an issue when setting a returned list as a reader then writing. The error is AttributeError: 'unicode' object has no attribute 'readlines. I think it has an issue with passing the list in its current encoded state ? #Open Excel Docuements readexcel = open ('xxx.csv','r') writeexcel = open ('yyy.csv','w') #Set Reader & Writer reader = readexcel.readlines() writer = writeexcel.writelines (reader) #Loop Read Excel Document to print to Write Excel Docuement for line in (readexcel): line = readexcel.next() print (line) #Close Excel Files readexcel.close() writeexcel.close()
... View more
05-25-2016
08:02 AM
|
0
|
0
|
1137
|
|
POST
|
I have looked at many regarding csv writer, yet I am not successful yet.
... View more
05-24-2016
01:31 PM
|
0
|
4
|
2876
|
|
POST
|
I am still working on trying to get the csv to write. You know about readlines and writelines? I just leaned of these, yet I haven't noticed anyone mentioning this option, ever.
... View more
05-23-2016
01:36 PM
|
0
|
7
|
2876
|
|
POST
|
I am going with csv instead, so I can share the script not worrying whether a person may or may not have openpyxl. Csv should suffice, but I am having a little trouble. I have the following and can see the csv file in windows explorer processing/looping the files, but when I open the csv it has one file just repeated in several rows. You know what may be the cause? with open('CSVLISTLAYERS.csv', 'wb') as outputcsv: writer = csv.writer(outputcsv, dialect = 'excel') for filename in (fullpath + lyr_source): writer.writerow ([fullpath + lyr_source])
... View more
05-19-2016
10:52 AM
|
0
|
1
|
2876
|
|
POST
|
I have tried write to csv also, but it seems that openpyxl is more versatile, e.g. write to a native xlsx . I will see what works out for me and let you know.
... View more
05-17-2016
12:12 PM
|
0
|
2
|
2876
|
|
POST
|
This is what worked for me. I used only what I needed and added openpyxl so I can write to excel. Yet I am still working on it successfully writing to excel #Import Modules import arcpy,os from openpyxl import Workbook #Set folder space folder = xxxxx #Set variables # create excel worksheets wb = Workbook() ws1 = wb.create_sheet("yyy") 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": arcpy.AddMessage("Processing: " + basename) mxd = arcpy.mapping.MapDocument(fullpath) dfs = arcpy.mapping.ListDataFrames(mxd) for df in dfs: arcpy.AddMessage("DataFrame: " + df.name) layers = arcpy.mapping.ListLayers(mxd, "", df) for layer in layers: if layer.isFeatureLayer: lyr_source = layer.dataSource lyr_name = layer.name.encode("utf8", "replace") arcpy.AddMessage("Copying: {}".format(lyr_name)) print fullpath + lyr_source wb.save('aaaaaaa.xlsx') Thank you for your help. My next step is the openpyxl writing to excel.
... View more
05-17-2016
09:52 AM
|
1
|
1
|
2876
|
|
POST
|
The following code prints out the data I want for a specified mxd. I want to iterate every mxd in a specified folderpath and return the layers. Any idea how to do this ? import arcpy,os folderPath = (xxxxxx) mxd = arcpy.mapping.MapDocument (xxxx) layers = arcpy.mapping.ListLayers (mxd) for layer in layers: if layer.supports("dataSource"): print layer.dataSource del mxd
... View more
05-13-2016
03:07 PM
|
0
|
2
|
3222
|
|
POST
|
Thank you, I will take a look and parse only what I need. Which is the most difficult part, there are examples and suggestions that I wish only had just what I needed.
... View more
05-13-2016
07:03 AM
|
0
|
0
|
3222
|
|
POST
|
I went ahead and did as you suggested. I opened and parsed the syntax to attempt in getting only what I need. No luck in successfully creating a script for what I want. I apologize for taking up your time. You have been more than helpful. I don't know what I cant seem to get this right to loop all mxds.
... View more
05-10-2016
01:19 PM
|
0
|
0
|
2767
|
| 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
|