RevitPythonShell: Planes and Sketch Planes

<<< Return to Nathan's Revit API Notebook

Introduction

Planes and sketch planes are an essential component for operations such as drawing model curves. This section will describe two methods for creating planes and sketch planes.

Plane using World XYZ

This defines a simple plane using world XYZ

import clr
clr.AddReference('RevitAPI') 
clr.AddReference('RevitAPIUI') 
from Autodesk.Revit.DB import * 
 
doc = __revit__.ActiveUIDocument.Document
app = __revit__.Application
 
t = Transaction(doc, 'Create Line')
 
t.Start()
 
# define origin point and normal from world XYZ
origin = XYZ.Zero
normal = XYZ.BasisZ
 
# define a NewPlane() using normal and origin
plane = app.Create.NewPlane(normal, origin)
 
# define a NewSketchPlane from a plane
skplane = doc.FamilyCreate.NewSketchPlane(plane)
 
t.Commit()
 
__window__.Close()

Plane using 3 Points and Line Reference

A plane can be defined by defining three points in space as a reference. This method is more complicated, but flexible for defining a custom plane. Modifying the XYZ variables will let you define a plane anywhere in space at any orientation.

import clr
clr.AddReference('RevitAPI') 
clr.AddReference('RevitAPIUI') 
from Autodesk.Revit.DB import * 
 
doc = __revit__.ActiveUIDocument.Document
app = __revit__.Application
 
t = Transaction(doc, 'Create extrusion.')
 
t.Start()
#Define XYZ to define plane corners
p1 = XYZ(0,0,0)
p2 = XYZ(1,0,0)
p3 = XYZ(0,1,0)
 
#Define plane with curves
pline1 = app.Create.NewLine(p1, p2, True)
pline2 = app.Create.NewLine(p2, p3, True)
 
#create and append a new CurveArray() with plane curves
parray = CurveArray()
parray.Append(pline1)
parray.Append(pline2)
 
#create a plane using NewPlane()
plane = app.Create.NewPlane(parray)
 
#create a sketch plane using NewSketchPlane()
skplane = doc.FamilyCreate.NewSketchPlane(plane)
 
t.Commit()
 
__window__.Close()
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License