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.
public class Command : IExternalCommand
public Result Execute(ExternalCommandData commandData,
ref string message,
UIApplication uiApp = commandData.Application;
UIDocument uiDoc = uiApp.ActiveUIDocument;
Transaction transaction =
new Transaction(uiDoc.Document, "WorkPlane");
Plane plane =
SketchPlane sp = uiDoc.Document.Create.NewSketchPlane(plane);
uiDoc.Document.ActiveView.SketchPlane = sp;
The above provided code can also help in general, whenever you have the need to create a work plane for the active view.