Hello
I am trying to achieve a functionality where a user can copy a geometry to the clipboard, and then paste this geometry into a an existing feature layer with the correct geometry-type using "Paste special".
However I am really struggling to find a solution to this. I have found the ClipboardItem class in the API, however I am not sure how I can copy a geometry to the clipboard as an geometry object or feature object.
If there is anyone here who have gotten this to work, I would be very happy to get some pointers.
Thanks a bunch for your time
Tor
Solved! Go to Solution.
Sorry for the delay. I attached a copy/paste sample project to this reply. As @GKmieliauskas mentioned there is no published ArcGIS Pro standard on copy/paste published (instead all copy/paste handling is custom), so you have to implement your own copy/paste handlers in your Module class. The attached sample implements the paste part since i encountered some issues with intercepting the copy (and cancopy) actions, which we will try to address this in an upcoming release of ArcGIS Pro. However, i think you can still use the attached sample to get your desired workflow done. The same has a readme.md included which describes the usage. But in summary the sample allows the operator to create a geometry, then select the destination layer (which could be determined through a TOC selection or other means) and then use the ArcGIS Pro built-in Paste button to paste the geometry into the destination layer.
Hi,
I think you need to serialize geometry to text first (xml, json) and then using Clipboard.SetText(geometry.ToJson()) put it to the clipboard.
At the other end to get shape from clipboard use sample code below (for points):
string geometryText = Clipboard.GetText();
MapPoint point = MapPointBuilder.FromJson(geometryText);
Hello there,
Thank you for the response!
Could you elaborate on what you mean by "the other end"? Is there an clipboard-event or some other class that I need to register this MapPoint to, so that the "Paste Special" command will be activated in ArcGis Pro?
What I have achieved in my Addin so far is getting a WKT geometry from a webrequest, then building this into a PolyLine and adding this to the graphic overlay. The next functionality I want to add is for the user to copy this PolyLine to the clipboard so the user can paste it into a layer of choice using "Paste special".
Hi,
I mean, that in the other place of your code you can read clipboard value, which you have added. You can develop add-ins button with implementing "Paste spatial" and add it to the ArcGIS Pro ribbon/toolbar/group, which you want.
If you want what ArcGIS Pro could read your clipboard content, you need to know clipboard content format. Try to copy selected feature from ArcGIS Pro to clipboard. Then from your created addin button try to investigate current clipboard content. Clipboard class has many different methods to read clipboard content.
Some links to help you:
https://learn.microsoft.com/en-us/dotnet/api/system.windows.clipboard?view=windowsdesktop-7.0
Copy and paste using the clipboard—ArcGIS Pro | Documentation
Thank you for the reply.
I watched the clipboard-content and got a step further, but I will be going through Wolf's sample to see how I can solve my challenge.
Sorry for the delay. I attached a copy/paste sample project to this reply. As @GKmieliauskas mentioned there is no published ArcGIS Pro standard on copy/paste published (instead all copy/paste handling is custom), so you have to implement your own copy/paste handlers in your Module class. The attached sample implements the paste part since i encountered some issues with intercepting the copy (and cancopy) actions, which we will try to address this in an upcoming release of ArcGIS Pro. However, i think you can still use the attached sample to get your desired workflow done. The same has a readme.md included which describes the usage. But in summary the sample allows the operator to create a geometry, then select the destination layer (which could be determined through a TOC selection or other means) and then use the ArcGIS Pro built-in Paste button to paste the geometry into the destination layer.
Hi Wolf!
This looks like a good solution to my problem so far. Thank you for taking your time to make a sample for me and giving a thorough explanation. Having easy access to the copy/paste-functionality would be really sweet seeing that beeing able to easy store results straight into a target layer of choice is applicable in loads of use cases.
And seeing as ArcGis Pro already have a nice workflow for "Paste special" already, it would be nice to be able to access that further down the road without to much hassle.
I've also hit a snag with inspecting the addin-sample you sent over. I get an error-message in the "Add-in Manager" that the addin targets version 3.1 of ArcGis Pro when I run it in debug-mode. Is there some settings I have overlooked?
UPDATE: I found out how to fix this last issue, so no worries. Again, thanks a bunch for the sample and reply.
kind regards
Tor R Børset
Hello,
as far as I can see (v. 3.1.2) there are still issues trying to intercept the copy: I encountered the same problem in my project, basicly the overriden CopyAsync() is never hit and I cannot set the copied geometry in order to trigger the workflow showed in @Wolf's sample. Of course the scenario is quite different, the sample allows the user to draw a geometry and then paste it in the chosen layer. This looks like a special case of a more generic scenario where you just want copy an existing gemetry and paste it in another layer.
My workflow is actually more like that: I would like to intercept the copy event and handle a custom paste operation which the user can setup on the UI. I don't want to expose the stock clipboard commands (with the 'Paste Special' button) because we need to keep control on a number of customized aspects. In other words, I would like to achieve the same workflow as the sample, but the copy operation should be availble on already existing and selected objects, following some custom contraints in order to be enabled.
Anyone knows whether there are some news about accessing and managing clipboard actions in order to achieve something like this?
As a side note, I still don't totally get the supposed usage of the clipboard events: if I read the 'remarks' section on documentation, I can understand there is something about their logic I'm missing ("they defer their logic to active window first and if this object returns false, they then consult each currently loaded module"), but I cannot find more detailed informations to clear my gap, and I'm not sure if I am missing something or if there is an actual bug preventing them to fire sometimes.