/// <summary>
        /// Place a Revit family instance of the given the FamilyType (also known as the FamilySymbol in the Revit API)
        /// on a surface derived from a backing Revit face as reference and a line as reference for its position.
        ///
        /// Note: The FamilyPlacementType must be CurveBased and the input surface must be created from a Revit Face
        /// </summary>
        /// <param name="familyType">Family Type. Also called Family Symbol.</param>
        /// <param name="face">Surface geometry derived from a Revit face as reference element</param>
        /// <param name="line">A line on the face defining where the symbol is to be placed</param>
        /// <returns>FamilyInstance</returns>
        public static FamilyInstance ByFace(FamilyType familyType, Surface face, Autodesk.DesignScript.Geometry.Line line)
        {
            if (familyType == null)
            {
                throw new ArgumentNullException("familyType");
            }
            if (face == null)
            {
                throw new ArgumentNullException("face");
            }
            if (line == null)
            {
                throw new ArgumentNullException("line");
            }
            var reference = ElementFaceReference.TryGetFaceReference(face);

            return(new FamilyInstance(familyType.InternalFamilySymbol, reference.InternalReference, (Autodesk.Revit.DB.Line)line.ToRevitType()));
        }
Exemple #2
0
        public static IEnumerable <Surface> ToProtoType(this Autodesk.Revit.DB.Face revitFace,
                                                        bool performHostUnitConversion = true)
        {
            if (revitFace == null)
            {
                throw new ArgumentNullException("revitFace");
            }

            var revitEdgeLoops            = EdgeLoopPartition.GetAllEdgeLoopsFromRevitFace(revitFace);
            var partitionedRevitEdgeLoops = EdgeLoopPartition.ByEdgeLoopsAndFace(revitFace, revitEdgeLoops);

            var listSurface = new List <Surface>();

            foreach (var edgeloopPartition in partitionedRevitEdgeLoops)
            {
                // convert the trimming curves
                var edgeLoops = EdgeLoopsAsPolyCurves(revitFace, edgeloopPartition);

                // convert the underrlying surface
                var     dyFace       = (dynamic)revitFace;
                Surface untrimmedSrf = SurfaceExtractor.ExtractSurface(dyFace, edgeLoops);
                if (untrimmedSrf == null)
                {
                    throw new Exception("Failed to extract surface");
                }

                // trim the surface
                Surface converted = untrimmedSrf.TrimWithEdgeLoops(edgeLoops);

                // perform unit conversion if necessary
                converted = performHostUnitConversion ? converted.InDynamoUnits() : converted;

                // if possible, apply revit reference
                var revitRef = revitFace.Reference;
                if (revitRef != null)
                {
                    converted = ElementFaceReference.AddTag(converted, revitRef);
                }

                listSurface.Add(converted);
            }

            return(listSurface);
        }
Exemple #3
0
        public void Faces_ExtractsFacesAccountingForInstanceTransform()
        {
            var ele   = ElementSelector.ByElementId(46874, true);
            var faces = ele.Faces;

            Assert.AreEqual(6, faces.Length);

            var bbox = BoundingBox.ByGeometry(faces);

            bbox.MaxPoint.ShouldBeApproximately(-210.846457, -26.243438, 199.124016, 1e-2);
            bbox.MinPoint.ShouldBeApproximately(-304.160105, -126.243438, 0, 1e-2);

            var refs = faces.Select(x => ElementFaceReference.TryGetFaceReference(x));

            foreach (var refer in refs)
            {
                Assert.AreEqual(46874, refer.InternalReference.ElementId.IntegerValue);
            }
        }
Exemple #4
0
        public void Faces_ExtractsFacesAccountingForInstanceTransform()
        {
            var ele   = ElementSelector.ByElementId(46874, true);
            var faces = ele.Faces;

            Assert.AreEqual(6, faces.Length);

            var bbox = BoundingBox.ByGeometry(faces);

            bbox.MaxPoint.ShouldBeApproximately(-64.266, -7.999, 60.693, 1e-3);
            bbox.MinPoint.ShouldBeApproximately(-92.708, -38.479, 0, 1e-3);

            var refs = faces.Select(x => ElementFaceReference.TryGetFaceReference(x));

            foreach (var refer in refs)
            {
                Assert.AreEqual(46874, refer.InternalReference.ElementId.IntegerValue);
            }
        }
