|
POST
|
I'm getting an error that says: "Index Error: list index out of range' Any ideas? I don't know how to do it besides using raw_inputs? and I also don't know how to have an alternative scenario if they type the wrong file name, apologies for my ignorance, I'm very new to Python. Maybe have a look at some great resources in the ESRI library to get you started: http://resources.arcgis.com/en/help/main/10.1/index.html#/A_quick_tour_of_creating_custom_tools/001500000001000000/ I picked this because it appears you need to start by making a choice between developing with Model Builder or jump into creating Toolbox components. Entirely up to you. Sorry I don't have a direct answer to your OP.
... View more
07-24-2013
11:59 AM
|
0
|
0
|
2137
|
|
POST
|
1. What exactly is the problem you are having? error? nothing happens? 2. This doesn't look right (maybe it is, but I have never set a workspace like this): arcpy.env.workspace = out_path = Workspace 3. Why raw input? What if they type in an incorrect path or raster? Seems like this is much better suited for a Toolbox that you can add input parameters for the individual rasters and the workspace itself.
... View more
07-24-2013
11:23 AM
|
0
|
0
|
2137
|
|
POST
|
James, you are the man. You deserve a nice cold beer. I greatly appreciate all of your guidance. BCPAO -- Is that acronym for Broward Co Property Appraiser Office? If so, you can send the beer up to west palm beach just north of ya 🙂 Glad to help. j
... View more
07-23-2013
12:04 PM
|
0
|
0
|
1463
|
|
POST
|
James, After much frustration, I was finally able to convert some of my tools to buttons. Back, to the initial part of my search. Can you provide an example string that would ask the user to provide their name? I would like to have the value entered directly into a field in the attribute table. Or at least point in the correct direction with which function to use. Thanks again. So, if your Add-In successfully launches/opens the correct BCPAO.tbx component... In your "NameDate" BCPAO.tbx Toolbox, add a new paramter and set it as String. At the top of this NameDate.py, set a variable to this parameter: inputName = arcpy.GetParameter(0) Now you can use this variable in an updateCursor on your set of selected features (that's a whole other thread! 🙂
... View more
07-23-2013
11:44 AM
|
0
|
0
|
4322
|
|
POST
|
I've successfully created a raster using FocalStatisitics:
smoothed = arcpy.sa.FocalStatistics('input', neighborhood, "MEAN","NODATA")
smoothed.save('output.tif')
Problem: The problem is that when I try to delete the 'output.tif' file within Python, I get the following error: The problem also occurs in an interactive Python session - the file cannot be deleted by Windows Explorer until the PythonWin is closed. I assume the problem is that FocalStatistics did not close the file it created. How can I delete 'output.tif' within Python? I am new to arcpy so I may be missing something obvious. Or I wonder if a with statement would be appropriate? (not sure if this would work, it is NOT tested), but it should handle the termination for you (from what I've read anyway):
with arcpy.sa.FocalStatistics('input', neighborhood, "MEAN","NODATA") as smoothed:
smoothed.save('output.tif')
(someone please correct this if it is wrong. Sorry OP for not testing this, just a quick thought that might work as expected).
... View more
07-23-2013
11:12 AM
|
0
|
0
|
1055
|
|
POST
|
I double checked the toolbox path and it is fine. I included the latest suggestion, to add the message. Nothing. I have the toolbar name, but no picture or button name. Then there is something wrong with the building/registering the add-in steps. Soooo frustrating!
... View more
07-23-2013
07:38 AM
|
0
|
0
|
2859
|
|
POST
|
Welcome to the club. I struggled to get the add-in to work as intended (most of my dev work was with ArcObjects/COM components with installers). To test to see if the actual button click event is getting fired, just try to present a message box
import arcpy
import pythonaddins
class UpdatesDates_Name(object):
"""Implementation for UpdatesDates_Name.button (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
msg = "The click event worked!"
pythonaddins.MessageBox(msg, 'Just a test', 0)
Edit/Addition: if the msg pops up okay, then I'd guess there is an issue with the path to your toolbox or something. Maybe use the UNC path if it is on a network location (that's what we do anyway, because not everyone I distribute will have the same letter'ed mapped drives).
... View more
07-23-2013
07:09 AM
|
0
|
0
|
2859
|
|
POST
|
James, Logically, this seems like a long way around. Why create a button to call a toolbox? Why not just use the script in the toolbox? I will give it a shot and see if it works though. I am not try to come off as ungrateful or rude. I am new to python and scripting and I am just trying to gain some more knowledge and understanding. Thanks. Not rude at all. The reason is because the toolbox needs to be launched in some manner -- the user can just access the Toolbox in the integrated ArcCatalog tree and I think that is just fine of an option. But the Add-In allows for some user interaction FIRST with the map itself (which is what I thought you needed) --- the problem is that there are no real good options for GUI development with the add-in. So, I just "use" the Toolbox as my User Interface and launch it from the Python Add-in as I suggested. For example, what if you want the user to draw a polygon (an add-in tool) on the map that performs a SelectByLocation, then immediately after it finishes it selection, you want a GUI to popup that can present the user to input some information and save that info to the features that were selected by the tool? I don't see how you can do this with just a Toolbox. I mean, sure, you could just force the user to make some selections with the default Select Features tool, then just have them manually double-click your toolbox tool. But that is what seems like a long way around! The idea for creating an Add-In is to aggregate your tools into a single, unique toolbar that you can distribute to your users. Hope that makes sense!
... View more
07-23-2013
06:25 AM
|
0
|
0
|
2859
|
|
POST
|
I'd have the Python Add-In with a button. Just configure the OnClick event of this add-in to launch your toolbox that has a string input parameter.
import pythonaddins
class ButtonClass_Button_1(object):
"""Implementation for MyAddin_addin.button_1 (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
pythonaddins.GPToolDialog('C:\MyToolboxFoler\MyCustomToolbox.tbx', 'MyScriptTool')
This MyScriptTool you reference would open and present the user the ability to enter in the string parameter. Clicking the Ok button would run the SelectFeatures and zoom to selected code that you'd place in it.
... View more
07-23-2013
05:44 AM
|
0
|
0
|
2859
|
|
POST
|
The pass function was included in the initial Python_addin.py. import arcpy
import pythonaddins
class ParcelSearch(object):
"""Implementation for Python_addin.btn1 (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
pass I removed the pass function and the result was still the same. If I used the SelectLayerByAttribute_management in my initial script, should the Python_addin use the same function? Since, the Python_addin I am running calls for the ZoomtoSelectedFeatures? What I was suggesting was for you keep all of the code you had for the OnClick event, but simply just remove the pass argument at the bottom. That is all. I know it automatically has it in there for each method/def when you generate the add-in for the first time. It is up to you to determine which event to use, add the appropriate code and get the add-in installed. It is going to be very difficult for me to work thru the rest as there are so many little things to get done on the add-in --- you might have to rebuild and re-install it after you complete edits. I really don't know why it is not zooming to selected and is something you might have to trial-and-error your way through it.
... View more
07-22-2013
07:59 AM
|
0
|
0
|
688
|
|
POST
|
I see a "pass" in there at the end --- you should only have that in the def/methods that you do not want to implement. Not sure if that should be there or if it would have any effect, but I'd go ahead and remove it and see if the tool works then.
... View more
07-22-2013
07:26 AM
|
0
|
0
|
2500
|
|
POST
|
Thanks. I will need to read up on Python add-ins. With the add-in, will I still need to figure out the scripting part? Or will the add-in allow a GUI? It depends on the type of Add-In. If it is a Python Add-In, then your GUI options are quite limited. I think if you have Visual Studio and build your user interfaces there, then this type of Add-In can extend your options quite a bit. I've not gone thru the later myself, I have built a ton of COM objects/extension in ArcObjects complete with package installers, but have not had a chance to check out the add-in model. My experience with the Python Add-in implementations has been with mixed feelings. You get lots of restrictions placed on you for the GUI-side, but I love the Geoprocessing (scripting) for speeding up the development time compared to building your own ArcObjects. What I am suggesting is that we have used an extra Geoprocessing tool that simply acts as a GUI to collect user input by launching it from a Python Add-In. That is, the add-in allows you to create the toolbar, with some ways to 'do stuff', then you can launch another toolbox that is merely a user interface or/and includes the geoprocessing that you need to get done.
... View more
07-22-2013
05:48 AM
|
0
|
0
|
2500
|
|
POST
|
First is to build the Add-In: http://resources.arcgis.com/en/help/main/10.1/index.html#//014p00000025000000 Then, code the click event to open the Toolbox you create that accepts the Name and Date parameters and peforms the updates. That is, build tat Toolbox and launch it from your add-in like so:
pythonaddins.GPToolDialog(r'C:\Documents\MyToolbox.tbx', 'AttributeEditor')"""
... View more
07-19-2013
11:38 AM
|
0
|
0
|
2500
|
|
POST
|
All, I am attempting to write a Python Script that selects a record in the attribute table, zooms to the selected feature, and prompts the user to enter their name, date created, and date modified. The name, date created, and date modified fields already exist in the attribute table. The name field is a string type, and the date fields are date types. I have the first part of the script written, it prompts the user to enter a RENUM value, which selects a record in the Parcels attribute table, and zooms to the selected feature. How would I get the script to prompt the user to enter their name, date created, and date modified? Then, have the information they enter stored in the attribute table? I am going to have the users run the script from ArcToolbox. Any suggestions would be welcomed. Thanks. What I have so far is displayed below: #Import
import arcpy
#Variables
Parcels = arcpy.GetParameterAsText(0)
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr = arcpy.mapping.ListLayers(mxd, "Parcels", df)[0]
arcpy.AddMessage(lyr.name)
#Logic
try:
whereClause = "RENUM = "+Parcels+""
arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", whereClause)
df.extent = lyr.getSelectedExtent()
df.scale = df.scale*1.1
except:
print arcpy.GetMessages() One pattern that may work is to implement a Python Add-In that allows for some user interaction, opens another Toolbox dialog that accepts the Name and date parameters and peform the update to the attribute table of ths selected features. I know that is a very general outline, but this is something that we have done and it works fine.
... View more
07-19-2013
11:23 AM
|
0
|
0
|
2500
|
|
POST
|
Hi jamesfreddyc, thanks for your reply, the insertCursor-function is not the time killer. the function arcpy.Polyline() is fast fithout the Parameter "has_z" for example: Synatx = Polyline (inputs, {spatial_reference}, {has_z}, {has_m}) polyline = arcpy.Polyline(array) #this one is fast as expected polyline = arcpy.Polyline(array, <none>, True, False) #this one is very very very slow Okay, perhaps this is the issue: http://resources.arcgis.com/en/help/main/10.1/index.html#//018w0000000t000000 "...When using InsertCursor on a point feature class, creating a PointGeometry and setting it to the SHAPE@ token is a comparatively expensive operation. Instead, define the point feature using tokens such as SHAPE@XY, SHAPE@Z, and SHAPE@M for faster, more efficient access." I will look for an example of setting SHAPE@Z
... View more
07-19-2013
04:31 AM
|
0
|
0
|
1046
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-17-2020 10:47 AM | |
| 1 | 10-25-2022 11:46 AM | |
| 1 | 08-08-2022 01:40 PM | |
| 1 | 02-15-2019 08:21 AM | |
| 2 | 08-14-2023 07:14 AM |
| Online Status |
Offline
|
| Date Last Visited |
01-22-2025
02:28 PM
|