Example #1
0
        /// <summary>
        /// Internal constructor for the AdaptiveComponent wrapper
        /// </summary>
        /// <param name="pts">Points to use as reference</param>
        /// <param name="fs">FamilySymbol to place</param>
        private AdaptiveComponent(Point[] pts, FamilySymbol fs)
        {

            // 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 (fs.InternalFamilySymbol.Id != oldFam.Symbol.Id)
                   InternalSetFamilySymbol(fs);
                InternalSetPositions(pts.ToXyzs());
                return;
            }

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

            var fam = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(Element.Document, fs.InternalFamilySymbol);

            if (fam == null)
                throw new Exception("An adaptive component could not be found or created.");

            InternalSetFamilyInstance(fam);
            InternalSetPositions(pts.ToXyzs());

            TransactionManager.Instance.TransactionTaskDone();

            // remember this value
            ElementBinder.SetElementForTrace(this.InternalElement);
        }
Example #2
0
        /// <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)
        {
            // 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 (fs.InternalFamilySymbol.Id != oldFam.Symbol.Id)
                   InternalSetFamilySymbol(fs);
                InternalSetUvsAndFace(pts.ToUvs(), f.InternalReference );
                return;
            }

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

            var fam = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(Element.Document, fs.InternalFamilySymbol);

            if (fam == null)
                throw new Exception("An adaptive component could not be found or created.");

            InternalSetFamilyInstance(fam);
            InternalSetUvsAndFace(pts.ToUvs(), f.InternalReference );

            TransactionManager.Instance.TransactionTaskDone();

        }
Example #3
0
        public void ByParametersOnFace_CreatesValidACFromElementFaceReference()
        {
            var ele = ElementSelector.ByType <Autodesk.Revit.DB.Form>(true).FirstOrDefault();

            Assert.NotNull(ele);

            var form  = ele as Form;
            var faces = form.ElementFaceReferences;

            Assert.IsTrue(faces.All(x => x != null));
            Assert.AreEqual(6, faces.Length);

            var fs = FamilySymbol.ByName("3PointAC");

            var uvs = new[]
            {
                Autodesk.DesignScript.Geometry.UV.ByCoordinates(0, 0),
                Autodesk.DesignScript.Geometry.UV.ByCoordinates(0.5, 0.5),
                Autodesk.DesignScript.Geometry.UV.ByCoordinates(0.5, 0)
            };

            var ac = AdaptiveComponent.ByParametersOnFace(uvs, faces.First(), fs);

            Assert.NotNull(ac);
        }
Example #4
0
        public void ByPoints_PointArray_ProducesValidAdaptiveComponentAndLocations()
        {
            var pts = new Point[]
            {
                Point.ByCoordinates(0, 0, 0),
                Point.ByCoordinates(10, 0, 10),
                Point.ByCoordinates(20, 0, 0)
            };
            var fs = FamilySymbol.ByName("3PointAC");
            var ac = AdaptiveComponent.ByPoints(pts, fs);

            var locs = ac.Locations;

            var pairs = locs.Zip(pts, (point, point1) => new Tuple <Point, Point>(point, point1));

            // compares after unit conversion
            foreach (var pair in pairs)
            {
                pair.Item1.ShouldBeApproximately(pair.Item2);
            }

            var unconvertedPairs = pts.Zip(GetInternalPoints((FamilyInstance)ac.InternalElement),
                                           (point, point1) => new Tuple <Point, XYZ>(point, point1));

            foreach (var pair in unconvertedPairs)
            {
                pair.Item1.ShouldBeApproximately(pair.Item2 * UnitConverter.HostToDynamoFactor);
            }

            Assert.NotNull(ac);
        }
Example #5
0
        public void ByPoints_ShouldThrowExceptionWithNonMatchingNumberOfPoints()
        {
            var pts = new Point[]
            {
                Point.ByCoordinates(0, 0, 0),
                Point.ByCoordinates(10, 0, 10)
            };
            var fs = FamilySymbol.ByName("3PointAC");

            Assert.Throws(typeof(Exception), () => AdaptiveComponent.ByPoints(pts, fs));
        }
Example #6
0
        public void CanSuccessfullySetAndGetElement()
        {
            var wall   = ElementSelector.ByElementId(184176, true);
            var famSym = FamilySymbol.ByName("18\" x 18\"");

            var name = "Column";

            wall.SetParameterByName(name, famSym);
            var sym = wall.GetParameterValueByName(name) as Element;

            Assert.NotNull(sym);
            Assert.AreEqual(sym.Name, "18\" x 18\"");
        }
