コード例 #1
0
        /// <summary>
        /// Returns a list of desk Revit family instances using the Desk stored in the DeskArrangement.
        /// </summary>
        /// <param name="deskArrangement"> The DeskArrangement object.</param>
        /// <param name="deskType"> The desk type.</param>
        /// <param name="hostLevel"> The host hostLevel for the new desks.</param>
        public static List <DynamoElement> Generate(DeskArrangement deskArrangement, DynamoFamilyType deskType, DynamoLevel hostLevel)
        {
            Document doc = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(doc);

            FamilySymbol newDeskType = FamilyTypeCreator.Desk((FamilySymbol)deskType.InternalElement, deskArrangement, "AU 2019 Vegas Desk");

            // Get the Revit Document factory object from the Autodesk.Revit.DB.Creation namespace.
            // This object is used to instantiate most Revit Elements.
            var revitFactory = doc.Create;

            var revitDesks = new List <DynamoElement>();

            foreach (var desk in deskArrangement.Desks)
            {
                XYZ location       = desk.Origin.ToXyz();
                var familyInstance = revitFactory.NewFamilyInstance(location, newDeskType, hostLevel.InternalElement, StructuralType.NonStructural);

                // Wrap and bind the new desk instance.
                revitDesks.Add(familyInstance.ToDSType(false));
            }

            TransactionManager.Instance.TransactionTaskDone();

            return(revitDesks);
        }
コード例 #2
0
        public static Element ByFaceAndPoint(FamilyType familyType, Point point, Surface surface)
        {
            if (familyType == null)
            {
                throw new ArgumentNullException(nameof(familyType));
            }
            if (point == null)
            {
                throw new ArgumentNullException(nameof(point));
            }
            if (surface == null)
            {
                throw new ArgumentNullException(nameof(surface));
            }

            var symbol     = familyType.InternalElement as Autodesk.Revit.DB.FamilySymbol;
            var pt         = point.ToRevitType();
            var reference  = surface.Tags.LookupTag("RevitFaceReference") as Autodesk.Revit.DB.Reference;
            var faceNormal = surface.NormalAtPoint(point);
            var up         = Vector.ZAxis();

            Autodesk.Revit.DB.XYZ referenceDir;
            if (Math.Abs(faceNormal.Dot(up)) > 0.9999) // horizontal
            {
                referenceDir = Autodesk.Revit.DB.XYZ.BasisX;
            }
            else
            {
                referenceDir = faceNormal.Cross(up).ToXyz();
            }

            return(new FamilyInstances(symbol, pt, reference, referenceDir).InternalElement.ToDSType(true));
        }
コード例 #3
0
        public void ByPoints_PointArray_ProducesValidAdaptiveComponentAndLocations()
        {
            var pts = new Point[][]
            {
                new Point[]
                {
                    Point.ByCoordinates(0, 0, 0),
                    Point.ByCoordinates(10, 0, 10),
                    Point.ByCoordinates(20, 0, 0)
                }
            };
            var fs = FamilyType.ByName("3PointAC");
            var ac = AdaptiveComponent.ByPoints(pts, fs);

            var locs = ac.First().Locations;

            var pairs = locs.Zip(pts.First(), (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.First().Zip(GetInternalPoints((FamilyInstance)ac.First().InternalElement),
                                                   (point, point1) => new Tuple <Point, XYZ>(point, point1));

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

            Assert.NotNull(ac);
        }
コード例 #4
0
        /// <summary>
        /// Create a column.
        /// </summary>
        /// <param name="curve">The curve which defines the center line of the column.</param>
        /// <param name="level">The level with which you'd like the column to be associated.</param>
        /// <param name="structuralColumnType">The structural column type representing the column.</param>
        /// <returns></returns>
        public static StructuralFraming ColumnByCurve(
            Autodesk.DesignScript.Geometry.Curve curve, Level level, FamilyType structuralColumnType)
        {
            if (curve == null)
            {
                throw new ArgumentNullException("curve");
            }

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

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

            var start = curve.PointAtParameter(0);
            var end   = curve.PointAtParameter(1);

            // Revit will throw an exception if you attempt to create a column whose
            // base is above its top.
            if (end.Z <= start.Z)
            {
                throw new Exception(Properties.Resources.InvalidColumnBaseLocation);
            }

            return(new StructuralFraming(curve.ToRevitType(), level.InternalLevel, Autodesk.Revit.DB.Structure.StructuralType.Column, structuralColumnType.InternalFamilySymbol));
        }
コード例 #5
0
        public void Rotate_ZAxis()
        {
            var famSym  = FamilyType.ByName("Box");
            var pt      = Point.ByCoordinates(0, 1, 2);
            var famInst = FamilyInstance.ByPoint(famSym, pt);

            Assert.NotNull(famInst);

            var transform = famInst.InternalFamilyInstance.GetTransform();

            double[] rotationAngles;
            TransformUtils.ExtractEularAnglesFromTransform(transform, out rotationAngles);
            Assert.AreEqual(0.0, rotationAngles[0]);

            RevitServices.Persistence.DocumentManager.Instance.CurrentDBDocument.Regenerate();

            famInst.SetRotation(30);
            transform = famInst.InternalFamilyInstance.GetTransform();
            TransformUtils.ExtractEularAnglesFromTransform(transform, out rotationAngles);
            Assert.AreEqual(30.0, rotationAngles[0] * 180 / Math.PI, 1.0e-6);

            famInst.SetRotation(60);
            transform = famInst.InternalFamilyInstance.GetTransform();
            TransformUtils.ExtractEularAnglesFromTransform(transform, out rotationAngles);
            Assert.AreEqual(60.0, rotationAngles[0] * 180 / Math.PI, 1.0e-6);
        }
コード例 #6
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 ft = FamilyType.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(), ft);

            Assert.NotNull(ac);
        }
