DisplacementElementCreate Method |
Creates a new DisplacementElement as a child of the specified parent DisplacementElement.
Namespace: Autodesk.Revit.DBAssembly: RevitAPI (in RevitAPI.dll) Version: 27.0.4.0 (27.0.4.0)
Syntaxpublic static DisplacementElement Create(
Document document,
ICollection<ElementId> elementsToDisplace,
XYZ displacement,
View ownerDBView,
DisplacementElement parentDisplacementElement
)
Public Shared Function Create (
document As Document,
elementsToDisplace As ICollection(Of ElementId),
displacement As XYZ,
ownerDBView As View,
parentDisplacementElement As DisplacementElement
) As DisplacementElement
public:
static DisplacementElement^ Create(
Document^ document,
ICollection<ElementId^>^ elementsToDisplace,
XYZ^ displacement,
View^ ownerDBView,
DisplacementElement^ parentDisplacementElement
)
static member Create :
document : Document *
elementsToDisplace : ICollection<ElementId> *
displacement : XYZ *
ownerDBView : View *
parentDisplacementElement : DisplacementElement -> DisplacementElement Parameters
- document Document
-
The Document
- elementsToDisplace ICollectionElementId
-
The elements to be displaced.
- displacement XYZ
-
The translation to be applied to the graphics of the displaced elements.
- ownerDBView View
-
The 3D view which will own the DisplacementElement.
- parentDisplacementElement 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
DisplacementElement
The id of the new DisplacementElement.
Exceptions| Exception | Condition |
|---|
| 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.
|
| ArgumentNullException |
A non-optional argument was null
|
Examplepublic 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;
}
See Also