POST
|
Thanks, but I still do not understand the AddMessage issue. Why does specifying "Fields" using ListLayers not return the AddMessage and leaving the ListLayers as "" returns the AddMessage for all Feature Class selections, including "Fields"? lyr = arcpy.mapping.ListLayers(mxd, "Fields", df)[0] - Specifies "Fields" FC lyr = arcpy.mapping.ListLayers(mxd, "", df)[0] - Includes all Layers within TOC
... View more
10-16-2013
05:12 AM
|
0
|
0
|
671
|
POST
|
Perhaps try explicitly stating the false condition with an elif? for df in arcpy.mapping.ListDataFrames(mxd):
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
if lyr.name == "Fields":
df.extent = lyr.getSelectedExtent()
elif lyr.name != "Fields":
arcpy.AddMessage("Fields polygon not selected") Thanks for the suggestion. But, the AddMessage statement is returned when a "Fields" polygon is selected and when a polygon or polyline from another feature class is selected. The AddMessage statement is still returned 50 times. Changing the ListLayers from "" to "Fields" is the complete opposite. The AddMessage statement is not returned for "Fields" or for another selected Feature Class.
... View more
10-16-2013
03:40 AM
|
0
|
0
|
671
|
POST
|
I removed the redundant statement. I want to limit the selection to "Fields" or else return the AddMessage line. Otherwise, the zoom will work for all Feature Classes. My modified code now returns the AddMessage for when "Fields" are selected and when the are not. The script still zooms to selected "Fields" and zooms to full extent when other Feature Classes are selected. How can I get the Message to only return when a Feature Class other than "Fields" is selected? The message retuns approx 50 times. I just need one instance of the Message. for df in arcpy.mapping.ListDataFrames(mxd): for lyr in arcpy.mapping.ListLayers(mxd, "", df): if lyr.name == "Fields": df.extent = lyr.getSelectedExtent() else: arcpy.AddMessage("Fields polygon not selected")
... View more
10-15-2013
06:23 AM
|
0
|
0
|
671
|
POST
|
When a Fields polygon is selected the script zooms to the polygon extent. But, I want to return the AddMessage line if the correct Feature Class is not selected. The script does not get to the else statement for other Feature Classes. But, when another polygon or polyline Feature Class is selected it zooms to full extent, as expected. So, why does the script not use the else statement for Feature Classes other than Fields? fds = arcpy.mapping.ListLayers(mxd, "Fields", df)[0] for fds in arcpy.mapping.ListLayers(fds): desc = arcpy.Describe(fds) type = desc.shapeType if type == "Polygon": df.extent = fds.getSelectedExtent() else: arcpy.AddMessage("Fields polygon not selected")
... View more
10-15-2013
05:29 AM
|
0
|
9
|
792
|
POST
|
I have modified the suggestions provided to only zoom to one selected Feature Class. But, I want to return the AddMessage line if the correct Feature Class is not selected. The script does not get to the else statement for other Feature Classes. When a Fields polygon is selected, the script zooms to the polygon extent. But, when another polygon or polyline Feature Class is selected it zooms to full extent, as expected. So, why does the script not use the else statement for Feature Classes other than Fields? fds = arcpy.mapping.ListLayers(mxd, "Fields", df)[0]
for fds in arcpy.mapping.ListLayers(fds):
desc = arcpy.Describe(fds)
type = desc.shapeType
if type == "Polygon":
df.extent = fds.getSelectedExtent()
else:
arcpy.AddMessage("Fields polygon not selected")
... View more
10-15-2013
04:53 AM
|
0
|
0
|
268
|
POST
|
I have modified the suggestions provided to only zoom to one selected Feature Class. But, I want to return the AddMessage line if the correct Feature Class is not selected. The script does not get to the else statement for other Feature Classes. When a Fields polygon is selected, the script zooms to the polygon extent. But, when another polygon or polyline Feature Class is selected it zooms to full extent, as expected. So, why does the script not use the else statement for Feature Classes other than Fields? fds = arcpy.mapping.ListLayers(mxd, "Fields", df)[0] for fds in arcpy.mapping.ListLayers(fds): desc = arcpy.Describe(fds) type = desc.shapeType if type == "Polygon": df.extent = fds.getSelectedExtent() else: arcpy.AddMessage("Fields polygon not selected")
... View more
10-15-2013
04:35 AM
|
0
|
0
|
268
|
POST
|
rai = arcpy.mapping.ListLayers(mxd, "Railroads", df)[0]
EWmove = float(arcpy.GetParameter(0))
NSmove = float(arcpy.GetParameter(1))
def shift_features(in_features, EWmove=None, NSmove=None):
in_features = rai
point.X += EWmove
point.Y += NSmove
with arcpy.da.UpdateCursor(rai, ['SHAPE@XY']) as cursor:
for row in cursor:
cursor.updateRow([[row[0][0] + (EWmove or 0), row[0][1] + (NSmove or 0)]])
return
arcpy.RefreshActiveView()
shouldn't this be...
rai = arcpy.mapping.ListLayers(mxd, "Railroads", df)[0]
EWmove = float(arcpy.GetParameter(0))
NSmove = float(arcpy.GetParameter(1))
def shift_features(in_features, EWmove=None, NSmove=None):
rai = in_features
with arcpy.da.UpdateCursor(rai, ['SHAPE@XY']) as cursor:
for row in cursor:
cursor.updateRow([[row[0][0] + (EWmove), row[0][1] + (NSmove)]])
return
arcpy.RefreshActiveView()
Cheers, Neil Neither of these two approaches work. They both run with no results or errors. The other suggestion by Matt works. So, I am going to modify Matt's suggestion. I appreciate the help.
... View more
10-10-2013
11:37 AM
|
0
|
0
|
249
|
POST
|
What am I not seeing?
rai = arcpy.mapping.ListLayers(mxd, "Railroads", df)[0]
EWmove = float(arcpy.GetParameter(0))
NSmove = float(arcpy.GetParameter(1))
def shift_features(in_features, EWmove=None, NSmove=None):
in_features = rai
point.X += EWmove
point.Y += NSmove
with arcpy.da.UpdateCursor(rai, ['SHAPE@XY']) as cursor:
for row in cursor:
cursor.updateRow([[row[0][0] + (EWmove or 0), row[0][1] + (NSmove or 0)]])
return
arcpy.RefreshActiveView()
... View more
10-10-2013
07:47 AM
|
0
|
0
|
249
|
POST
|
I skipped the geometry section once the word point was listed. Since, I only intend to use Polylines, Polygons, and Annotations. Your suggestion works well for one Polyline. I am going to try and modify the script to work with multiple Polylines, Polygons, and Annotations(if possible). Thanks.
... View more
10-10-2013
07:00 AM
|
0
|
0
|
1325
|
POST
|
The script returns arcpy.AddMessage("Feature(s) not moved"). What am I doing incorrectly to move selected features? Railroads is a Polyline Feature Class. rai = arcpy.mapping.ListLayers(mxd, "Railroads", df)[0]
EW = arcpy.GetParameter(0)
NS = arcpy.GetParameter(1)
with arcpy.da.UpdateCursor(rai, ['OID@', 'SHAPE@X', 'SHAPE@Y']) as cursor:
EWmove = 0
NSmove = 0
for row in cursor:
if row[1] >= '0':
cursor.updateRow(row)
elif row[2] >= '0':
cursor.updateRow(row)
else:
arcpy.AddMessage("Feature(s) not moved")
... View more
10-10-2013
04:57 AM
|
0
|
0
|
1325
|
POST
|
Matt, Is this http://resources.arcgis.com/en/help/main/10.1/index.html#/Geometry/018z00000070000000/ the geometry information you suggested? If so, ESRI's example illustrates how to calculate geometry length. Where can I find information and script examples on how to move a selected feature?
... View more
10-09-2013
07:30 AM
|
0
|
0
|
1325
|
POST
|
Does Python provide a "short cut" approach other than using ListLayers? Otherwise, I will be typing out 50+ Feature Classes. Which is why I had hoped to be able to use use a generic, lyr = arcpy.mapping.ListLayers(mxd, df), and allow for any layer within the TOC to be selected and moved.
... View more
10-09-2013
04:16 AM
|
0
|
0
|
1325
|
POST
|
I am attempting to select features within ArcMap, run the script, and move the selected features by a distance entered. I am attempting to recreate the Editor Move Tool and the wheel. I read through the documentation; http://resources.arcgis.com/en/help/main/10.1/index.html#//01m80000000s000000. But, the documetation dos not provide a script example. I was thinking something along the lines of the following script. An attribute error exists on the line reading, ext = lyr.extent. I tried including a layer in the ListLayers function, but that did not solve the error. mxd = arcpy.mapping.MapDocument ("CURRENT") df = arcpy.mapping.ListDataFrames (mxd)[0] lyr = arcpy.mapping.ListLayers(mxd, df) EW = arcpy.GetParameter(0) NS = arcpy.GetParameter(1) #orig extent ext = lyr.extent #mods ext.XMin += EW ext.XMax += EW ext.YMin += NS ext.YMax += NS #new extent lyr.extent = ext
... View more
10-08-2013
11:16 AM
|
0
|
12
|
4578
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|