Exemple #5
0
        /// <summary>
        /// Create a Revit DividedSurface on a face given the face and number of divisions in u and v directon
        /// and the rotation of the grid lines with respect to the natural UV parameterization of the face
        /// </summary>
        /// <param name="surface"></param>
        /// <param name="uDivs"></param>
        /// <param name="vDivs"></param>
        /// <param name="gridRotation"></param>
        /// <returns></returns>
        public static DividedSurface ByFaceUVDivisionsAndRotation(Autodesk.DesignScript.Geometry.Surface surface, int uDivs, int vDivs, double gridRotation)
        {
            if (surface == null)
            {
                throw new ArgumentNullException("surface");
            }

            if (uDivs <= 0)
            {
                throw new Exception(string.Format(Properties.Resources.NotPositiveIntegerError, "uDivs"));
            }

            if (vDivs <= 0)
            {
                throw new Exception(string.Format(Properties.Resources.NotPositiveIntegerError, "vDivs"));
            }

            return(new DividedSurface(ElementFaceReference.TryGetFaceReference(surface), uDivs, vDivs, gridRotation));
        }
Exemple #6
0
        /// <summary>
        /// Create a Revit DividedSurface on a face given the face and number of divisions in u and v directon
        /// and the rotation of the grid lines with respect to the natural UV parameterization of the face
        /// </summary>
        /// <param name="elementFace"></param>
        /// <param name="uDivs"></param>
        /// <param name="vDivs"></param>
        /// <param name="gridRotation"></param>
        /// <returns></returns>
        public static DividedSurface ByFaceUVDivisionsAndRotation(object elementFace, int uDivs, int vDivs, double gridRotation)
        {
            if (elementFace == null)
            {
                throw new ArgumentNullException("elementFace");
            }

            if (uDivs <= 0)
            {
                throw new Exception("uDivs must be a positive integer");
            }

            if (vDivs <= 0)
            {
                throw new Exception("vDivs must be a positive integer");
            }

            return(new DividedSurface(ElementFaceReference.TryGetFaceReference(elementFace), uDivs, vDivs, gridRotation));
        }
        public static AdaptiveComponent ByParametersOnFace(double[][] uvs, Surface surface, FamilySymbol familySymbol)
        {
            if (uvs == null)
            {
                throw new ArgumentNullException("uvs");
            }

            if (surface == null)
            {
                throw new ArgumentNullException("surface");
            }

            if (familySymbol == null)
            {
                throw new ArgumentNullException("familySymbol");
            }

            return(new AdaptiveComponent(uvs, ElementFaceReference.TryGetFaceReference(surface), familySymbol));
        }
Exemple #8
0
        /// <summary>
        /// Create a Revit DividedSurface on a face given the face and number of divisions in u and v directon
        /// and the rotation of the grid lines with respect to the natural UV parameterization of the face
        /// </summary>
        /// <param name="surface"></param>
        /// <param name="uDivs"></param>
        /// <param name="vDivs"></param>
        /// <param name="gridRotation"></param>
        /// <returns></returns>
        public static DividedSurface ByFaceUVDivisionsAndRotation(Autodesk.DesignScript.Geometry.Surface surface, int uDivs, int vDivs, double gridRotation)
        {
            if (surface == null)
            {
                throw new ArgumentNullException("surface");
            }

            if (uDivs <= 0)
            {
                throw new Exception("uDivs must be a positive integer");
            }

            if (vDivs <= 0)
            {
                throw new Exception("vDivs must be a positive integer");
            }

            return(new DividedSurface(ElementFaceReference.TryGetFaceReference(surface), uDivs, vDivs, gridRotation));
        }
        public static AdaptiveComponent[] ByParametersOnFace(double[][][] uvs, ElementFaceReference faceReference, FamilyType familyType)
        {
            if (uvs == null)
            {
                throw new ArgumentNullException("uvs");
            }

            if (faceReference == null)
            {
                throw new ArgumentNullException("faceReference");
            }

            if (familyType == null)
            {
                throw new ArgumentNullException("familyType");
            }

            return(uvs.Select(x => ByParametersOnFace(x, faceReference, familyType)).ToArray());
        }
        /// <summary>
        /// Initialize an AdaptiveComponent element
        /// </summary>
        /// <param name="uvParams">Parameters to use as reference</param>
        /// <param name="f">Face to use as reference</param>
        /// <param name="ft">familyType to place</param>
        private void InitAdaptiveComponent(double[][] uvParams, ElementFaceReference f, FamilyType ft)
        {
            // if the family instance is present in trace...
            var oldFam =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.FamilyInstance>(Document);

            // just mutate it...
            if (oldFam != null)
            {
                InternalSetFamilyInstance(oldFam);
                if (ft.InternalFamilySymbol.Id != oldFam.Symbol.Id)
                {
                    InternalSetFamilySymbol(ft);
                }
                InternalSetUvsAndFace(uvParams.ToUvs(), f.InternalReference);

                return;
            }

            // otherwise create a new family instance...
            TransactionManager.Instance.EnsureInTransaction(Document);

            using (Autodesk.Revit.DB.SubTransaction st = new SubTransaction(Document))
            {
                try
                {
                    st.Start();
                    var fam = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(Element.Document, ft.InternalFamilySymbol);
                    InternalSetFamilyInstance(fam);
                    InternalSetUvsAndFace(uvParams.ToUvs(), f.InternalReference);
                    st.Commit();
                }
                catch (Exception ex)
                {
                    st.RollBack();
                    throw new ArgumentException(Revit.Properties.Resources.Adaptive_Component_Creation_Failed + ex.Message);
                }
            }

            TransactionManager.Instance.TransactionTaskDone();
            ElementBinder.SetElementForTrace(InternalElement);
        }
