Saturday 4 February 2017

arcmap - Customizing right click (context) menu of selected feature using ArcPy?



I want to confirm whether arcpy can customize the right click menu of the selected feature, which means I want to remove the default items and add in my own item. The following pictures show what I want to do:


(1) picture 1 - the default when right click a selected feature


enter image description here


(2) - picture 2 - what I want when right click a selected feature


enter image description here



Answer



Unfortunately, this type of modifications is not accessible via Python (arcpy or python add-ins). I believe you can change this with ArcObjects though. I recommend looking at ArcGIS Add-in, here is a good 10.1 sample to start with.


The closest you can get is to create a Python add-in button on a toolbar which user can click on when having selected a feature. This triggers opening a custom window (wxPython for instance) or web browser window or a .pdf file or alike.


EDIT: I have just found out that you actually can modify the look of the right-click menu (apart from dozens of other menus) in ArcGIS. Customize menu > Customize Mode > Toolbars tab > Tick Context Menus > in the Context Menus toolbar click drop-down list > go to Data View Context Menu. Then you can drag and drop to this list what items you want to have (and delete existing ones if you don't need them). Esri Help page on that is here.


So, in order to get your workflow working on a user machine, you need two things. First, you have to supply the configuration file for the customization (it is called the template file, Normal.mxt, stored C:\Users\user\AppData\Roaming\ESRI\Desktop10.2\ArcMap\Templates. Here the customization outlook is preserved). I believe the context menus customization should follow just like any other customization of toolbars. Second, you will need to build a custom tool (I'd go for Python Add-in, but I guess script tool which has an output format of .pdf file would work too). This tool will search for a selected feature in the current map, identify the file document associated with it based on some ID and then fire up the .pdf reader or other application for document interaction.



enter image description here


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...