Custom sketch tool

4668
5
04-26-2016 07:05 AM
TedChapin
Occasional Contributor III


I want to create a tool that the user uses like an edit template's sketch tool.  I want to get geometry from the user that is not tied to a particular layer, just want the user to digitize a geometry using their snapping environment.  When they're done I want to use that geometry and do some things with it.  Is there an existing sketch tool that I can inherit from in my tool class or something?

0 Kudos
5 Replies
by Anonymous User
Not applicable

Hi Ted,

Short answer is yes, but i'll give you the long answer to spread the word.

The easiest way to create Pro tools is through the Visual Studio add new item wizard. Once you have the SDK installed you should see ArcGIS Pro Map Tool, ArcGIS Pro Sketch Tool and ArcGIS Pro Construction Tool as options under the ArcGIS\ArcGIS Pro add-ins category within the wizard.

The Map Tool is a base for many of the tools in Pro.

The Sketch Tool is simply a MapTool with the IsSketchTool property set to true. Once this is set along with the SketchType, the tool will behave like the editor's sketch tool with a sketch context menu. To use the snapping environment with the sketch tool set the UseSnapping property to true.

A Construction Tool is normally a sketch tool that has been registered to a particular geometry type, similar to how it works in ArcObjects, where the configuration is in config.daml. These tools will then appear under the appropriate editor template.

With all these tools you can return the sketch geometry through the OnSketchCompleteAsync method.

Take a look at the community samples for some examples of map and sketch tools, in the editing and map folders.

You can also review the MapTool concepts page in the help.

0 Kudos
TedChapin
Occasional Contributor III

Thanks Sean Jones​. So a sketch tool is just a modified map tool.  That's exactly what I was looking for.  My next step is to use the geometry to do some validation and create new features in 2 feature classes.  I am using the CreateRowBuffer, CreateRow, Store pattern and although it works, I can't figure out how to refresh the map.  I found the IEditContext.Invalidate in the ProConcepts editing page.  Looks like I shouold be wrapping my edits in an edit operation, but having trouble figuring how to implement this in VB. In that example (ProConcepts Editing · Esri/arcgis-pro-sdk Wiki · GitHub ) how do you pass the callback function arguments?

0 Kudos
by Anonymous User
Not applicable

Hi Ted,

There's a bit of misconception about when to use the callback method to make edits in Pro. Were in the process of cleaning up the help this week to make it a bit clearer.

Generally speaking, If your layers are in the project (in a map) then you should be using the other methods on EditOperation to perform the edits (create, modify, etc). The callback method was introduced to allow edits on geodatabase feature classes that weren't usually in a map.

The following example shows the OnSketchCompleteAsync method for a point sketch tool that creates a point feature with some attribute values:

    protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
    {
      //run on MCT
      return QueuedTask.Run(() =>
      {
        //find layer by name
        var rsLayer = MapView.Active.Map.FindLayers("Ranger stations").FirstOrDefault() as FeatureLayer;
        //set some attributes via a dictionary (field name, value)
        var atts = new Dictionary<string, object>();
        atts.Add("Shape", geometry);
        atts.Add("Location", "Redlands");
        //create and execute the EditOperation
        var op = new EditOperation();
        op.Name = "Create feature with attributes";
        op.Create(rsLayer, atts);
        op.Execute();
        return op.IsSucceeded;
      });
    }

In the example im using the Create method to create a feature in the layer with a dictionary. If I didn't care about the attributes I could have used the other create methods to create the feature using just the layer and accepting the layer default attributes; or a feature template with its default attributes. Using this pattern, Pro looks after the layer refresh. And yes, all edits should be encapsulated within an editoperation to keep Pro in sync.

0 Kudos
TedChapin
Occasional Contributor III

Sean Jones​ Thank you, that is exactly what I was looking for.  You wouldn't believe the path I was going down.  I had a button that activated the layer's edit template, so the users could make their sketch and listened for OnRowCreated.  Then  I validated the feature and if it failed (using the sketch geometry, if it didn't connect to the right things) I used args.Row.delete to prevent the feature from getting saved.  That was working, until I needed to use the sketch geometry to create features in other layers as well.  Then I started the RowBuffer, Row, Store pattern.  Way too granular.  EditOperation.Create with a layer and a dictionary is much more concise.  And I like that you can Execute or ExecuteAsync.  For just adding a single simple feature to a layer in the map it doesn't seem worth the async plumbing.

I'm glad you're continuing to work on the documentation.  Often what I want is in the API reference, but I don't know where.  The concepts doc should tell you what pattern you should be using and guide you to the API reference for the syntax to implement that pattern.  Not a big fan of the GitHub wiki.  I wish the Pro SDK docs were more like this: ArcGIS API for JavaScript  or this:What is ArcPy?—Help | ArcGIS for Desktop

And more VB code samples please!

0 Kudos
by Anonymous User
Not applicable

Yeah were seeing some interesting coding patterns out there which prompted the doc review.

Thanks for the feedback.

0 Kudos