Select to view content in your preferred language

Custom ToolBar with custom commands and menus

3038
10
09-11-2013 12:33 AM
A_Kipfer
Emerging Contributor
Hi,

I need to create a custom toolbar programmatically and add custom commands / menus to it. The whole toolbar needs to be persistent and be handed over to other people.

In the last weeks I was fuzzing around with .NET and IToolBardef, BaseCommand, ICommandItem and what not but I just couldn't add the custom commands to the toolbar, just standard ESRI-commands would work.

Can you please tell me, if I can use Python Scripting for this and is it possible to start Python scripts from xaml-Dialogs? I know there are a couple of Python tutorials around but before I invest a lot of time again I'd like to know if Python scripting is basically the right approach to fulfill my tasks.

Thanks a lot in advance for your help!

Edit: Sorry, I forgot to mention that I use VS 2010 with .NET3.5 for ArcGIS 10.0 and higher.

Kianar
Tags (2)
0 Kudos
10 Replies
DuncanHornby
MVP Notable Contributor
Kianar,

What are you tasks? If it is using existing tools then python could be a solution. If you are doing serious number crunching then may be ArcObjects is the way. If you want fancy user interfaces then ArcObjects is what you need using VB/c# .net

With the release of 10.1 ESRI created the Python Addin, this allows you to use your python coding skills with arcpy and create tool bars with buttons that can interact with the map. Have a look here.

I've had a play with this and you can use all that is arcpy but you still cannot create an interface, although some python expert will hopefully tell me otherwise!

Duncan
0 Kudos
A_Kipfer
Emerging Contributor
Hello Horbydd,

thanks for your reply. My tasks are described in the first paragraph of my last post.

Did I understand you right, that I can't use Python to create custom Toolbars with custom menus / commands for ArcMap 10.0?
Thanks for the link but as I said, I need to create the Toolbar programmatically notby using a wizard.

Regards
Kianar


Kianar,

What are you tasks? If it is using existing tools then python could be a solution. If you are doing serious number crunching then may be ArcObjects is the way. If you want fancy user interfaces then ArcObjects is what you need using VB/c# .net

With the release of 10.1 ESRI created the Python Addin, this allows you to use your python coding skills with arcpy and create tool bars with buttons that can interact with the map. Have a look here.

I've had a play with this and you can use all that is arcpy but you still cannot create an interface, although some python expert will hopefully tell me otherwise!

Duncan
0 Kudos
DuncanHornby
MVP Notable Contributor
Correct Python AddIns only appeared in 10.1 so do not exist in 10.0

You say your tasks are to create toolbars with commands/menu but you don't say what these will actually do, this is what I was trying to get at? Are you intending to do complex fine grain manipulation of geometries (then ArcObjects is the way to go) or call upon existing geo-processing tools to improve a workflow (then may be python is your answer)?

Why can't you use the addin wizard? With this you create the toolbar and controls, attach your code and then you have an addin which can be easily installed and distributed.
0 Kudos
A_Kipfer
Emerging Contributor
Hornbydd, thanks for your time...

I don't necessarily need a Python Addin, I need to write code to let a user define a custom Toolbar with custom commands and menus on the fly and make them persistent. What those commands and menus are supposed to do is currently not so important. The problem is, that I can't seem to create them otherwise and would like to know if I can create the Toolbars with Python.

Hope, this makes it clearer.

Regards
Kianar


Correct Python AddIns only appeared in 10.1 so do not exist in 10.0

You say your tasks are to create toolbars with commands/menu but you don't say what these will actually do, this is what I was trying to get at? Are you intending to do complex fine grain manipulation of geometries (then ArcObjects is the way to go) or call upon existing geo-processing tools to improve a workflow (then may be python is your answer)?

Why can't you use the addin wizard? With this you create the toolbar and controls, attach your code and then you have an addin which can be easily installed and distributed.
0 Kudos
DuncanHornby
MVP Notable Contributor
You say "...let a user define a custom Toolbar with custom commands and menus on the fly and make them persistent".

Is that not what the desktop menu option customize > customize mode all about? This allows the user to create a toolbar, drag any existing tool onto it and have their own customized toolbar? Look here on customizing a map document.
0 Kudos
JamesCrandall
MVP Frequent Contributor
Hornbydd, thanks for your time...

I don't necessarily need a Python Addin, I need to write code to let a user define a custom Toolbar with custom commands and menus on the fly and make them persistent. What those commands and menus are supposed to do is currently not so important. The problem is, that I can't seem to create them otherwise and would like to know if I can create the Toolbars with Python.

Hope, this makes it clearer.

Regards
Kianar


Your most appropriate options are:

1. COM/ArcObjects Components
2. .NET Add-In

Without knowing what kind of functionality you plan to build, I'd say any significant map interaction should be handled with ArcObjects as the Python mapping library simply is not that extensive and will limit your options.  But as Hornbydd  alludes to, it depends on the functionality you plan to provide.

The biggest difference between the two options listed above I think resides with getting your tools distributed.  I don't have experience with the .NET Add-in, but from what I understand it affords much more UI development tools than the Python Add-In does, but is more limited than a full-blown COM component. 

The .NET Add-In has the advantage of easy distribution, while the COM/ArcObjects tools will need to have Installer.msi/.exe component and must be run to get your tools installed on the end-user's workstation.

I can assure you that  IToolBardef, BaseCommand, ICommandItem all work fine and you simply need to do more research and testing to get it to work.
0 Kudos
A_Kipfer
Emerging Contributor
Hi Hornbydd,

right, but with ArcGIS 10.0 (or 10.1, I'm not sure) the custom toolbars get stored in the Normal.mxd and no longer in single mxd-files which makes it hard to share the toolbar with others and that is exactly what I need.


You say "...let a user define a custom Toolbar with custom commands and menus on the fly and make them persistent".

Is that not what the desktop menu option customize > customize mode all about? This allows the user to create a toolbar, drag any existing tool onto it and have their own customized toolbar? Look here on customizing a map document.
0 Kudos
DuncanHornby
MVP Notable Contributor
You can store custom tool bars in an mxd created via the menu option customize > customize mode route and then say distribute an mxd. You need to go to menu option customize > customize mode > Options tab and click on "Save all customizations to the document". This is something that appeared in 10.0.
0 Kudos
A_Kipfer
Emerging Contributor
Hornbydd,

thanks a lot for your hint, I'll check this out!

Regards
Kianar


You can store custom tool bars in an mxd created via the menu option customize > customize mode route and then say distribute an mxd. You need to go to menu option customize > customize mode > Options tab and click on "Save all customizations to the document". This is something that appeared in 10.0.
0 Kudos