Visual Studio GP tool add-in closes data table view once process is complete

681
9
10-06-2022 07:04 AM
KThomasson
New Contributor III

I have a Visual Studio 2022 GP tool add-in that I have developed that works but once the processing is done to the standalone data table it closes out the data table view in the map, I have been able to make the button open said data table with the OnClick() event method which works, but once the tool is finished with it's process the table is closed, this is problematic and I need the table to stay visible for work personnel and ease of use.  I have been looking through documentation but I am not sure if using a GPexcuteTool is the way to go or if using a getStandaloneTable module in the Button is the way to go.  I would like the button to hold on to the table view and not close it out, anyways any advice that would get me in the right direction is appreciated.

0 Kudos
9 Replies
CharlesMacleod
Esri Regular Contributor

ExecuteToolAsync does not add behavior to a GP tool*. I'd recommend experimenting with the GP tool(s) via the UI to see if it can give u the behavior u want.  If "yes" then whatever parameters/options u have set should be replicated in your code. If "no" then ExecuteToolAsync likely wont be able to suppress the behavior.

*There are some GPExecuteToolFlags values which can be specified to control some aspects of GP behavior. These flags override any GP options set via the UI.

0 Kudos
KThomasson
New Contributor III

@CharlesMacleod  So when the process use to run in ArcMap it would leave the Standalone table view open with the added rows, but now it closes it in ArcGIS Pro, I am just calling the pyt file from my project in Visual Studio.  You said I should check to UI to get what behavior I desire to see, but where in the UI would that be. I was thinking that the Button1.cs would be it but are you saying I should look else where, like the Module or the config.daml?

0 Kudos
CharlesMacleod
Esri Regular Contributor

Go to the Analysis tab and open the Geoprocessing pane. From the Geoprocessing pane, select the tool and run it. Enter into/select on - the tool dialog whatever are the required parameters.

Run a Geoprocessing tool 

0 Kudos
KThomasson
New Contributor III

I mean that is the process that you would run a normal Geoprocessing tool, but when I run my custom GPtool  it still closes out the table view.  I can use the Append tool on a feature layer while the attribute table is open in the map and after that process has completed the table view does not close out from the map.  I am using Visual Studio 2022 to configure this functionality into the custom GPtool so it has the same behavior.

0 Kudos
KThomasson
New Contributor III

@CharlesMacleod So I tried the .py file that the .pyt file was created from and it worked without closing out the Attribute table view.  So I guess it must have something to do with using the .pyt file's function inside ArcGIS Pro.  I am not sure if this behavior can be programmed Visual Studio to automatically call open the standalone table after the GPtool is finished creating the new records inside the table, If you have any suggestions on the best method to do this in C # I would happy to have some advice.

0 Kudos
KThomasson
New Contributor III

I have found a thread where someone else was wanting to create and add a standalone Table using the C# in Visual Studio so I am going to try that and see if adding that to the .cs file will work, I will update as soon as I have something new.

0 Kudos
CharlesMacleod
Esri Regular Contributor

To create a standalone table programmatically u can use: StandaloneTableFactory.CreateStandaloneTable

It takes a StandaloneTableCreationParams instance as the parameter. There is a code snippet on the API ref page showing usage/workflow.

To add records via an addin, the best way is to use EditOeration.Create. There are lots of different overloads. I suspect that the one best suited for your purposes is this one: Create(MapMember, Dictionary). Pass in your standalone table instance along with a Dictionary of field names/attribute value keyvalue pairs. Any field that is missing from the Dictionary will be assumed to be null.

U can find lots more code examples here: https://github.com/esri/arcgis-pro-sdk/wiki/ProSnippets-Editing#edit-operation-create-features 

Although these arent specifically creating a table row in many cases, they will give u a very good idea of the EditOperation pattern of usage. Note: StandaloneTable instances derive from MapMember so any method that consumes a MapMember will also consume a StandaloneTable.

You can also read more on EditOperations in the Editor concepts doc.

 

 

0 Kudos
KThomasson
New Contributor III

Yes, this is what I was looking for @CharlesMacleod I had already passed the standalone table so that the button opens the table upon clicking the button so I was pretty much there I just need to do this again down after the initial process is complete thank you for providing this information.  I will eventually just code these old tools using C# in the future, again thanks for the help.

0 Kudos
KThomasson
New Contributor III

@CharlesMacleod I appreciate all the information you had provided me, but unfortunately I am dealing with a and Add-in that is referencing a .pyt file.  The function of the tool works fine, I am able to test the button that is added into ArcGIS Pro 3.0 but as soon as I set the parameter for  the tool and hit run the tool runs the process and adds the change but in the process it closes the table view in the map.  I was wondering if there is a way to prevent the table from closing?

Edit I should say that I think the reason the table closes in the first place is due to the .pyt file, because it has been altered from it' original ArcMap Python toolbox syntax.

0 Kudos