POST
|
I know this is an old post, but I have just recently ran into this issue myself. I have developed a custom .Net Desktop Windows Form Application in VS 2010. The culprit for me was a Visual Basic PowerPack element I had added to my form. I was using a Rectangle Shape as a divider. Once I deleted this element I no longer had the error when I debugged my project. I used a label instead for my divider. This may not always be the case for everyone's project, but it solved my problem.
... View more
04-21-2014
07:32 AM
|
0
|
0
|
240
|
POST
|
This works for me with field names and values in the SelectLayerByAttribute_management tool. You will of course need to change the name of the fields and layer name to your own. import arcpy mxd = arcpy.mapping.MapDocument('CURRENT') arcpy.SelectLayerByAttribute_management("PARC+ADDR_all","NEW_SELECTION","C_MAP = '010N' AND Parcel_Num = 6") parcels = arcpy.mapping.ListLayers(mxd,"PARC+ADDR_all")[-1] df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0] df.extent=parcels.getSelectedExtent() df.zoomToSelectedFeatures() this also worked for me using your variable instead of field names. import arcpy mxd = arcpy.mapping.MapDocument('CURRENT') value = ' "Parcel_Num" = ' + str(6) arcpy.SelectLayerByAttribute_management("PARC+ADDR_all","NEW_SELECTION",value) parcels = arcpy.mapping.ListLayers(mxd,"PARC+ADDR_all")[-1] df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0] df.extent=parcels.getSelectedExtent() df.zoomToSelectedFeatures() Hope this helps or at least points you in the right direction.
... View more
12-09-2013
07:53 AM
|
0
|
0
|
918
|
POST
|
THANKS SO MUCH. That fixed it and your annotated script helped to. Glad to help. For future reference, the following code will zoom to a selected feature in any shapefile that is in the top dataframe. import arcpy mxd = arcpy.mapping.MapDocument('CURRENT') df = arcpy.mapping.ListDataFrames(mxd, "put name of top dataframe here")[0] df.zoomToSelectedFeatures() df.scale = df.scale * 1.1 arcpy.RefreshActiveView()
... View more
09-10-2010
10:53 AM
|
0
|
0
|
918
|
POST
|
Thanks for the response. I caught that after posting, thats not it. I tried changing that line a lot of ways and the error always changes to whatever I change the "variable" to as I tried substituing in different expressions for what df. extent = AttributeError: 'str' object has no attribute 'zoomToSelectedFeatures' AttributeError: 'str' object has no attribute 'Layer' AttributeError: 'str' object has no attribute 'section' AttributeError: 'str' object has no attribute 'selected' AttributeError: 'str' object has no attribute 'getSelectedExtent' Mike, I got this to work for me, fill in your dataframe name and shapefile name where indicated. Make sure map is open and a feature is selected. This zooms to selected feature. import arcpy mxd = arcpy.mapping.MapDocument('CURRENT') df = arcpy.mapping.ListDataFrames(mxd,"put name of top dataframe here")[0] Layer = (mxd, "put name of first shapefile in top dataframe here", df)[0] df.zoomToSelectedFeatures() arcpy.RefreshActiveView
... View more
09-10-2010
10:22 AM
|
0
|
0
|
918
|
POST
|
Could it be the layer in line 5 should be Layer. It's very case sensitive. df.zoomToSelectedFeatures(layer) change to: df.zoomToSelectedFeatures(Layer)
... View more
09-10-2010
09:14 AM
|
0
|
0
|
884
|
POST
|
Thanks so much for the help. The Make Feature Layer was the problem in the model. I removed it and all works well; my model with script runs great now. Appreciate the help.
... View more
07-22-2010
07:30 AM
|
0
|
0
|
884
|
POST
|
Good morning, thanks for the fast response. I am using Arcgis 10, the code works great in the python window. I can select a parcel with the select tool, or from the attribute table and the code in the python window works. I can also build an expression using the Select by Attributes in Arcmap and the code works in the python window. I have saved the code as a python script file. I can double click the script outside of the python window and it works great as well.The only time it doesn't zoom to the selected feature is when I add the script file to a geoprocess in model builder. It doesn't stop the process or give an error it just doesn't zoom to the selected feature. I can remove the script file from my model and run the process,and then double click the script file outside of the model and it will work, it just doesn't work within model builder.I have only one data frame and one shapefile added to the map doc. Code for zoom to selected script import arcpy mxd = arcpy.mapping.MapDocument('CURRENT') df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0] df.zoomToSelectedFeatures() arcpy.RefreshActiveView() I have attached an image of my simple model. Thanks for your help.
... View more
07-22-2010
06:23 AM
|
0
|
0
|
884
|
POST
|
I have the python script that will zoom to selected features. It works great outside of model builder, however; when I add the script to a model and connect it to the output of Select Layer By Attributes it doesn't work. The output is set as a precondition before the script runs. I don't receive any errors when I run the model, it just doesn't zoom to the selected features. Any insight to this problem would be helpful. Thanks
... View more
07-21-2010
09:26 AM
|
0
|
0
|
1365
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|