Create Curve Offset

Let me share how to offset curves in Revit API.

I found it really useful on a few recent tools I was working, so I want to share it with you. It's not complicated and I think it can be really useful.

Here is how it works.

Simple Curve Offset

Curve class has a method CreateOffset(distance, axis) to create an offset.

Overall it's very simple to use:

axis       = XYZ.BasisZ
new_curve  = curve.CreateOffset(offset_ft, axis)


Axis

Some people get confused about the Axis for their offset.

Imagine a simple line in 3D space.
Theoretically you could create an offset in any direction(360degrees) around its own axis like a circle.
Therefore you need an axis so you can only create offset in 2 directions (positive, negative).

Here a few sketches to explain it.

💡Your axis should be perpendicular to your curve.


Example 1: Create Wall Offset

Here is an example:

  • Pick Wall

  • Get Curve

  • Create Wall Offset

  • Get Wall parameters

  • Create new Walls with Offset

#⬇️ Imports
from Autodesk.Revit.DB import *
from pyrevit import forms

#📦 Variables
app      = __revit__.Application
uidoc    = __revit__.ActiveUIDocument
doc      = __revit__.ActiveUIDocument.Document #type:Document



def pick_wall():
    from Autodesk.Revit.UI.Selection import ObjectType
    ref = uidoc.Selection.PickObject(ObjectType.Element)
    el = doc.GetElement(ref)

    if type(el) == Wall:
        return el

    forms.alert('Please select a Wall to continue.', exitscript=True)


# Pick Wall to access Curve
wall  = pick_wall()
curve = wall.Location.Curve

# Crete Offset Curve
offset_ft  = UnitUtils.ConvertToInternalUnits(100, UnitTypeId.Centimeters) #Revit API uses feet.
axis       = XYZ.BasisZ
new_curve  = curve.CreateOffset(offset_ft, axis)
new_curve_ = curve.CreateOffset(-offset_ft, axis)


# Create New Walls
with Transaction(doc, 'Offset Wall') as t:
    t.Start()

    # Get Wall Parameters
    wall_type_id = wall.GetTypeId()
    level_id     = wall.LevelId
    h            = wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).AsDouble()
    base_offset  = 0
    flip         = False
    struc        = False

    # Create New Walls
    new_wall = Wall.Create(doc, new_curve , wall_type_id, level_id, h, base_offset, flip,struc)
    new_wall = Wall.Create(doc, new_curve_, wall_type_id, level_id, h, base_offset, flip,struc)

    t.Commit()

Example 2: Create Model Line Offset

  • Pick ModelLine

  • Create Offset Curve

  • Define Plane

  • Create New Model Lines

#⬇️ Imports
from Autodesk.Revit.DB import *
from pyrevit import forms

#📦 Variables
app      = __revit__.Application
uidoc    = __revit__.ActiveUIDocument
doc      = __revit__.ActiveUIDocument.Document #type:Document


def pick_line():
    from Autodesk.Revit.UI.Selection import ObjectType
    ref = uidoc.Selection.PickObject(ObjectType.Element)
    el  = doc.GetElement(ref)

    if isinstance(el, CurveElement):
        return el
    else:
        forms.alert('Please select a model line.', exitscript=True)

# Pick Existing ModelLine
model_line = pick_line()

# Create Offset Curve
curve      = model_line.GeometryCurve
offset_ft  = UnitUtils.ConvertToInternalUnits(10, UnitTypeId.Centimeters) #Revit API uses feet.
axis       = XYZ.BasisZ
new_curve  = curve.CreateOffset(offset_ft, axis)
new_curve_ = curve.CreateOffset(-offset_ft, axis)

# Define plane (for new model line)
pt_start     = new_curve.GetEndPoint(0)
plane        = Plane.CreateByNormalAndOrigin(axis, pt_start)
sketch_plane = SketchPlane.Create(doc, plane)

# Create new Model Line
with Transaction(doc, 'Create Offset Model Lines') as t:
    t.Start()  #🔓

    new_line = doc.Create.NewModelCurve(new_curve, sketch_plane)
    new_line = doc.Create.NewModelCurve(new_curve_, sketch_plane)
    
    t.Commit() #🔒


⌨️ Happy Coding!
Erik Frits