Example #7
0
        public void ByPointsOnCurve_ProducesValidAdaptiveComponentAndLocations()
        {
            // create spline
            var pts = new Autodesk.DesignScript.Geometry.Point[]
            {
                Point.ByCoordinates(0, 0, 0),
                Point.ByCoordinates(1, 0, 0),
                Point.ByCoordinates(3, 0, 0),
                Point.ByCoordinates(10, 0, 0),
                Point.ByCoordinates(12, 0, 0),
            };

            var spline = NurbsCurve.ByControlPoints(pts, 3);

            Assert.NotNull(spline);

            // build model curve from spline
            var modCurve = ModelCurve.ByCurve(spline);

            Assert.NotNull(modCurve);

            // obtain the family from the document
            var fs = FamilySymbol.ByName("3PointAC");

            // build the AC
            var parms = new double[]
            {
                0, 0.5, 1
            };

            var ac = AdaptiveComponent.ByParametersOnCurveReference(parms, modCurve.ElementCurveReference, fs);

            // with unit conversion
            foreach (var pt in ac.Locations)
            {
                spline.DistanceTo(pt).ShouldBeApproximately(0);
            }

            // without unit conversion
            var unconvertedPoints = GetInternalPoints((FamilyInstance)ac.InternalElement);

            foreach (var pt in unconvertedPoints)
            {
                spline.DistanceTo(pt.ToPoint()).ShouldBeApproximately(0);
            }

            Assert.NotNull(ac);
        }
Example #8
0
 static FamilyInstance ByCurve(FamilySymbol fs, Autodesk.DesignScript.Geometry.Curve c)
 {
     throw new NotImplementedException();
 }
Example #9
0
        /// <summary>
        /// Place a Revit FamilyInstance given the FamilySymbol (also known as the FamilyType) and it's coordinates in world space
        /// </summary>
        /// <param name="familySymbol"></param>
        /// <param name="x">X coordinate in meters</param>
        /// <param name="y">Y coordinate in meters</param>
        /// <param name="z">Z coordinate in meters</param>
        /// <returns></returns>
        public static FamilyInstance ByCoordinates(FamilySymbol familySymbol, double x = 0, double y = 0, double z = 0)
        {
            if (familySymbol == null)
            {
                throw new ArgumentNullException("familySymbol");
            }

            var pt = Point.ByCoordinates(x, y, z);

            return ByPoint(familySymbol, pt);
        }
Example #10
0
        public void ByPoints_NullPts()
        {
            var fs = FamilySymbol.ByName("3PointAC");

            Assert.Throws(typeof(ArgumentNullException), () => AdaptiveComponent.ByPoints(null, fs));
        }
Example #11
0
        /// <summary>
        /// Create an adaptive component by uv points on a face.
        /// </summary>
        /// <param name="uvs">An array of UV pairs</param>
        /// <param name="revitFace">The surface on which to place the AdaptiveComponent</param>
        /// <param name="familySymbol"></param>
        /// <returns></returns>
        public static AdaptiveComponent ByParametersOnFace(double[][] uvs, object revitFace, FamilySymbol familySymbol)
        {
            if (uvs == null)
            {
                throw new ArgumentNullException("uvs");
            }

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

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

            return(new AdaptiveComponent(uvs, ElementFaceReference.TryGetFaceReference(revitFace), familySymbol));
        }
Example #12
0
        /// <summary>
        /// Place a Revit FamilyInstance given the FamilySymbol (also known as the FamilyType) and it's coordinates in world space
        /// </summary>
        /// <param name="familySymbol"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public static FamilyInstance ByPoint(FamilySymbol familySymbol, Point point)
        {
            if (familySymbol == null)
            {
                throw new ArgumentNullException("familySymbol");
            } 
            
            if (point == null)
            {
                throw new ArgumentNullException("point");
            }

            return new FamilyInstance(familySymbol.InternalFamilySymbol, point.ToXyz());
        }
Example #13
0
        public static AdaptiveComponent ByParametersOnCurveReference(double[] parameters, ElementCurveReference revitCurve, FamilySymbol familySymbol)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

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

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

            return new AdaptiveComponent(parameters, ElementCurveReference.TryGetCurveReference(revitCurve).InternalReference, familySymbol);
        }
Example #14
0
        /// <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);
        }