コード例 #7
0
        /// <summary>
        /// Set the family symbol for the internal family instance
        /// </summary>
        /// <param name="ft"></param>
        private void InternalSetFamilySymbol(FamilyType ft)
        {
            TransactionManager.Instance.EnsureInTransaction(Document);

            InternalFamilyInstance.Symbol = ft.InternalFamilySymbol;

            TransactionManager.Instance.TransactionTaskDone();
        }
コード例 #8
0
ファイル: FamilyInstance.cs プロジェクト: ziter05/DynamoRevit
        /// <summary>
        /// Place a Revit FamilyInstance given the FamilyType (also known as the FamilySymbol in the Revit API), it's coordinates in world space, and the Level
        /// </summary>
        /// <param name="familyType">Family Type. Also called Family Symbol.</param>
        /// <param name="point">Point in meters.</param>
        /// <param name="level">Level to host Family Instance.</param>
        /// <returns></returns>
        public static FamilyInstance ByPointAndLevel(FamilyType familyType, Point point, Level level)
        {
            if (familyType == null)
            {
                throw new ArgumentNullException("familyType");
            }

            return(new FamilyInstance(familyType.InternalFamilySymbol, point.ToXyz(), level.InternalLevel));
        }
コード例 #9
0
ファイル: FamilyInstance.cs プロジェクト: ziter05/DynamoRevit
        /// <summary>
        /// Place a Revit FamilyInstance given the FamilyType (also known as the FamilySymbol in the Revit API) and its coordinates in world space
        /// </summary>
        /// <param name="familyType">Family Type. Also called Family Symbol.</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(FamilyType familyType, double x = 0, double y = 0, double z = 0)
        {
            if (familyType == null)
            {
                throw new ArgumentNullException("familyType");
            }

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

            return(ByPoint(familyType, pt));
        }
コード例 #10
0
        public void ByPoints_ShouldThrowExceptionWithNonMatchingNumberOfPoints()
        {
            var pts = new Point[]
            {
                Point.ByCoordinates(0, 0, 0),
                Point.ByCoordinates(10, 0, 10)
            };
            var ft = FamilyType.ByName("3PointAC");

            Assert.Throws(typeof(ArgumentException), () => AdaptiveComponent.ByPoints(pts, ft));
        }
コード例 #11
0
        public void FacingOrientation()
        {
            var famSym  = FamilyType.ByName("Box");
            var pt      = Point.ByCoordinates(0, 1, 2);
            var famInst = FamilyInstance.ByPoint(famSym, pt);

            Assert.NotNull(famInst);

            var dir = famInst.FacingOrientation;

            dir.IsAlmostEqualTo(Vector.ByCoordinates(0.0, 0.0, 1.0));
        }
コード例 #12
0
        /// <summary>
        /// New Family Instance by Curve
        /// </summary>
        /// <param name="familyType">Family Type to be applied to new Family Instance.</param>
        /// <param name="line">Line to place Family Instance at.</param>
        /// <param name="level">Level to associate Family Instance with.</param>
        /// <returns>New Family Instance.</returns>
        public static Element ByLine(FamilyType familyType, Line line, Level level)
        {
            if (familyType == null)
            {
                throw new ArgumentNullException(nameof(familyType));
            }

            var symbol       = familyType.InternalElement as Autodesk.Revit.DB.FamilySymbol;
            var locationLine = line.ToRevitType() as Autodesk.Revit.DB.Line;
            var hostLevel    = level.InternalElement as Autodesk.Revit.DB.Level;

            return(new FamilyInstances(symbol, locationLine, hostLevel));
        }