Exemple #11
0
        public static Surface ToProtoType(this Autodesk.Revit.DB.Face revitFace)
        {
            if (revitFace == null)
            {
                return(null);
            }

            var dyFace = (dynamic)revitFace;
            List <PolyCurve> edgeLoops    = EdgeLoopsAsPolyCurves(dyFace);
            Surface          untrimmedSrf = SurfaceExtractor.ExtractSurface(dyFace, edgeLoops);
            var converted = untrimmedSrf != null?untrimmedSrf.TrimWithEdgeLoops(edgeLoops.ToArray()) : null;

            if (converted == null)
            {
                return(null);
            }

            var revitRef = revitFace.Reference;

            return(revitRef != null?ElementFaceReference.AddTag(converted, revitRef) : converted);
        }
Exemple #12
0
        /// <summary>
        /// Place a Revit family instance given the FamilyType (also known as the FamilySymbol in the Revit API)
        /// on a surface derived from a backing Revit face as reference, a reference direction and a point location where to place the family.
        ///
        /// Note: The FamilyType should be workplane based and the input surface must be created from a Revit Face. The reference direction defines the rotation of the instance on the reference, and thus cannot be perpendicular to the face.
        /// </summary>
        /// <param name="familyType">Family Type. Also called Family Symbol.</param>
        /// <param name="face">Surface geometry derived from a Revit face as reference element</param>
        /// <param name="location">Point on the face where the instance is to be placed</param>
        /// <param name="referenceDirection">A vector that defines the direction of placement of the family instance</param>
        /// <returns>FamilyInstance</returns>
        public static FamilyInstance ByFace(FamilyType familyType, Surface face, Point location,
                                            Vector referenceDirection)
        {
            if (familyType == null)
            {
                throw new ArgumentNullException("familyType");
            }
            if (face == null)
            {
                throw new ArgumentNullException("face");
            }
            if (location == null)
            {
                throw new ArgumentNullException("location");
            }
            if (referenceDirection == null)
            {
                throw new ArgumentNullException("referenceDirection");
            }
            var reference = ElementFaceReference.TryGetFaceReference(face);

            return(new FamilyInstance(familyType.InternalFamilySymbol, reference.InternalReference,
                                      location.ToXyz(), referenceDirection.ToXyz()));
        }
        /// <summary>
        /// Create an adaptive component by uv points on a face.
        /// </summary>
        /// <param name="uvs">An array of UV pairs</param>
        /// <param name="surface">The surface on which to place the AdaptiveComponent</param>
        /// <param name="familySymbol"></param>
        /// <returns></returns>
        public static AdaptiveComponent ByParametersOnFace(Autodesk.DesignScript.Geometry.UV[] uvs, Surface surface, FamilySymbol familySymbol)
        {
            if (uvs == null)
            {
                throw new ArgumentNullException("uvs");
            }

            if (surface == null)
            {
                throw new ArgumentNullException("surface");
            }

            if (familySymbol == null)
            {
                throw new ArgumentNullException("familySymbol");
            }

            return(new AdaptiveComponent(uvs.Select(x => new [] { x.U, x.V }).ToArray(), ElementFaceReference.TryGetFaceReference(surface), familySymbol));
        }
        public static IEnumerable <Surface> ToProtoType(this Autodesk.Revit.DB.Face revitFace,
                                                        bool performHostUnitConversion = true, Reference referenceOverride = null)
        {
            if (revitFace == null)
            {
                throw new ArgumentNullException("revitFace");
            }

            var revitCurveLoops            = CurveLoopPartition.GetAllCurveloopsFromRevitFace(revitFace);
            var partitionedRevitCurveLoops = CurveLoopPartition.ByCurveLoops(revitCurveLoops);

            var listSurface = new List <Surface>();

            foreach (var curveloopPartition in partitionedRevitCurveLoops)
            {
                // convert the trimming curves
                var curveLoops = CurveLoopsAsPolyCurves(revitFace, curveloopPartition.GetAllCurves());

                // convert the underrlying surface
                var     dyFace       = (dynamic)revitFace;
                Surface untrimmedSrf = SurfaceExtractor.ExtractSurface(dyFace, curveLoops);
                if (untrimmedSrf == null)
                {
                    curveLoops.ForEach(x => x.Dispose());
                    curveLoops.Clear();
                    throw new Exception("Failed to extract surface");
                }

                // trim the surface
                Surface converted;
                try
                {
                    converted = untrimmedSrf.TrimWithEdgeLoops(curveLoops);
                }
                catch (Exception e)
                {
                    curveLoops.ForEach(x => x.Dispose());
                    curveLoops.Clear();
                    untrimmedSrf.Dispose();
                    throw e;
                }

                curveLoops.ForEach(x => x.Dispose());
                curveLoops.Clear();
                untrimmedSrf.Dispose();

                // perform unit conversion if necessary
                if (performHostUnitConversion)
                {
                    UnitConverter.ConvertToDynamoUnits(ref converted);
                }

                // if possible, apply revit reference
                var revitRef = referenceOverride ?? revitFace.Reference;
                if (revitRef != null)
                {
                    converted = ElementFaceReference.AddTag(converted, revitRef);
                }

                listSurface.Add(converted);
            }

            return(listSurface);
        }
 /// <summary>
 /// Internal constructor for the AdaptiveComponent wrapper
 /// </summary>
 /// <param name="pts">Points to use as reference</param>
 /// <param name="f">Face to use as reference</param>
 /// <param name="fs">FamilySymbol to place</param>
 private AdaptiveComponent(double[][] pts, ElementFaceReference f, FamilySymbol fs)
 {
     SafeInit(() => InitAdaptiveComponent(pts, f, fs));
 }
