In some workflows, where you wish to use to the PickPoint() method to prompt users to pick a point, you might get an error stating “No work plane set in current view”.
To be able to use the PickObject() method, as the exception mentioned, we might need to create a workplane using the API. For that, we can use the active view’s origin and view’s right direction to create a plane which is then used to create a new sketch plane. This sketch plane is then assigned to the current view’s sketch plane property and now we can safely pick a point on the active workplane. The following complete code illustrates the steps.
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.HelloRevit.CS
{
[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
public Result Execute(ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiApp = commandData.Application;
UIDocument uiDoc = uiApp.ActiveUIDocument;
Transaction transaction =
new Transaction(uiDoc.Document, "WorkPlane");
transaction.Start();
Plane plane =
new Plane(
uiDoc.Document.ActiveView.ViewDirection,
uiDoc.Document.ActiveView.Origin);
SketchPlane sp = uiDoc.Document.Create.NewSketchPlane(plane);
uiDoc.Document.ActiveView.SketchPlane = sp;
uiDoc.Document.ActiveView.ShowActiveWorkPlane();
transaction.Commit();
return Result.Succeeded;
}
}
}
<p>The above provided code can also help in general, whenever you have the need to create a work plane for the active view.

Leave a Reply to vidyaCancel reply