コード例 #13
0
ファイル: FamilyInstance.cs プロジェクト: ziter05/DynamoRevit
        /// <summary>
        /// Obtain a collection of FamilyInstances from the Revit Document and use them in the Dynamo graph
        /// </summary>
        /// <param name="familyType">Family Type. Also called Family Symbol.</param>
        /// <returns></returns>
        /// <search>
        /// byfamilysymbol,ByFamilySymbol
        /// </search>
        public static FamilyInstance[] ByFamilyType(FamilyType familyType)
        {
            if (familyType == null)
            {
                throw new ArgumentNullException("familyType");
            }

            return(DocumentManager.Instance
                   .ElementsOfType <Autodesk.Revit.DB.FamilyInstance>()
                   .Where(x => x.Symbol.Id == familyType.InternalFamilySymbol.Id)
                   .Select(x => FromExisting(x, true))
                   .ToArray());
        }
コード例 #14
0
        public void CanSuccessfullySetAndGetElement()
        {
            var wall   = ElementSelector.ByElementId(184176, true);
            var famSym = FamilyType.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\"");
        }
コード例 #15
0
        public static AdaptiveComponent[] ByPoints(Point[][] points, FamilyType familyType)
        {
            if (points == null)
            {
                throw new ArgumentNullException("points");
            }

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

            return(InternalByPoints(points, familyType));
        }
コード例 #16
0
ファイル: FamilyInstance.cs プロジェクト: ziter05/DynamoRevit
        /// <summary>
        /// Place a Revit FamilyInstance given the FamilyType (also known as the FamilySymbol in the Revit API) and its coordinates in world space
        /// </summary>
        /// <param name="familyType">Family Type. Also called Family Symbol.</param>
        /// <param name="point">Point in meters.</param>
        /// <returns></returns>
        public static FamilyInstance ByPoint(FamilyType familyType, Point point)
        {
            if (familyType == null)
            {
                throw new ArgumentNullException("familyType");
            }

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

            return(new FamilyInstance(familyType.InternalFamilySymbol, point.ToXyz()));
        }
コード例 #17
0
        public static Revit.Elements.FamilyInstance ChangeType(
            Revit.Elements.FamilyInstance familyInstance,
            Revit.Elements.FamilyType familyType)
        {
            // Unwrap input parameters
            Autodesk.Revit.DB.FamilyInstance instance    = familyInstance.InternalElement as Autodesk.Revit.DB.FamilyInstance;
            Autodesk.Revit.DB.Element        anotherType = familyType.InternalElement;

            TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
            instance.ChangeTypeId(anotherType.Id);
            TransactionManager.Instance.TransactionTaskDone();

            return(familyInstance);
        }
コード例 #18
0
ファイル: FamilyInstance.cs プロジェクト: ziter05/DynamoRevit
        /// <summary>
        /// Place a Revit FamilyInstance given the FamilyType (also known as the FamilySymbol in the Revit API) and its coordinate system.
        /// </summary>
        /// <param name="familyType">Family Type. Also called Family Symbol.</param>
        /// <param name="coordinateSystem">Coordinates system to place the new family instance in.</param>
        /// <returns>New family instance.</returns>
        public static FamilyInstance ByCoordinateSystem(FamilyType familyType, CoordinateSystem coordinateSystem)
        {
            var transform = coordinateSystem.ToTransform() as Autodesk.Revit.DB.Transform;

            double[] newRotationAngles;
            TransformUtils.ExtractEularAnglesFromTransform(transform, out newRotationAngles);
            double rotation = ConvertEularToAngleDegrees(newRotationAngles.FirstOrDefault());
            Point  location = transform.ToCoordinateSystem().Origin;

            FamilyInstance familyInstance = ByPoint(familyType, location);

            familyInstance.SetRotation(rotation);

            return(familyInstance);
        }
コード例 #19
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 ft = FamilyType.ByName("3PointAC");

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

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

            // 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);
        }
