Select to view content in your preferred language

Draw a rectangle by dragging

4559
11
01-25-2013 01:17 PM
babakkasraei
Emerging Contributor
Hi Experts

How can I draw a rectangle on my map by clicking and dragging my cursor click using python codes?

Best Regards
Babak
Tags (2)
0 Kudos
11 Replies
KimOllivier
Honored Contributor
You change the draw symbol by defining a layer with the symbol you need and use that as the schema in the parameter property.
Using a tool at the start is the only way before 10.1 to interactively draw a box with python scripting unless you use .NET and ArcObjects.

I have no idea how you are using TKinter inside your script, so I cannot help you further. I have used TKinter for some forms and feedback, but not to interact with the map page. I have already mentioned that the TKinter message queue is not the same as the ArcMap queue.

For a much better interactive experience, use the 10.1 AddIns that allow you to have interactive control of the mouse from inside a python tool. You can have buttons in an AddIn that initiate dragging a box, in fact the Esri example in the help is exactly that.
AddIns
To make an AddIn you have to download the AddIn Wizard, program up a loop that watches for windows events, and responds to them. Event based programming is very different from the batch style programming used in the geoprocessing tools. Once the scripts have been written correctly and tested for syntax errors, they have to be assembled into a folder of resources and installed. Then you must restart ArcMap to test the AddIn. For any script edits you have to close down ArcMap and repeat the compilation and installation, and then re-open ArcMap. It is fairly difficult and tedious to debug. That is why I suggested you abandon Tkinter and get the rectangle first using an easy-to-program geoprocessing tool.

If you want a robust and reliable process in ArcMap with interaction using the mouse then use AddIns with Python or .NET and C#.
0 Kudos
babakkasraei
Emerging Contributor
Thank you Kim

Your help was really important for me.

Drawing a shape before running the tool is OK. I go for other buttons.

Best regards

Babak
0 Kudos