SketchEditScope Class

A SketchEditScope allows an application to create and maintain an editing session for a Sketch.
Inheritance Hierarchy
SystemObject
  Autodesk.Revit.DBEditScope
    Autodesk.Revit.DBSketchEditScope

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntax
public class SketchEditScope : EditScope

The SketchEditScope type exposes the following members.

Constructors
 NameDescription
Public methodSketchEditScope Instantiates a SketchEditScope object.
Top
Properties
 NameDescription
Public propertyIsActive Tells if the EditScope is active. In other words, the EditScope has started but not committed/canceled yet.
(Inherited from EditScope)
Public propertyIsPermitted Tells if the edit scope is permitted to start.
(Inherited from EditScope)
Public propertyIsValidObject Specifies whether the .NET object represents a valid Revit entity.
(Inherited from EditScope)
Top
Methods
 NameDescription
Public methodCancel Cancels the edit scope.
(Inherited from EditScope)
Public methodCommit Finishes the edit scope.
(Inherited from EditScope)
Public methodDispose
(Inherited from EditScope)
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Public methodIsElementWithoutSketch Validates if an element can have a sketch but currently does not.
Public methodIsSketchEditingSupported Checks whether sketch can be edited.
Public methodIsSketchEditingSupportedForSketchBasedElement Checks whether the element supports sketch editing.
Public methodStart Starts a sketch edit mode.
Public methodCode exampleStartWithNewSketch Starts a sketch edit mode for an element which, at this moment, doesn't have a sketch.
Public methodToStringReturns a string that represents the current object.
(Inherited from Object)
Top
Remarks
Start/end of a SketchEditScope will start/end a transaction group. After a SketchEditScope is started, an application can start transactions and edit the sketch. Individual transactions the application creates inside SketchEditScope will not appear in the undo menu. All transactions committed during the edit mode will be merged into a single one which will bear the given name passed into SketchEditScope constructor.
Example
C#
public void ReplaceBoundaryLine(Document document)
{
   FilteredElementCollector floorCollector = new FilteredElementCollector(document)
      .WhereElementIsNotElementType()
      .OfCategory(BuiltInCategory.OST_Floors).OfClass(typeof(Floor));

   Floor floor = floorCollector.FirstOrDefault() as Floor;
   if (floor == null)
   {
      TaskDialog.Show("Error", "Document does not contain a floor.");
      return;
   }

   Sketch sketch = document.GetElement(floor.SketchId) as Sketch;

   Line line = null;
   foreach (CurveArray curveArray in sketch.Profile)
   {
      foreach (Curve curve in curveArray)
      {
         line = curve as Line;
         if (line != null)
         {
            break;
         }
      }
      if (line != null)
      {
         break;
      }
   }

   if (line == null)
   {
      TaskDialog.Show("Error", "Sketch does not contain a straight line.");
      return;
   }

   // Start a sketch edit scope
   SketchEditScope sketchEditScope = new SketchEditScope(document, "Replace line with an arc");
   sketchEditScope.Start(sketch.Id);

   using (Transaction transaction = new Transaction(document, "Modify sketch"))
   {
      transaction.Start();

      // Create arc
      XYZ normal = line.Direction.CrossProduct(XYZ.BasisZ).Normalize().Negate();
      XYZ middle = line.GetEndPoint(0).Add(line.Direction.Multiply(line.Length / 2));
      Curve arc = Arc.Create(line.GetEndPoint(0), line.GetEndPoint(1), middle.Add(normal.Multiply(20)));

      // Remove element referenced by the found line. 
      document.Delete(line.Reference.ElementId);

      // Model curve creation automatically puts the curve into the sketch, if sketch edit scope is running.
      document.Create.NewModelCurve(arc, sketch.SketchPlane);

      transaction.Commit();
   }

   sketchEditScope.Commit(new FailuresPreprocessor());
}
C#
public void ReplaceBoundaryLine(Document document)
{
   FilteredElementCollector floorCollector = new FilteredElementCollector(document)
      .WhereElementIsNotElementType()
      .OfCategory(BuiltInCategory.OST_Floors).OfClass(typeof(Floor));

   Floor floor = floorCollector.FirstOrDefault() as Floor;
   if (floor == null)
   {
      TaskDialog.Show("Error", "Document does not contain a floor.");
      return;
   }

   Sketch sketch = document.GetElement(floor.SketchId) as Sketch;

   Line line = null;
   foreach (CurveArray curveArray in sketch.Profile)
   {
      foreach (Curve curve in curveArray)
      {
         line = curve as Line;
         if (line != null)
         {
            break;
         }
      }
      if (line != null)
      {
         break;
      }
   }

   if (line == null)
   {
      TaskDialog.Show("Error", "Sketch does not contain a straight line.");
      return;
   }

   // Start a sketch edit scope
   SketchEditScope sketchEditScope = new SketchEditScope(document, "Replace line with an arc");
   sketchEditScope.Start(sketch.Id);

   using (Transaction transaction = new Transaction(document, "Modify sketch"))
   {
      transaction.Start();

      // Create arc
      XYZ normal = line.Direction.CrossProduct(XYZ.BasisZ).Normalize().Negate();
      XYZ middle = line.GetEndPoint(0).Add(line.Direction.Multiply(line.Length / 2));
      Curve arc = Arc.Create(line.GetEndPoint(0), line.GetEndPoint(1), middle.Add(normal.Multiply(20)));

      // Remove element referenced by the found line. 
      document.Delete(line.Reference.ElementId);

      // Model curve creation automatically puts the curve into the sketch, if sketch edit scope is running.
      document.Create.NewModelCurve(arc, sketch.SketchPlane);

      transaction.Commit();
   }

   sketchEditScope.Commit(new FailuresPreprocessor());
}
See Also