コード例 #20
0
        public void ByCoordinates_ProducesValidFamilyInstanceWithCorrectLocation()
        {
            var famSym  = FamilyType.ByName("Box");
            var famInst = FamilyInstance.ByCoordinates(famSym, 0, 1, 2);

            Assert.NotNull(famInst);

            var position = famInst.Location;

            position.ShouldBeApproximately(Point.ByCoordinates(0, 1, 2));

            // no unit conversion
            var internalPos =
                InternalLocation(famInst.InternalElement as Autodesk.Revit.DB.FamilyInstance);

            (internalPos * UnitConverter.HostToDynamoFactor(SpecTypeId.Length)).ShouldBeApproximately(
                Point.ByCoordinates(0, 1, 2));
        }
コード例 #21
0
ファイル: FamilyInstance.cs プロジェクト: ziter05/DynamoRevit
        /// <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()));
        }
コード例 #22
0
        /// <summary>
        /// Initialize an AdaptiveComponent element
        /// </summary>
        /// <param name="pts">Points to use as reference</param>
        /// <param name="ft">familyType to place</param>
        private void InitAdaptiveComponent(Point[] pts, 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);
                }
                InternalSetPositions(pts.ToXyzs());

                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);
                    InternalSetPositions(pts.ToXyzs());
                    st.Commit();
                }
                catch (Exception ex)
                {
                    st.RollBack();
                    throw new ArgumentException(Revit.Properties.Resources.Adaptive_Component_Creation_Failed + ex.Message);
                }
            }

            TransactionManager.Instance.TransactionTaskDone();

            // remember this value
            ElementBinder.SetElementForTrace(this.InternalElement);
        }
コード例 #23
0
ファイル: FamilyInstances.cs プロジェクト: jpahlow/archilab
        /// <summary>
        ///
        /// </summary>
        /// <param name="familyType"></param>
        /// <param name="point"></param>
        /// <param name="view"></param>
        /// <returns></returns>
        public static Element ByView(FamilyType familyType, Point point, View view)
        {
            if (familyType == null)
            {
                throw new ArgumentNullException(nameof(familyType));
            }
            if (point == null)
            {
                throw new ArgumentNullException(nameof(point));
            }
            if (view == null)
            {
                throw new ArgumentNullException(nameof(view));
            }

            var symbol = familyType.InternalElement as Autodesk.Revit.DB.FamilySymbol;
            var pt     = point.ToRevitType();
            var v      = view.InternalElement as Autodesk.Revit.DB.View;

            return(new FamilyInstances(symbol, pt, v));
        }
コード例 #24
0
        public static Element ByHostAndPoint(FamilyType familyType, Point point, Element host)
        {
            if (familyType == null)
            {
                throw new ArgumentNullException(nameof(familyType));
            }
            if (point == null)
            {
                throw new ArgumentNullException(nameof(point));
            }
            if (host == null)
            {
                throw new ArgumentNullException(nameof(host));
            }

            var doc    = DocumentManager.Instance.CurrentDBDocument;
            var symbol = familyType.InternalElement as Autodesk.Revit.DB.FamilySymbol;
            var pt     = point.ToRevitType();
            var h      = host.InternalElement;
            var level  = doc.GetElement(h.LevelId) as Autodesk.Revit.DB.Level;

            return(new FamilyInstances(symbol, pt, h, level).InternalElement.ToDSType(true));
        }
コード例 #25
0
ファイル: FamilyInstance.cs プロジェクト: ziter05/DynamoRevit
        /// <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()));
        }
コード例 #26
0
        public void ByPoints_NullPts()
        {
            var ft = FamilyType.ByName("3PointAC");

            Assert.Throws(typeof(ArgumentNullException), () => AdaptiveComponent.ByPoints(null, ft));
        }
コード例 #27
0
 public static FamilyType Wrap(Autodesk.Revit.DB.FamilySymbol ele, bool isRevitOwned)
 {
     return(FamilyType.FromExisting(ele, isRevitOwned));
 }
コード例 #28
0
        /// <summary>
        /// Create a list of adaptive components from two-dimensional array of points
        /// </summary>
        /// <param name="points">a two-dimensional array of points</param>
        /// <param name="familyType">a family type to use to create the adaptive components</param>
        /// <returns></returns>
        private static AdaptiveComponent[] InternalByPoints(Point[][] points, FamilyType familyType)
        {
            var oldInstances        = ElementBinder.GetElementsFromTrace <Autodesk.Revit.DB.FamilyInstance>(Document);
            int countToBeCreated    = points.Count();
            int countOfOldInstances = 0;

            if (oldInstances != null)
            {
                countOfOldInstances = oldInstances.Count();
            }
            int reusableCount = Math.Min(countToBeCreated, countOfOldInstances);

            TransactionManager.Instance.EnsureInTransaction(Document);

            List <Autodesk.Revit.DB.FamilyInstance> instances = new List <Autodesk.Revit.DB.FamilyInstance>();
            List <AdaptiveComponent> components = new List <AdaptiveComponent>();

            try
            {
                // Reuse the adaptive components that can be reused if possible
                for (int i = 0; i < reusableCount; i++)
                {
                    var fi   = oldInstances.ElementAt(i);
                    var comp = new AdaptiveComponent(fi);
                    components.Add(comp);

                    //Update the family symbol
                    if (familyType.InternalFamilySymbol.Id != fi.Symbol.Id)
                    {
                        fi.Symbol = familyType.InternalFamilySymbol;
                    }

                    UpdatePlacementPoints(fi, points[i].ToXyzs());
                    instances.Add(fi);
                }

                // Delete the redundant adaptive components if any
                for (int i = reusableCount; i < countOfOldInstances; i++)
                {
                    var fi = oldInstances.ElementAt(i);
                    Document.Delete(fi.Id);
                }

                // Create new adaptive components
                if (countToBeCreated > countOfOldInstances)
                {
                    var remainingPoints = points.Skip(reusableCount).ToArray();
                    // Prepare the creation data for batch processing
                    int numOfComponents = remainingPoints.Count();
                    List <FamilyInstanceCreationData> creationDatas = new List <FamilyInstanceCreationData>(numOfComponents);
                    for (int i = 0; i < numOfComponents; ++i)
                    {
                        int numOfPoints = remainingPoints[i].Length;
                        var aPoints     = remainingPoints[i].ToXyzs();

                        var creationData = DocumentManager.Instance.CurrentUIApplication.Application.Create.
                                           NewFamilyInstanceCreationData(familyType.InternalFamilySymbol, aPoints);

                        if (creationData != null)
                        {
                            creationDatas.Add(creationData);
                        }
                    }

                    // Create elements based on the creation data in a batch
                    ICollection <ElementId> elements;
                    if (creationDatas.Count > 0)
                    {
                        if (Document.IsFamilyDocument)
                        {
                            elements = DocumentManager.Instance.CurrentDBDocument.FamilyCreate.NewFamilyInstances2(creationDatas);
                        }
                        else
                        {
                            elements = DocumentManager.Instance.CurrentDBDocument.Create.NewFamilyInstances2(creationDatas);
                        }

                        foreach (var id in elements)
                        {
                            Autodesk.Revit.DB.FamilyInstance instance;
                            if (ElementUtils.TryGetElement <Autodesk.Revit.DB.FamilyInstance>(
                                    DocumentManager.Instance.CurrentDBDocument, id, out instance))
                            {
                                instances.Add(instance);
                                components.Add(new AdaptiveComponent(instance));
                            }
                        }
                    }
                }

                ElementBinder.SetElementsForTrace(instances);
            }
            catch (Exception e)
            {
                // Unregister the elements from the element life cycle manager and delete the elements
                var elementManager = ElementIDLifecycleManager <int> .GetInstance();

                foreach (var component in components)
                {
                    elementManager.UnRegisterAssociation(component.InternalElementId.IntegerValue, component);
                }
                foreach (var instance in instances)
                {
                    Document.Delete(instance.Id);
                }

                if (e is Autodesk.Revit.Exceptions.ArgumentException)
                {
                    throw new ArgumentException("The arguments have issues", e);
                }
                else
                {
                    throw e;
                }
            }
            finally
            {
                TransactionManager.Instance.TransactionTaskDone();
            }

            return(components.ToArray());
        }
コード例 #29
0
 /// <summary>
 /// Internal constructor for the AdaptiveComponent wrapper
 /// </summary>
 /// <param name="parms">Params on curve to reference</param>
 /// <param name="c">Curve to use as reference</param>
 /// <param name="ft">familyType to place</param>
 private AdaptiveComponent(double[] parms, Reference c, FamilyType ft)
 {
     SafeInit(() => InitAdaptiveComponent(parms, c, ft));
 }
コード例 #30
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="familyType">The family type to construct</param>
        /// <returns></returns>
        public static AdaptiveComponent ByParametersOnCurveReference(double[] parameters, Autodesk.DesignScript.Geometry.Curve curve, FamilyType familyType)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

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

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

            return(new AdaptiveComponent(parameters, ElementCurveReference.TryGetCurveReference(curve).InternalReference, familyType));
        }