ISketchTool: setting constraints doesn't work

854
4
04-07-2017 01:12 PM
ScottEckersall
New Contributor II

I created an Editor Extension and am listening to the OnSketchModified event.  Inside that, I have:

ISketchTool sketchTool = ArcMap.Editor.Parent.CurrentTool.Command as ISketchTool;
if (sketchTool == null)
    return;


double angle = 0.0;  //radians
sketchTool.Constraint = esriSketchConstraint.esriConstraintAngle;
sketchTool.AngleConstraint = angle;

When I create a Polygon feature, this all runs without error but the sketch is still unconstrained.

0 Kudos
4 Replies
by Anonymous User
Not applicable

In ArcMap 10+ you'll need to set the constraint on the current shape constructor.

      //get the editor
      var editorUid = new UID();
      editorUid.Value = "esriEditor.Editor";
      var editor = ArcMap.Application.FindExtensionByCLSID(editorUid) as IEditor;

      //get the edit sketch and set current constructor constraint
      var edSketch = editor as IEditSketch3;
      var constructor = edSketch.ShapeConstructor;
      constructor.Constraint = esriSketchConstraint.esriConstraintAngle;
      constructor.AngleConstraint = 45 * Math.PI / 180;

The constraint is only applied to the current segment.

You can create you own shape constructors with custom constraints if required.

0 Kudos
ScottEckersall
New Contributor II

Hi Sean... thank you so much for the really quick reply!  I implemented your code and it still isn't doing what I expect.  I must be missing some key concept here.  Once a user starts to draw a sketch, I want the sketch to be limited to 45 degrees, as if the user had just right-clicked and specified "45" for the Direction.  I wonder if I need to create my own ShapeConstructor, or is it possible to set the Constraint and AngleConstraint of the existing Polygon ShapeConstructor.  Again, no errors and code steps through just fine.

0 Kudos
by Anonymous User
Not applicable

Scott,

The example posted above was driven from a simple button on a toolbar. I would expect it to work through an extension and the sketch modified event, but I haven't tried that yet. A shape constructor is a more generic approach and avoids the overhead of an extension and filtering out the event for your polygon layer but the onus will be on the user to use it.

I'll try the extension approach today to see if there's any problems and probably bang out a 45° shape constructor and post here as an example. Its not exactly straight forward.

0 Kudos
by Anonymous User
Not applicable

I tried the extension approach and got the same result as you. Something in the display pipeline is eating the constraint. You can solve this by setting the constraint in IEditEvents3.BeforeDrawSketch instead of sketchmodified.

Ive also posted a right angle shape constructor as an example. This is modelled after the right angle shape constructor on the feature construction toolbar, which constrains the sketch 90 degrees from the previous segment. If you just want 45 degrees regardless of the previous segments you can just set that constraint there also.

0 Kudos