Arcpy Add - In tool, deselect tool?

1397
6
08-17-2016 05:01 PM
LukeWebb
Occasional Contributor III

I have an add-in tool created that works perfectly. Yehaw!

It takes your input selection, takes the tools rectangle_geometry, does a load of clever stuff, then clears the selection as work is complete.  Its time to make another selection, and use the tool to select your region again.,,,

But I cant find any way to de-activate the tool or set it back to the standard ArcMap select tool after its job is done? Please help!? Its very user unfriendly as if they click again now, it will complain about no selection being present!

I have tried using:

self.deactivate()      , but thats not an attribute of my tool :S

0 Kudos
6 Replies
DanPatterson_Retired
MVP Emeritus

Tool class—Help | ArcGIS for Desktop has a deactivate... or have I got the wrong tool type

0 Kudos
LukeWebb
Occasional Contributor III

Yes that is what I am using. I found this so it doesnt look hopeful:

https://community.esri.com/thread/88371 

Its a bit of a pain, I have now to decide whether to code my tool as a "Selector if nothing is selected, or the tool if so", or just leave it as is! Neither is the ideal solution.

DanPatterson_Retired
MVP Emeritus

as per John Dye's comment then... it is misleading at worst, but as described as best

0 Kudos
NobbirAhmed
Esri Regular Contributor

@Luke Webb, In your code add an "if" block to see if there is any selection - if yes then put your "takes the tools rectangle_geometry, does a load of clever stuff, then clears the selection as work is complete" code there. In the "else" block you can print a statement or pop-up a message window or do nothing - going ahead to use ArcMap's select tool to make a new selection and use the tool again. Your code may look like:

def onRectangle( .................):
    dsc = arcpy.Describe("layer_name")
    selection_set = dsc.FIDSet   # returns a list of selected feaures' IDs

    if selection_set:  # that means at least one feature is in selection set
        # do your stuff ...
        # ....
    else:   # no feature is selected
        # pop up a message dialog asking user to select some feature to use the tool
        pythonaddins.MessageBox("Please select some features to use the tool", 0)
        # or ... just skip this part
        pass

Note: the above code is typed in the browsed - there might be syntax error

0 Kudos
DanPatterson_Retired
MVP Emeritus

nahmed-esristaff‌ I 'syntax highlighted' it for you... check please

0 Kudos
NobbirAhmed
Esri Regular Contributor

The correct syntax for MessageBox is – I mistakenly left out ‘title’ ☹

MessageBox(message, title, )

0 Kudos