Creates a new DisplacementElement as a child of the specified parent DisplacementElement.
Namespace: Autodesk.Revit.DBAssembly: RevitAPI (in RevitAPI.dll) Version: 20.0.0.0 (20.0.0.377)
Since:
2014
Syntax
Return Value
The id of the new DisplacementElement.
Examples
CopyC#
public static void CreateDisplacementAndPath(Document doc, View view)
{
FilteredElementCollector fec = new FilteredElementCollector(doc);
fec.OfClass(typeof(RoofBase));
RoofBase roof = fec.FirstElement() as RoofBase;
Reference edgeRef = GetHorizontalEdgeReference(roof);
using (Transaction t = new Transaction(doc, "CreateDisplacementAndPath"))
{
t.Start();
DisplacementElement dispElem = DisplacementElement.Create(doc, new ElementId[] { roof.Id }, new XYZ(10, 0, 20), view, null);
DisplacementPath.Create(doc, dispElem, edgeRef, 0.5);
t.Commit();
}
}
private static Reference GetHorizontalEdgeReference(Element elem)
{
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)
{
var edgeLoops = face.EdgeLoops;
foreach (EdgeArray edgeArray in edgeLoops)
{
foreach (Edge edge in edgeArray)
{
if (Math.Abs(edge.AsCurve().ComputeDerivatives(0.0, true).BasisX.DotProduct(XYZ.BasisZ)) - 1 <= 0.00001)
{
return edge.Reference;
}
}
}
}
}
}
}
return null;
}
CopyVB.NET
Public Shared Sub CreateDisplacementAndPath(doc As Document, view As View)
Dim fec As New FilteredElementCollector(doc)
fec.OfClass(GetType(RoofBase))
Dim roof As RoofBase = TryCast(fec.FirstElement(), RoofBase)
Dim edgeRef As Reference = GetHorizontalEdgeReference(roof)
Using t As New Transaction(doc, "CreateDisplacementAndPath")
t.Start()
Dim dispElem As DisplacementElement = DisplacementElement.Create(doc, New ElementId() {roof.Id}, New XYZ(10, 0, 20), view, Nothing)
DisplacementPath.Create(doc, dispElem, edgeRef, 0.5)
t.Commit()
End Using
End Sub
Private Shared Function GetHorizontalEdgeReference(elem As Element) As Reference
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
Dim edgeLoops = face.EdgeLoops
For Each edgeArray As EdgeArray In edgeLoops
For Each edge As Edge In edgeArray
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
|
See Also