SketchEditScopeStartWithNewSketch Method |
Starts a sketch edit mode for an element which, at this moment, doesn't have a sketch.
Namespace: Autodesk.Revit.DBAssembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntaxpublic void StartWithNewSketch(
ElementId elementId
)
Public Sub StartWithNewSketch (
elementId As ElementId
)
public:
void StartWithNewSketch(
ElementId^ elementId
)
member StartWithNewSketch :
elementId : ElementId -> unit
Parameters
- elementId ElementId
-
The Element without sketch to be edited.
ExceptionsException | Condition |
---|
ArgumentException |
The ElementId elementId already has a sketch defined.
-or-
Element does not support sketch editing.
-or-
Failed to start the sketch edit mode.
|
ArgumentNullException |
A non-optional argument was null
|
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.
|
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.
ExampleDocument document = commandData.Application.ActiveUIDocument.Document;
AnalyticalPanel analyticalPanel = CreateAnalyticalPanel.CreateAMPanel(document);
if (analyticalPanel != null)
{
SketchEditScope sketchEditScope = new SketchEditScope(document, "Replace line with an arc");
sketchEditScope.StartWithNewSketch(analyticalPanel.Id);
using (Transaction transaction = new Transaction(document, "Modify sketch"))
{
transaction.Start();
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;
}
}
}
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)));
document.Delete(line.Reference.ElementId);
document.Create.NewModelCurve(arc, sketch.SketchPlane);
transaction.Commit();
}
sketchEditScope.Commit(new FailurePreproccessor());
}
return Result.Succeeded;
See Also