Example #15
0
        /// <summary>
        /// Create an adaptive component referencing the parameters on a Curve reference
        /// </summary>
        /// <param name="parameters">The parameters on the curve</param>
        /// <param name="revitCurve">The curve to reference</param>
        /// <param name="familySymbol">The family symbol to construct</param>
        /// <returns></returns>
        public static AdaptiveComponent ByParametersOnCurveReference(double[] parameters, object revitCurve, FamilySymbol familySymbol)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

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

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

            return(new AdaptiveComponent(parameters, ElementCurveReference.TryGetCurveReference(revitCurve).InternalReference, familySymbol));
        }
Example #16
0
        /// <summary>
        /// Place a Revit FamilyInstance given the FamilySymbol (also known as the FamilyType) and it's coordinates in world space
        /// </summary>
        /// <param name="familySymbol"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <returns></returns>
        public static FamilyInstance ByCoordinates(FamilySymbol familySymbol, double x, double y, double z)
        {
            if (familySymbol == null)
            {
                throw new ArgumentNullException("familySymbol");
            }

            return new FamilyInstance(familySymbol.InternalFamilySymbol, new XYZ(x,y,z));
        }
Example #17
0
        /// <summary>
        /// Place a Revit FamilyInstance given the FamilySymbol (also known as the FamilyType), it's coordinates in world space, and the Level
        /// </summary>
        /// <param name="familySymbol"></param>
        /// <param name="point"></param>
        /// <param name="level"></param>
        /// <returns></returns>
        public static FamilyInstance ByPointAndLevel(FamilySymbol familySymbol, Point point, Level level)
        {
            if (familySymbol == null)
            {
                throw new ArgumentNullException("familySymbol");
            }

            return new FamilyInstance(familySymbol.InternalFamilySymbol, point.ToXyz(), level.InternalLevel);
        }
Example #18
0
        /// <summary>
        /// Place a Revit FamilyInstance given the FamilySymbol (also known as the FamilyType) and it's coordinates in world space
        /// </summary>
        /// <param name="familySymbol"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public static FamilyInstance ByPoint(FamilySymbol familySymbol, Point point)
        {
            if (familySymbol == null)
            {
                throw new ArgumentNullException();
            }

            if (point == null)
            {
                throw new ArgumentNullException();
            }

            return new FamilyInstance(familySymbol.InternalFamilySymbol, new XYZ(point.X, point.Y, point.Z));
        }
Example #19
0
        /// <summary>
        /// Obtain a collection of FamilyInstances from the Revit Document and use them in the Dynamo graph
        /// </summary>
        /// <param name="familySymbol"></param>
        /// <returns></returns>
        public static FamilyInstance[] ByFamilySymbol(FamilySymbol familySymbol)
        {
            if (familySymbol == null)
            {
                throw new ArgumentNullException("familySymbol");
            }

            return DocumentManager.Instance
                .ElementsOfType<Autodesk.Revit.DB.FamilyInstance>()
                .Where(x => x.Symbol.Id == familySymbol.InternalFamilySymbol.Id)
                .Select(x => FamilyInstance.FromExisting(x, true))
                .ToArray();
        }
Example #20
0
       /// <summary>
       /// Set the family symbol for the internal family instance 
       /// </summary>
       /// <param name="fs"></param>
        private void InternalSetFamilySymbol( FamilySymbol fs)
       {
          TransactionManager.Instance.EnsureInTransaction(Document);

          InternalFamilyInstance.Symbol = fs.InternalFamilySymbol;

          TransactionManager.Instance.TransactionTaskDone();

       }
Example #21
0
 static FamilyInstance ByUvsOnFace(FamilySymbol fs, Vector uv, Face f)
 {
     throw new NotImplementedException();
 }
Example #22
0
        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);
        }
Example #23
0
 public static FamilySymbol Wrap(Autodesk.Revit.DB.FamilySymbol ele, bool isRevitOwned)
 {
     return(FamilySymbol.FromExisting(ele, isRevitOwned));
 }
Example #24
0
        /// <summary>
        /// Create an AdaptiveComponent from a list of points.
        /// </summary>
        /// <param name="points">The points to reference in the AdaptiveComponent</param>
        /// <param name="familySymbol">The family symbol to use to build the AdaptiveComponent</param>
        /// <returns></returns>
        public static AdaptiveComponent ByPoints( Point[] points, FamilySymbol familySymbol )
        {
            if (points == null)
            {
                throw new ArgumentNullException("points");
            }

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

            return new AdaptiveComponent(points, familySymbol);
        }
