|
POST
|
Your issue with the search cursor not being limited by the definition query on the layer is that you are not referencing the layer, you are referencing the data source feature class. This rows = arcpy.SearchCursor(mapLyr.dataSource, "PageID = \'Intersec\'") Should just be this rows = arcpy.SearchCursor(mapLyr, "PageID = \'Intersec\'")
... View more
08-19-2013
05:14 AM
|
0
|
0
|
1724
|
|
POST
|
I'm just thinking maybe the range function would apply here? Yes that's a nice method when you know the number of columns. Would need a slight tweak for odd numbers of rows. rowcount = 9
for rows in range(rowcount):
if rows in range(rowcount / 2 + 1):
print 'row ' + str(rows) + ' in range 1.'
elif rows in range(rowcount / 2, rowcount):
print 'row ' + str(rows) + ' in range 2.' There was also this for a tool that can take a dynamic number of text columns (as long as they are already created and follow the naming/number convention). import os
import arcpy
def main():
layer_name = arcpy.GetParameterAsText(0)
field = arcpy.GetParameterAsText(1)
number_columns = float(arcpy.GetParameterAsText(2))
mxd = arcpy.mapping.MapDocument("Current")
mapLyr = arcpy.mapping.ListLayers(mxd, layer_name)[0]
rowcount = int(arcpy.GetCount_management(layer_name).getOutput(0))
percolumn = round(rowcount / number_columns)
text_var = str()
item_count = 0
column_count = 1
for row in arcpy.SearchCursor(mapLyr.dataSource, sort_fields='{0} A'.format(field)):
text_var += '{0}{1}'.format(row.getValue(field), os.linesep)
item_count += 1
column = 'concat{0}'.format(column_count)
arcpy.AddMessage(item_count)
if item_count == percolumn and column_count != number_columns:
arcpy.AddMessage('next column')
arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", column)[0].text = text_var
text_var = str()
column_count += 1
item_count = 0
arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", column)[0].text = text_var
arcpy.RefreshActiveView()
mxd.save()
del mxd
arcpy.AddMessage("First column should have : {0} rows.".format(percolumn)) #used to check that it calculated properly
if __name__ == '__main__':
main()
... View more
08-15-2013
01:41 PM
|
0
|
0
|
1545
|
|
POST
|
If you want to split the items half between each text element you can add a counter and if statement to your cursor to only do half the rows as defined by your getcount method previously. I'm sure there is a better way of doing this but I just can't think of it right now. text_var = str()
count = 0
for row in rows:
if count < percolumn:
text_var += '{0}{1}'.format(row.getValue("CONCAT"), os.linesep)
count += 1
elif count == percolumn:
concat1Elem.text = text_var
text_var = str()
else:
text_var += '{0}{1}'.format(row.getValue("CONCAT"), os.linesep)
concat2Elem.text = text_var
... View more
08-15-2013
12:12 PM
|
0
|
0
|
2061
|
|
POST
|
There are a few ways you could go about it. You can create a string variable and insert as many row values as you want is one way. Here is an example of taking all values in the 'CONCAT' field. rows = arcpy.SearchCursor(mapLyr.dataSource)
text_var = str()
for row in rows:
text_var += '{0}{1}'.format(row.getValue("CONCAT"), os.linesep)
typeElem.text = text_var
... View more
08-14-2013
11:49 AM
|
0
|
0
|
2061
|
|
POST
|
Verified bug that has been fixed in 10.2. NIM076948 The arcpy.da.SearchCursor() where clause does not work with a table view Work around for 10.1 involved using a select by attribute on the layer with the where clause then running a cursor without a where clause. So editing the initial example that was broken. import arcpy data = r'D:\GIS\DataBase\misc.gdb\CLI_N' lyr = 'temp' arcpy.MakeFeatureLayer_management(data, lyr, 'OBJECTID < 100') print(arcpy.GetCount_management(lyr)) count = 0 arcpy.SelectLayerByAttribute_management(lyr, 'NEW_SELECTION', 'OBJECTID < 10') cursor = arcpy.da.SearchCursor(lyr, 'OBJECTID') for _ in cursor: count += 1 arcpy.SelectLayerByAttribute_management(lyr, 'CLEAR_SELECTION') print(count) Returns the appropriate. >>> 99 9 >>>
... View more
08-01-2013
11:49 AM
|
0
|
0
|
1338
|
|
POST
|
Initially, I was going to create a list, but then determined that I needed to update two fields. So, if I get help with the syntax, I can just recreate the for loop twice. Guess, I could have taken the list out. The suggested code is not working yet. So, I am going to go through my code and see if something else is missing. Are you getting an error message or is the script just not changing the values?
... View more
07-30-2013
08:00 AM
|
0
|
0
|
1548
|
|
POST
|
I'm not sure what you need a field list for when you are just changing one field with a known name. Here is how I would go about it. import arcpy
field = "RMS"
cursor = arcpy.da.UpdateCursor(fc, field, "{0} IS NULL".format(arcpy.AddFieldDelimiters(fc, field)))
for row in cursor:
row[0] = ""
cursor.updateRow(row)
del row, cursor
... View more
07-30-2013
07:03 AM
|
0
|
0
|
1548
|
|
POST
|
Ah that is because that tool requires two parameters, the path and the folder name separate. arcpy.CreateFolder_management("C:\\", str(val)) http://resources.arcgis.com/en/help/main/10.1/index.html#//0017000000pz000000 It would be easier to just use os.makedirs()
... View more
07-30-2013
05:54 AM
|
0
|
0
|
2248
|
|
POST
|
Str shouldn't be capitalized. Also string substitution would be the preferred method for these kinds of operations, which eliminates the need for the str operator at all. arcpy.CreateFolder_management("C:\\{0}".format(val) The way I create folders is using os.makedirs(). This creates all directories recursively if they do not exist which helps if you want to create folders where the parent folders may or may not exist.
... View more
07-30-2013
05:08 AM
|
0
|
0
|
2248
|
|
POST
|
I would highly appreciate of a python expert who writes a few lines script for me to solve this So basically you want someone to do your work for you? Have you even attempted to solve this problem on your own?
... View more
07-29-2013
09:13 AM
|
0
|
0
|
965
|
|
POST
|
Replace your entire loop with this. for row in cursor: row[0] = inputName cursor.updateRow(row) Hopefully you see where your code went wrong.
... View more
07-25-2013
04:59 AM
|
0
|
0
|
853
|
|
POST
|
A possible answer for the error you are getting on SO. http://stackoverflow.com/questions/16504975/error-unsupported-format-or-corrupt-file-expected-bof-record Double check your xlrd version and test on a simple xlsx file.
... View more
07-23-2013
02:25 PM
|
0
|
0
|
5903
|
|
POST
|
You've found a good workaround yourself. Creating a connection file is wholly independent from connecting to the database and you can't really test the connection until you create the connection file.
... View more
07-23-2013
07:35 AM
|
0
|
0
|
802
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 05-17-2011 10:36 AM | |
| 1 | 08-16-2012 10:48 AM | |
| 1 | 10-31-2012 08:39 AM | |
| 1 | 07-16-2012 01:52 PM | |
| 1 | 03-15-2012 10:57 AM |
| Online Status |
Offline
|
| Date Last Visited |
08-22-2024
11:12 PM
|