16

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 ...


14

If you are going to ArcMap 10.1 you could create a python add-in. The add-in gives you access to an "on open" function that will run code when you open the mxd. The help here explains how to create one and has a sample that adds a base layer to the mxd when opening.


11

You can use the builtin reload function in python to automatically reload your module. What you can do is something like this: import mymodule def hook(): reload(mymodule) mymodule.myfunction() 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 ...


11

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.


9

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 ...


8

Per @blah238's suggestion, the following script closes ArcMap (if open) creates Add-in installs Add-in silently re-opens ArcMap document Save to directory containing makeaddin.py: import os #Location of ESRIRegAddIn.exe esri = "C:/Program Files (x86)/Common Files/ArcGIS/bin/ESRIRegAddIn.exe" cwd = os.getcwd() mapdoc = <path to mxd> #Close ...


8

I also use Eclipse with PyDev as my main Python editor for arcpy and non-arcpy scripts. If I decide to develop Python Add-ins in 10.1, I will probably just use NTFS symbolic links so that the file in the .py file in the Add-in folder is just a symbolic link to the actual .py file in my Eclipse folder. This is like a shortcut, but is seamless because it's ...


8

Parallel processing is easier 'shown than done.' In the case of stuffing this all into a button, I'm guessing two issues: Multiple threads block the ArcMap UI thread, or ArcMap puts its own schema lock on the data source and doesn't permit the python process access to the data. Hmm looking further issue has been documented here in an ArcGIS Resources page. ...


8

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 = ...


8

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 ...


7

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.


7

The pythonaddins module has a function to do just this, GetSelectedTOCLayerOrDataFrame(): >>> import pythonaddins >>> sel = pythonaddins.GetSelectedTOCLayerOrDataFrame() >>> print sel Exported_Data >>>


7

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.


6

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, ...


6

No. Python Add-Ins are only usable in the desktop ArcGIS applications (ArcMap, ArcCatalog, etc.).


6

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 ...


6

Yes you can, you could do it by adding a global variable that keeps track of your clicks. For example: class ToolClass2(object): """Implementation for Test_addin.tool (Tool)""" def __init__(self): self.enabled = True self.shape = "NONE" global clickCount clickCount = 0 def onMouseDownMap(self, x, y, button, shift): global clickCount ...


6

You will need to edit your config.xml and add: separator="true" 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....


6

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: ...


6

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 ...


5

@BMac's code also crashes my ArcMap 10.1 SP1 installation. This code works properly however: import arcpy import pythonaddins import webbrowser from threading import Thread def OpenBrowserURL(): url = 'http://www.google.com' webbrowser.open(url,new=2) class OpenWebBrowserButtonClass(object): """Implementation for WebBrowserAddIn....


5

You could code within the VBA of the mxd and call the python script within the code wrapper below: Private Function MxDocument_OpenDocument() As Boolean End Function


5

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 file. Python Add-ins, however, are not part of the map itself, but instead extensions to the ArcMap ...


5

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 ...


5

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 ...


5

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 ...


5

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: def onClick(self): mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping....


5

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. if focused: self.mxd = arcpy.mapping.MapDocument('current') ...


5

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.


5

There is property isBroken - Returns True if a layer's data source is broken. for layer in arcpy.mapping.ListLayers(mxd, "*", df): if layer.isBroken: arcpy.mapping.RemoveLayer(df, layer) Link to Esri help


Only top voted, non community-wiki answers of a minimum length are eligible