Problem Creating a FaceWall on a DirectShape Face
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone,
I'm trying to create a `FaceWall` on the face of a `DirectShape` object of the Mass category. According to the Revit API documentation and The Building Coder article, this should be possible by using the face reference of the `DirectShape` as input for:
public static FaceWall Create(
Document document,
ElementId wallType,
WallLocationLine locationLine,
Reference faceReference
)
The relevant documentation states:
"DirectShape elements, by default, support element references, including dimensions, alignments, and face hosting, as well as snapping. This default behavior can be changed using the DirectShapeOptions.ReferencingOption property."
Sources:
https://thebuildingcoder.typepad.com/blog/2018/01/directshape-topics-and-happy-new-year.html#4
Despite this, I encounter the following error:
Failed to create FaceWall: This reference cannot be applied to a face wall.
Parameter name: faceReference
Additionally, I cannot manually select `DirectShape` faces to create a `WallByFace`.
Here's a simplified version of my code:
# -*- coding: utf-8 -*-
# Imports
from Autodesk.Revit.DB import *
from pyrevit import revit
doc = revit.doc
# Create a rectangle for extrusion
p1 = XYZ(0, 0, 0)
p2 = XYZ(10, 0, 20)
p3 = XYZ(10, 10, 20)
p4 = XYZ(0, 10, 0)
line1 = Line.CreateBound(p1, p2)
line2 = Line.CreateBound(p2, p3)
line3 = Line.CreateBound(p3, p4)
line4 = Line.CreateBound(p4, p1)
curve_loop = CurveLoop()
for line in [line1, line2, line3, line4]:
curve_loop.Append(line)
# Create DirectShape
with Transaction(doc, 'Create Direct Shape') as t1:
t1.Start()
extrusion = GeometryCreationUtilities.CreateExtrusionGeometry([curve_loop], XYZ.BasisX, 100)
ds = DirectShape.CreateElement(doc, ElementId(BuiltInCategory.OST_Mass))
ds.SetShape([extrusion])
ds.Name = "TechMass"
ds_options = ds.GetOptions()
ds_options.ReferencingOption = DirectShapeReferencingOption.Referenceable
ds.SetOptions(ds_options)
t1.Commit()
# Create FaceWall
with Transaction(doc, 'Create Face Wall') as t2:
t2.Start()
opt = Options()
opt.ComputeReferences = True
opt.IncludeNonVisibleObjects = True
opt.View = doc.ActiveView
# Find largest planar face
max_face_ref = None
max_area = 0
ds_geos = ds.get_Geometry(opt)
for geo in ds_geos:
if isinstance(geo, Solid):
for face in geo.Faces:
area = face.Area
if area > max_area and face.GetSurface().Normal:
max_area = area
max_face_ref = face.Reference
if max_face_ref:
try:
wall = FaceWall.Create(doc, ElementId(771976), WallLocationLine.CoreCenterline, max_face_ref)
except Exception as e:
print("Failed to create FaceWall:", e)
t2.Commit()
Here is the debug output I receive:
Max face reference found: <Autodesk.Revit.DB.Reference object at 0x0000000000001079 [Autodesk.Revit.DB.Reference]>
Failed to create FaceWall: This reference cannot be applied to a face wall.
Parameter name: faceReference
Additional Notes:
- I am using two transactions and explicitly setting the `DirectShapeOptions.ReferencingOption` to `Referenceable`.
- This script is executed using pyRevit
I will also provide screenshots of the DirectShape and its face reference details from RevitLookup:
Does anyone know why this reference cannot be applied to create a `FaceWall`? Is there a limitation with `DirectShape` references for this method, or am I missing something in the implementation?
Thanks in advance for any help or suggestions!