Example #25
0
        /// <summary>
        /// Create an adaptive component referencing the parameters on a Curve reference
        /// </summary>
        /// <param name="parameters">The parameters on the curve</param>
        /// <param name="curveReference">The curve to reference</param>
        /// <param name="familySymbol">The family symbol to construct</param>
        /// <returns></returns>
        public static AdaptiveComponent ByParametersOnCurveReference(double[] parameters, CurveReference curveReference, FamilySymbol familySymbol)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

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

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

            return new AdaptiveComponent(parameters, curveReference.InternalReference, familySymbol);
        }
Example #26
0
        /// <summary>
        /// Create an adaptive component referencing the parameters on a Curve reference
        /// </summary>
        /// <param name="parameters">The parameters on the curve</param>
        /// <param name="curve">The curve to reference</param>
        /// <param name="familySymbol">The family symbol to construct</param>
        /// <returns></returns>
        public static AdaptiveComponent ByParametersOnCurveReference( double[] parameters, Autodesk.DesignScript.Geometry.Curve curve, FamilySymbol familySymbol)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

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

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

            return new AdaptiveComponent(parameters, ElementCurveReference.TryGetCurveReference(curve).InternalReference, familySymbol);
        }
Example #27
0
        /// <summary>
        /// Create an adaptive component by uv points on a face.
        /// </summary>
        /// <param name="uvs">An array of UV pairs</param>
        /// <param name="face">The face on which to place the AdaptiveComponent</param>
        /// <param name="face">The face on which to place the AdaptiveComponent</param>
        /// <returns></returns>
        public static AdaptiveComponent ByParametersOnFace(double[][] uvs, Face face, FamilySymbol familySymbol)
        {
            if (uvs == null)
            {
                throw new ArgumentNullException("uvs");
            }

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

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

            return new AdaptiveComponent(uvs, face, familySymbol);
        }
Example #28
0
        /// <summary>
        /// Create a Revit Structural Member - a special FamilyInstance
        /// </summary>
        /// <param name="curve">The curve path for the structural member</param>
        /// <param name="upVector">The up vector for the element - this is required to determine the orientation of the element</param>
        /// <param name="level">The level on which the member should appear</param>
        /// <param name="structuralType">The type of the structural element - a beam, column, etc</param>
        /// <param name="structuralFramingType">The structural framing type representing the structural type</param>
        /// <returns></returns>
        public static StructuralFraming ByCurveLevelUpVectorAndType(Autodesk.DesignScript.Geometry.Curve curve, Level level, 
            Autodesk.DesignScript.Geometry.Vector upVector, StructuralType structuralType, FamilySymbol structuralFramingType)
        {
            if (curve == null)
            {
                throw new System.ArgumentNullException("curve");
            }

            if (level == null)
            {
                throw new System.ArgumentNullException("level");
            }

            if (upVector == null)
            {
                throw new System.ArgumentNullException("upVector");
            }

            if (structuralFramingType == null)
            {
                throw new System.ArgumentNullException("structuralFramingType");
            }            

            return new StructuralFraming(curve.ToRevitType(), upVector.ToXyz(), level.InternalLevel,
                structuralType.ToRevitType(), structuralFramingType.InternalFamilySymbol);
        }
Example #29
0
        /// <summary>
        /// Create a Revit Structural Member - a special FamilyInstance
        /// </summary>
        /// <param name="curve">The curve path for the structural member</param>
        /// <param name="upVector">The up vector for the element - this is required to determine the orientation of the element</param>
        /// <param name="level">The level on which the member should appear</param>
        /// <param name="structuralType">The type of the structural element - a beam, column, etc</param>
        /// <param name="structuralFramingType">The structural framing type representing the structural type</param>
        /// <returns></returns>
        public static StructuralFraming ByCurveLevelUpVectorAndType(Autodesk.DesignScript.Geometry.Curve curve, Level level,
                                                                    Autodesk.DesignScript.Geometry.Vector upVector, StructuralType structuralType, FamilySymbol structuralFramingType)
        {
            if (curve == null)
            {
                throw new System.ArgumentNullException("curve");
            }

            if (level == null)
            {
                throw new System.ArgumentNullException("level");
            }

            if (upVector == null)
            {
                throw new System.ArgumentNullException("upVector");
            }

            if (structuralFramingType == null)
            {
                throw new System.ArgumentNullException("structuralFramingType");
            }

            return(new StructuralFraming(curve.ToRevitType(), upVector.ToXyz(), level.InternalLevel,
                                         structuralType.ToRevitType(), structuralFramingType.InternalFamilySymbol));
        }