How can I send a coordinate to the active "Create feature" tool

1024
7
07-14-2017 07:02 AM
MauricioTerneus
New Contributor II

In ArcMap 10.5 I could send points to the editor like so:

IEditor3 editor = ArcMap.Editor as IEditor3;
editor.SendPoint(worldPoint, true);

Is there any way to accomplish the same thing with the ArcGIS Pro SDK?

I see plenty of snippets for creating new edit operations, but I want to pass coordinates to the users active tool.

0 Kudos
7 Replies
MauricioTerneus
New Contributor II

Basically trying to get the same functionality as the "Absolute X,Y,Z" feature when sketching (Specify an x,y,z location—ArcGIS Pro | ArcGIS Desktop ).. I want to be able to specify a coordinate and pass it to the active sketch

0 Kudos
CharlesMacleod
Esri Regular Contributor

Mauricio, can you take a look at these samples and see if they are doing what you want to do:

https://github.com/esri/arcgis-pro-sdk-community-samples/tree/master/Editing/SketchToolDemo - implements a MapTool that shows use of the "OnSketchModifiedAsync" event to retrieve the sketch using GetCurrentSketchAsync. There is also a corresponding set method to alter the geometry of the sketch(which I think is what you are after).

https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Editing/ReplaceSketch shows modifying the sketch by accessing the sketch directly off the MapView itself in a button click (rather than implementing a map tool and using its protected methods as above) - see http://pro.arcgis.com/en/pro-app/sdk/api-reference/#topic11944.html  and scroll down to the extension methods section.

0 Kudos
MauricioTerneus
New Contributor II

Hi Charles,

Thanks for the response.

I have been playing around with both GetCurrentSketch and SetCurrentSketch, however there is a few problems.

First, If i am in the place polyline sketch mode and have only placed 1 vertex, the sketch geometry returned by " GetCurrentSketchAsync" returns with no points in the Points array... so there is no way to get the coordinate of the initial point that starts the polyline unless a whole segment is plotted.

Also, not sure what I would do if I want to place points.

            QueuedTask.Run(async () =>
            {
                Geometry sketchGeom = await MapView.Active.GetCurrentSketchAsync();
                if (sketchGeom.GeometryType != GeometryType.Polyline)
                    return;

                
                //get the sketch as a point collection
                var pointCol = ((Multipart)sketchGeom).Points;
                
                if (pointCol.Count > 0 || ((Multipart)sketchGeom).PartCount > 0)
                {
                    Polyline polyline = sketchGeom as Polyline;

                    //get the last point in the sketch based on its geometry type  
                    // Crash because no points in the poly line... 
                    var lastSketchPoint = pointCol[(sketchGeom.GeometryType == GeometryType.Polygon) ? pointCol.Count - 2 : pointCol.Count - 1];

                    
                    using (PolylineBuilder pb = new PolylineBuilder(polyline))
                    {
                        try
                        {
                            LineBuilder lb = new LineBuilder(lastSketchPoint.Coordinate3D, ((MapPoint) worldPoint).Coordinate3D);
                            pb.AddSegment(lb);
                            await MapView.Active.SetCurrentSketchAsync(pb.ToGeometry());
                        } catch (Exception ex)
                        {

                        }

                    }
                } else
                {
                    // Starts a new polyline.
                    var sketchPolyline = new PolylineBuilder(new[] { ((MapPoint)worldPoint).Coordinate3D });
                    await MapView.Active.SetCurrentSketchAsync(sketchPolyline.ToGeometry());
                }

            });
0 Kudos
CharlesMacleod
Esri Regular Contributor

Hi Mauricio, thanks for that, this is a bug. If I create the polyline from scratch (with the builder) with a single point it works (I get a polyline with a PointCount of 1). However, the sketch from the viewer has a point count of 0 after I have digitized the first vertex. We will fix for 2.1.

MauricioTerneus
New Contributor II

Charles,

Any ideas when that will be released?

Is there any other alternatives for sending the coordinate to the active sketch?  How is the Absolute XYZ tool doing it?

Thanks,

Maury

0 Kudos
CharlesMacleod
Esri Regular Contributor

Any ideas when that will be released?<< December

Is there any other alternatives for sending the coordinate to the active sketch?  How is the Absolute XYZ tool doing it?<<

I assume you are asking about alternatives for getting the point that was digitized as the first vertex of a single point polyline? Modifying the sketch polyline and reapplying to the sketch using SetCurrentSketchAsync is the correct approach when the returned polyline is valid.

If snapping is not an issue, you can retrieve the point that was digitized for the vertex via OnToolMouseDown(MapViewMouseButtonEventArgs e). The e.ClientPoint can be converted via mapView.ClientToMap. If snapping is an issue there is no suitable workaround (to getting the initial point for a single point polyline/line sketch type). Absolute XYZ is using an internal (native) API call.

0 Kudos
MauricioTerneus
New Contributor II

Charles,

Sorry, let me clarify what I am trying to do to make sure we are talking about the same bug, and to verify that what I am trying to do wont be possible until after 2.1

I am not working in a MapTool so using the OnToolMouseDown is not an option. 

We have developed our own 3rd party map that runs in a docked pane. This map is unique to my plugin and has no connection to esri\arcgis at all.  What I am trying to do is allow the user to click in my 3rd party map and send that 3d coordinate to the active sketch tool in ArcGIS.. Snapping is irrelevant.. also keep in mind that this is not done in a MapTool, but rather whenever the user clicks on the 3rd party(Not ESRI) map inside of my docked pane.

If the active sketch tool is a polyline, it needs to insert a vertex.. If the active sketch tool is a point, it would plot a point.


We accomplished this in arcmap 10.5 very easily by using this:

IEditor3 editor = ArcMap.Editor as IEditor3;
editor.SendPoint(worldPoint, true);

It sounds like with ArcGIS Pro I need to grab the current sketch, check what type of element it is, modify it accordingly, and set the modified version as the active sketch.

That is what I had attempted with the code I posted above (currently only polyline support), but as I mentioned, the point would not appear in the points property of the geometry unless there were at least 2 points in the polyline regardless of whether or not the initial point was created by the PolylineBuilder or manually through the esri Map.

 

Hopefully an easier method can be created to mimic what was possible with 10.5, if not, I look forward to the 2.1 release. If you can think of anything else, please let me know

Thanks for your time and hope that was more clear!

Maury