HI @zzhiweii
My first advice is to learn Revit API from the scratch, The Below links will help you out to learn Revit API. Because this forum will help you in solving queries but it wont' provide you the complete solution.
Revit API Learning Sites
https://thebuildingcoder.typepad.com/blog/2013/04/getting-started-with-the-revit-api.html
https://www.autodesk.com/autodesk-university/class/Revit-Programming-Beginners-Easily-Access-Revit-A...
https://www.autodesk.com/support/technical/article/caas/tsarticles/ts/7I2bC1zUr4VjJ3U31uM66K.html
Kindly refer the below script for Sketch Plane creation from face.
Reference Macro Script
public void CreatePlaneFromFace()
{
UIDocument uiDoc= Application.ActiveUIDocument;
Document doc= uiDoc.Document;
Reference faceRef = uiDoc.Selection.PickObject(ObjectType.Face);
GeometryObject geoObj = doc.GetElement(faceRef).GetGeometryObjectFromReference(faceRef);
if (geoObj is PlanarFace)
{
PlanarFace face = (PlanarFace)geoObj;
using (Transaction createSketchPlane = new Transaction(doc, "Create Sketch Plane"))
{
createSketchPlane.Start();
Plane planeGeo = Plane.CreateByNormalAndOrigin(face.FaceNormal, face.Origin);
SketchPlane skp = SketchPlane.Create(doc, planeGeo);
uiDoc.ActiveView.SketchPlane = skp;
doc.ActiveView.ShowActiveWorkPlane();
createSketchPlane.Commit();
}
}
}
Hope this will Helps 🙂
Mohamed Arshad K
Software Developer (CAD & BIM)