If an unhandled exception, such as an ImportError, occurs before the add-in classes are instantiated they will become unresponsive, be given a [Missing] label, and have a red symbol for their icon in the case of items on toolbars or in menus.
You can confirm whether an import error is happening by wrapping your import statement with an exception handler and ...
You can use the builtin reload function in python to automatically reload your module. What you can do is something like this:
where hook() is what's called by ArcMap and mymodule is the module you're editing between invocations. You may have to edit sys.path to include the path ...
Try unchecking the 'Add results of geoprocessing operations to the display' in the Geoprocessing Options in ArcMap.
You can also access this option via the addOutputsToMap property of the env class:
just add arcpy.env.addOutputsToMap = 0 in the beginning of your script.
To iterate over the layers in the map, get a reference to the current map document and list the layers within it:
mxd = arcpy.mapping.MapDocument("CURRENT")
layers = arcpy.mapping.ListLayers(mxd):
for layer in layers:
# do something with 'layer'
To just get the number of selected features, try leveraging the Describe object's fidSet property:
desc = ...
You can get the coordinates a mouse click via the onMouseDownMap() function of the Tool Class for Python add-ins.
The x and y values for onMouseDownMap and onMouseUpMap represent the map coordinates where the button was pressed or released.
Since you are already creating scripts in Python, it's not much more learning to implement this is an add-in. It's ...
An .esriaddin file is just a ZIP-compressed archive containing the files that make up your add-in. You can open it with something like 7-Zip to prove this to yourself. The Essential Python Add-in concepts article hints at this.
The layout of your-addin, including definitions of toolbars, menus and buttons, is all stored within the config.xml, whose syntax ...
As mentioned in the documentation, you can refer to other 'types' by using the appropriate ID.
This is what you set in the wizard when creating the combo-box, button, etc. and you can change it by editing the config.xml file in the root directory of your addin source.
A really simple example that clears a combo-box list when the user presses a button:
You can also deploy addins by copying the .esriaddin file to a network location and telling the addin manager to search this folder.
This location can be added to every PC in your organisation using group policy to set a registry key. See the last section of this page for more details.
The pythonaddins module has a function to do just this, GetSelectedTOCLayerOrDataFrame():
>>> import pythonaddins
>>> sel = pythonaddins.GetSelectedTOCLayerOrDataFrame()
>>> print sel
ArcGIS Code Sharing seems to be the site that you are looking for.
It claims to enable you to:
Search, browse, and use code, scripts, models, add-ins, widgets, and more.
There were 48 results when I searched there for Python AddIns just now.
Well here is a partial solution -- I don't see any way to access ArcMap's selection tolerance with arcpy, but if you want to pass in your own or just stick with the default of 3 pixels, this function will give you the map distance in inches by which to buffer or use as a search_distance with Select Layer by Location.
def getSearchDistanceInches(scale, ...
pythonaddins is limited in reporting and displaying attributes to users. pythonaddins is mainly a way to offer python developers a way to interact with user events. That being said the main mechanism for a developer to display messages to the user is through pythonaddins.MessageBox.
This function takes in a message formatted as a string as the first ...
Yes you can, you could do it by adding a global variable that keeps track of your clicks. For example:
"""Implementation for Test_addin.tool (Tool)"""
self.enabled = True
self.shape = "NONE"
clickCount = 0
def onMouseDownMap(self, x, y, button, shift):
You will need to edit your config.xml and add:
to the button that you want the separator to appear before, like I have done near the end of the line of code below:
<Toolbar caption="RJSS Toolbar" category="RJSS Addin" id="RJSS.toolbar" showInitially="true"><Items><Button refID="RJSS.button1" /><Button refID="RJSS....
Tkinter is not compatible with any version of Arcmap desktop. As a script you are running pure python, and not using the ArcMap desktop application at all, which is why you are seeing different behavior. Esri has determined that tkinter and Arcmap desktop conflict in their messaging designs and they will not resolve the conflict, so tkinter is not supported ...
No, you shouldn't expect Add-ins to be included in a Map Package. Here's the description from the documentation:
A map package contains a map document (.mxd) and the data referenced
by the layers it contains, packaged into one convenient, portable
Python Add-ins, however, are not part of the map itself, but instead extensions to the ArcMap ...
@BMac's code also crashes my ArcMap 10.1 SP1 installation.
This code works properly however:
from threading import Thread
url = 'http://www.google.com'
"""Implementation for WebBrowserAddIn....
Well I couldn't work out how to access the outputs of the script tool from the python addin, but i have achieved the next best thing which works for me. Which was to pass the list from the script in the script tool dialog to a list in the python add in tool.
By importing the python add in tool into the script for the script tool I was able to access the list ...
Any file included in the Install\ directory of your add-in project will be carried along in the Python add-in when you run makeaddin.py. You can include layer files or anything else really. You'll find the absolute path to them on disk via
path_to_layer = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'mylayer.lyr')
in your whatever_addin.py to ...
pythonaddins is limited in getting parameters directly from a user that are not associated with the table of contents as pythonaddins is mainly a way to offer python developers a way to interact with user events. That being said the main mechanism for a developer to get parameters from a user in the same way as arcpy.GetParameterAsText is through ...
It would be better to remove the layer using arcpy.mapping.RemoveLayer. The parameters are the data frame to remove the layer from (possibly a group layer if you are trying to remove from a group) and the layer itself, this alleviates any chance of confusion:
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping....
There is no property that defines the number of items that can be shown in the ComboBox. Instead, use the onFocus method to append the layers in the TOC to the drop-down list.
def onFocus(self, focused):
# When focused, update the combo box with the list of layer names.
self.mxd = arcpy.mapping.MapDocument('current')
If you already packed your addin to an .esriaddin-file (which is nothing but an archive-file similar to ZIP or others) all you have to do is copy the file to your client-PC and install it by double-clicking.
There is property isBroken - Returns True if a layer's data source is broken.
for layer in arcpy.mapping.ListLayers(mxd, "*", df):
Link to Esri help
I had this problem before.
There are two solutions:
You need to set the result of the geoprocessing tool "CreateFileGDB" as a variable using arcpy.getOutput method.
Another way to set the GDB variable is to use the OS module.
result = arcpy.CreateFileGDB_management(Project_Folder, "FFRA_WRRI.gdb")
Output_File_GDB = result.getOutput(0)
The documentation states:
Add-ins are not backward compatible. Add-ins targeting 10.1, for example, will not work with 10.0 but will work with 10.2.
Considering that ArcGIS 10.0 is old enough to have been Retired for nearly two years, and that the link you provided states that Python Add-ins were new at 10.1, it doesn't seem likely you'll find a way to ...
I think, It's most probably about Python GUI (especially Tkinter). Matplotlib uses Tkinter by default. I couldn't figure it out why, but If I change GUI package for matplotlib to PyQt4, no more crashing with one exception.
First, I tried wxPython, but I encountered errors. Then I installed PyQt4 (cp27m‑win32) and after some editings on script like below, ...
You will probably want to use onMouseDownMap rather than onMouseDown as this returns the location in map coordinates, not window coordinates.
Additionally, be sure to pass in a valid SpatialReference object to the PointGeometry constructor, otherwise it will most likely not work. In the example below I use the spatial reference of the active data frame.