Starts a sketch edit mode for an element which, at this moment, doesn't have a sketch.
Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 23.0.0.0 (23.1.0.0)
Since: 2023
Syntax
C# |
---|
|
Visual Basic |
---|
|
Visual C++ |
---|
|
Parameters
- elementId
- Type: Autodesk.Revit.DB ElementId
The Element without sketch to be edited.
Remarks
Some surface Revit elements (like some Walls or some Analytical Elements) does not have a valid sketch all the time so in order to edit them, we have to create a valid sketch first. The application will need to start a transaction to actually make changes to the element. SketchEditScope can only be started when there is no transaction active, thus it does not work for commands running in automatic transaction mode.
Examples

Document document = commandData.Application.ActiveUIDocument.Document;
//create analytical panel
AnalyticalPanel analyticalPanel = CreateAnalyticalPanel.CreateAMPanel(document);
if (analyticalPanel != null)
{
// Start a sketch edit scope
SketchEditScope sketchEditScope = new SketchEditScope(document, "Replace line with an arc");
sketchEditScope.StartWithNewSketch(analyticalPanel.Id);
using (Transaction transaction = new Transaction(document, "Modify sketch"))
{
transaction.Start();
//replace a boundary line with an arc
Line line = null;
Sketch sketch = document.GetElement(analyticalPanel.SketchId) as Sketch;
if (sketch != null)
{
foreach (CurveArray curveArray in sketch.Profile)
{
foreach (Curve curve in curveArray)
{
line = curve as Line;
if (line != null)
{
break;
}
}
if (line != null)
{
break;
}
}
}
// 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 FailurePreproccessor());
}
return Result.Succeeded;
Exceptions
Exception | Condition |
---|---|
Autodesk.Revit.Exceptions ArgumentException | The ElementId elementId already has a sketch defined. -or- Element does not support sketch editing. -or- Failed to start the sketch edit mode. |
Autodesk.Revit.Exceptions ArgumentNullException | A non-optional argument was null |
Autodesk.Revit.Exceptions InvalidOperationException | This SketchEditScope is not permitted to start at this moment for one of the following possible reasons: The document is in read-only state, or the document is currently modifiable, or there already is another edit mode active in the document. -or- Cannot create sketch. |