Exemple #16
0
 /// <summary>
 /// Create a Revit DividedSurface on a face given the face and number of divisions in u and v directon
 /// </summary>
 /// <param name="elementFace"></param>
 /// <param name="uDivs"></param>
 /// <param name="vDivs"></param>
 /// <returns></returns>
 public static DividedSurface ByFaceAndUVDivisions(object elementFace, int uDivs, int vDivs)
 {
     return(ByFaceUVDivisionsAndRotation(ElementFaceReference.TryGetFaceReference(elementFace), uDivs, vDivs, 0.0));
 }
Exemple #17
0
        /// <summary>
        ///get curtain grid from element with curtain grid or grids
        /// </summary>
        /// <param name="curtainHolderElement"></param>
        /// <param name="elementFaceReference"></param>

        static public CurtainGrid ByElementAndReference(Element curtainHolderElement, ElementFaceReference elementFaceReference)
        {
            return(new CurtainGrid(curtainHolderElement.InternalElement, elementFaceReference.InternalReference));
        }
Exemple #18
0
 /// <summary>
 /// Private constructor for creating a divided surface
 /// </summary>
 /// <param name="elementFace"></param>
 /// <param name="uDivs"></param>
 /// <param name="vDivs"></param>
 /// <param name="rotation"></param>
 private DividedSurface(ElementFaceReference elementFace, int uDivs, int vDivs, double rotation)
 {
     SafeInit(() => InitDividedSurface(elementFace, uDivs, vDivs, rotation));
 }
Exemple #19
0
 /// <summary>
 /// Create a Revit DividedSurface on a face given the face and number of divisions in u and v directon
 /// </summary>
 /// <param name="elementFace"></param>
 /// <param name="uDivs"></param>
 /// <param name="vDivs"></param>
 /// <returns></returns>
 public static DividedSurface ByFaceAndUVDivisions(ElementFaceReference elementFace, int uDivs, int vDivs)
 {
     return(ByFaceUVDivisionsAndRotation(elementFace, uDivs, vDivs, 0.0));
 }
Exemple #20
0
 private static Autodesk.DesignScript.Geometry.Surface Tag(Autodesk.DesignScript.Geometry.Surface srf,
                                                           Autodesk.Revit.DB.Reference reference)
 {
     return(reference != null?ElementFaceReference.AddTag(srf, reference) : srf);
 }
Exemple #21
0
 /// <summary>
 /// Create a Revit DividedSurface on a face given the face and number of divisions in u and v directon
 /// </summary>
 /// <param name="elementFace"></param>
 /// <param name="uDivs"></param>
 /// <param name="vDivs"></param>
 /// <returns></returns>
 public static DividedSurface ByFaceAndUVDivisions(Autodesk.DesignScript.Geometry.Surface elementFace, int uDivs, int vDivs)
 {
     return(ByFaceUVDivisionsAndRotation(ElementFaceReference.TryGetFaceReference(elementFace), uDivs, vDivs, 0.0));
 }