Toolbox to toolbar

533
9
04-15-2019 10:21 AM
Highlighted
New Contributor II

Is it possible to add all my toolbox tools to a toolbar ribbon in arcpro?

Reply
0 Kudos
9 Replies
Highlighted
Esri Regular Contributor

Hi Laura

Yes, Tools can be added to a Toolbar on the Pro ribbon.

You can define which tools/buttons you want on the toolbar using this piece of code in your config.daml:

 <toolbars>
<toolbar id="TestToolbar">
<group>
<button refID="ArcProToolbar_ButtonOnToolbar" />
<tool refID="ArcProToolbar_MyMapTool"></tool>
<tool refID="ArcProToolbar_MyConstructionTool1"></tool>
</group>
</toolbar>
</toolbars>

And then you add the toolbar using its refID to the group and the tab like this:

      <tabs>
<tab id="ArcProToolbar_Tab1" caption="New Tab">
<group refID="ArcProToolbar_Group1" />
</tab>
</tabs>
<groups>
<!-- comment this out if you have no controls on the Addin tab to avoid
an empty group-->

<group id="ArcProToolbar_Group1" caption="Group 1" appearsOnAddInTab="false">
<!-- host controls within groups -->
<toolbar refID="TestToolbar" />
</group>
</groups>

The RibbonControls sample has a toolbar in it.

Thanks

Uma

Highlighted
New Contributor II

HI Uma,

Are you talking about the config.daml in visual studio when opening that sample?

Reply
0 Kudos
Highlighted
Esri Regular Contributor

Yes. If you check out line 150 in the config.daml in this sample, it shows how to add toolbars to the ribbon. 

Reply
0 Kudos
Highlighted
New Contributor II

also I am a little lost on how I connect it to a tool in a toolbox.

Reply
0 Kudos
Highlighted
Esri Regular Contributor

Hi

To run a specific GP Tool using the Pro API, you can call the ExecuteToolAsync method.  There are some samples available that will walk you through this:

Sample that uses a GP Tool.

Some more code snippets that runs GP Tools

If you need to open a specific GP Tool dialog using code, you can do something like this:

string input_data = @"C:\data\data.gdb\Population";
string out_pdf = @"C:\temp\Reports.pdf";
string field_name = "INCOME";
// use defaults for other parameters - no need to pass any value
var arguments = Geoprocessing.MakeValueArray(input_data, out_pdf, field_name);

string toolpath = @"C:\data\WorkflowTools.tbx\MakeHistogram";

Geoprocessing.OpenToolDialog(toolpath, args);

You can use the Pro SDK Item templates and create a button item in a Pro add-in. The OnClick event stubbed out for you via the template is where you would add code to access/run a specific GP tool.

This button can then be displayed directly on the Pro ribbon or you can add them to a "toolbar" on the Pro ribbon.

Thanks

Uma

Reply
0 Kudos
Highlighted
New Contributor II

but that geoprocessing tool isn't using python or arctoolbox? I tried the callsriptfromnet one but could never get it to run my tool. I'm sorry I'm pretty frustrated and would love any help and below is the python tool I would like to run.

Reply
0 Kudos
Highlighted
Esri Regular Contributor

Hi Laura

In Pro, you can Insert a new Toolbox into your project and then add your script tool (test1.py) to that toolbox. 

This help topic walks you through this: Use a custom geoprocessing tool

Also, this help topic has some information on how to structure the parameters in the script tool: https://pro.arcgis.com/en/pro-app/help/analysis/geoprocessing/basics/create-a-python-script-tool.htm

Once you have your custom tool included in Pro, you can run it manually using the UI, or using the Pro API.

Thanks

Uma

Reply
0 Kudos
Highlighted
New Contributor II

I know how to do all that but I would really like it run from a toolbar. Is this possible with that script? could you go over more of the steps for the ribbon one to work? or does it have to have the toolbox and be in catalog?

Reply
0 Kudos
Highlighted
Esri Regular Contributor

Hi Laura

Once you have your custom python tool in a toolbox in a Pro project, you can add it to a button on the Pro ribbon. So when you click the button, your tool will execute. I am assuming this is what you want to do.

The following details how to exactly accomplish this.

1. Using the Pro SDK, you will create an Add-in project in Visual Studio. This is a .NET project that allows you to extend the Pro UI with new buttons, etc.

2. You will add a Button item template to this add-in project using the Pro SDK.

3. The button class file created by the Pro SDK will have an OnClick method stubbed out for you. This is where you would add code to access/run a specific GP tool - in your case your custom python tool in the toolbox in Pro.

4. To run a GP tool using the .NET Pro API, you can use ExecuteToolAsync method or the Geoprocessing.OpenToolDialog method.  Code snippets for all this is available in this message trail above.

A useful link on how to get started with the Pro SDK is ProGuide: Build your first add in

Thanks

Uma

Reply
0 Kudos