Creates a new DisplacementElement as a child of the specified parent DisplacementElement.
Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 2015.0.0.0 (2015.0.0.0)
Since: 2014
Syntax
C# |
---|
|
Visual Basic |
---|
|
Visual C++ |
---|
|
Parameters
- document
- Type: Autodesk.Revit.DB Document
The Document
- elementsToDisplace
- Type: System.Collections.Generic ICollection ElementId
The elements to be displaced.
- displacement
- Type: Autodesk.Revit.DB XYZ
The translation to be applied to the graphics of the displaced elements.
- ownerDBView
- Type: Autodesk.Revit.DB View
The 3D view which will own the DisplacementElement.
- parentDisplacementElement
- Type: Autodesk.Revit.DB DisplacementElement
An existing DisplacementElement that will be the parent of the one being created. It must be owned by ownerDBView. The relative transform of new DisplacementElement will be concatenated with the absolute transform of the parent DisplacementElement. If the elements specified by displacedElemIds are already displaced by another DisplacementElement, then this must be that element.
Return Value
The id of the new DisplacementElement.Examples

public static void CreateDisplacementAndPath(Document doc, View view)
{
// Find roof
FilteredElementCollector fec = new FilteredElementCollector(doc);
fec.OfClass(typeof(RoofBase));
RoofBase roof = fec.FirstElement() as RoofBase;
// Get a geometric reference for the path
Reference edgeRef = GetHorizontalEdgeReference(roof);
using (Transaction t = new Transaction(doc, "CreateDisplacementAndPath"))
{
t.Start();
// Create a new top level DisplacementElement
DisplacementElement dispElem = DisplacementElement.Create(doc, new ElementId[] { roof.Id }, new XYZ(10, 0, 20), view, null);
// Create the path associated to the element
DisplacementPath.Create(doc, dispElem, edgeRef, 0.5);
t.Commit();
}
}
private static Reference GetHorizontalEdgeReference(Element elem)
{
//Find target edge from lower face of roof
Options options = new Options();
options.ComputeReferences = true;
GeometryElement geomElem = elem.get_Geometry(options);
foreach (var geomObj in geomElem)
{
if (geomObj is Solid)
{
Solid solid = geomObj as Solid;
var faces = solid.Faces;
foreach (Face face in faces)
{
BoundingBoxUV box = face.GetBoundingBox();
UV midpoint = (box.Min + box.Max) / 2.0;
if (face.ComputeNormal(midpoint).Normalize().Z < -0.1) // Downward facing, this is good enough
{
var edgeLoops = face.EdgeLoops;
foreach (EdgeArray edgeArray in edgeLoops)
{
foreach (Edge edge in edgeArray)
{
// horizontal?
if (Math.Abs(edge.AsCurve().ComputeDerivatives(0.0, true).BasisX.DotProduct(XYZ.BasisZ)) - 1 <= 0.00001)
{
return edge.Reference;
}
}
}
}
}
}
}
return null;
}

Public Shared Sub CreateDisplacementAndPath(doc As Document, view As View)
' Find roof
Dim fec As New FilteredElementCollector(doc)
fec.OfClass(GetType(RoofBase))
Dim roof As RoofBase = TryCast(fec.FirstElement(), RoofBase)
' Get a geometric reference for the path
Dim edgeRef As Reference = GetHorizontalEdgeReference(roof)
Using t As New Transaction(doc, "CreateDisplacementAndPath")
t.Start()
' Create a new top level DisplacementElement
Dim dispElem As DisplacementElement = DisplacementElement.Create(doc, New ElementId() {roof.Id}, New XYZ(10, 0, 20), view, Nothing)
' Create the path associated to the element
DisplacementPath.Create(doc, dispElem, edgeRef, 0.5)
t.Commit()
End Using
End Sub
Private Shared Function GetHorizontalEdgeReference(elem As Element) As Reference
'Find target edge from lower face of roof
Dim options As New Options()
options.ComputeReferences = True
Dim geomElem As GeometryElement = elem.Geometry(options)
For Each geomObj As GeometryObject In geomElem
If TypeOf geomObj Is Solid Then
Dim solid As Solid = TryCast(geomObj, Solid)
Dim faces = solid.Faces
For Each face As Face In faces
Dim box As BoundingBoxUV = face.GetBoundingBox()
Dim midpoint As UV = (box.Min + box.Max) / 2.0
If face.ComputeNormal(midpoint).Normalize().Z < -0.1 Then
' Downward facing, this is good enough
Dim edgeLoops = face.EdgeLoops
For Each edgeArray As EdgeArray In edgeLoops
For Each edge As Edge In edgeArray
' horizontal?
If Math.Abs(edge.AsCurve().ComputeDerivatives(0.0, True).BasisX.DotProduct(XYZ.BasisZ)) - 1 <= 0.00001 Then
Return edge.Reference
End If
Next
Next
End If
Next
End If
Next
Return Nothing
End Function
Exceptions
Exception | Condition |
---|---|
Autodesk.Revit.Exceptions ArgumentException | #elementIds# contains no element ids. -or- ownerDBView is not a 3D view. -or- For each individual element in the set elementsToDisplace, isAllowedAsDisplacedElement must return true, and the elements must either not already be displaced in the specified view, or else they must all be displaced by the same displacement element in the view. -or- The DisplacementElement parentDisplacementElement in not owned by the view ownerDBView. |
Autodesk.Revit.Exceptions ArgumentNullException | A non-optional argument was NULL |