Create reference plane from selected Face

Create reference plane from selected Face

zzhiweii
Explorer Explorer
951 Views
7 Replies
Message 1 of 8

Create reference plane from selected Face

zzhiweii
Explorer
Explorer

Hi can some one help create this macro I found on Youtube?

 

ReferencePlaneByFace - Simply select any face and it will create a Plane. If the face in not a Planar Face then the face will be evaluated where selected and create a plane tangent to the point you picked.

 

https://www.youtube.com/watch?v=jgw_il1YRfg

0 Likes
Accepted solutions (2)
952 Views
7 Replies
Replies (7)
Message 2 of 8

Mohamed_Arshad
Advisor
Advisor

HI @zzhiweii 
  

     You need to create plane for non planar face ?


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 3 of 8

zzhiweii
Explorer
Explorer

Nope I just need plane from face. Thanks!

0 Likes
Message 4 of 8

Mohamed_Arshad
Advisor
Advisor
Accepted solution

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)

0 Likes
Message 5 of 8

zzhiweii
Explorer
Explorer
Hi Arshard,

I really appreciate your help but I've encountered an error message, I'm using Revit 2020

Build started.
Compiling ZW
C:\ProgramData\Autodesk\Revit\Macros\2020\Revit\AppHookup\ZW\Source\ZW\ThisApplication.cs(41,34) : Error CS1061: 'Autodesk.Revit.ApplicationServices.Application' does not contain a definition for 'ActiveUIDocument' and no extension method 'ActiveUIDocument' accepting a first argument of type 'Autodesk.Revit.ApplicationServices.Application' could be found (are you missing a using directive or an assembly reference?)
Build failed. (00:00:01.5581340)

0 Likes
Message 6 of 8

zzhiweii
Explorer
Explorer

zzhiweii_0-1710827836905.png

 

0 Likes
Message 7 of 8

zzhiweii
Explorer
Explorer
Thanks much Arshad! I'm able to make it to work by editing it from
UIDocument uiDoc= Application.ActiveUIDocument;
to
UIDocument uiDoc= ActiveUIDocument;
Message 8 of 8

Mohamed_Arshad
Advisor
Advisor
Accepted solution

HI @zzhiweii 

 

    you have create Application Macro instead of Document. Kindly follow steps shown in below gif Image

 

Manage Tab --> MarcoManager ---> Choose Second Tab (It is in Project Name)

 

Reference GIF

Macro Manager.gif

 

Hope this will Helps 🙂


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes