Exemple #1
0
        public new void Tessellate(IRenderPackage package, TessellationParameters parameters)
        {
            //Ensure that the object is still alive
            if (!IsAlive)
            {
                return;
            }

            //Location Point
            DB.LocationPoint locPoint = InternalElement.Location as DB.LocationPoint;
            GeometryPrimitiveConverter.ToPoint(InternalTransform.OfPoint(locPoint.Point)).Tessellate(package, parameters);
            package.ApplyPointVertexColors(CreateColorByteArrayOfSize(package.LineVertexCount, 255, 0, 0, 0));

            //Boundaries
            foreach (DB.BoundarySegment segment in InternalBoundarySegments)
            {
                Curve crv = RevitToProtoCurve.ToProtoType(segment.GetCurve().CreateTransformed(InternalTransform));

                crv.Tessellate(package, parameters);

                if (package.LineVertexCount > 0)
                {
                    package.ApplyLineVertexColors(CreateColorByteArrayOfSize(package.LineVertexCount, 255, 0, 0, 0));
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Creates a Revit ViewSection by a specified corrdinate system, minPoint and maxPoint
 /// </summary>
 /// <param name="cs"></param>
 /// <param name="minPoint"></param>
 /// <param name="maxPoint"></param>
 /// <returns></returns>
 public static SectionView ByCoordinateSystemMinPointMaxPoint(
     Autodesk.DesignScript.Geometry.CoordinateSystem cs,
     Autodesk.DesignScript.Geometry.Point minPoint,
     Autodesk.DesignScript.Geometry.Point maxPoint)
 {
     return(new SectionView(GeometryPrimitiveConverter.ToRevitBoundingBox(cs, minPoint, maxPoint)));
 }
Exemple #3
0
        /// <summary>
        /// Create a `MEP Space
        /// based on a location
        /// </summary>
        /// <param name="point">Location point for the space</param>
        /// <returns></returns>
        public static Space ByPoint(Point point)
        {
            DB.XYZ   revitPoint = GeometryPrimitiveConverter.ToXyz(point);
            DB.Level revitLevel = GetNearestLevel(revitPoint);

            DB.UV uv = new DB.UV(revitPoint.X, revitPoint.Y);

            return(new Space(revitLevel, uv));
        }
Exemple #4
0
        /// <summary>
        /// Create a Room
        /// based on a location and a level
        /// </summary>
        /// <param name="point">Location point for the room</param>
        /// <param name="level">Level of the room</param>
        /// <returns></returns>
        public static CustomRoom ByPointAndLevel(Point point, Level level)
        {
            DB.Level revitLevel = level.InternalElement as DB.Level;
            DB.XYZ   revitPoint = GeometryPrimitiveConverter.ToXyz(point);

            DB.UV uv = new DB.UV(revitPoint.X, revitPoint.Y);

            return(new CustomRoom(revitLevel, uv));
        }
Exemple #5
0
        /// <summary>
        /// Create a MEP Space
        /// based on a location and a level
        /// </summary>
        /// <param name="point">Location point for the space</param>
        /// <param name="level">Level of the space</param>
        /// <returns></returns>
        public static Space ByPointAndLevel(Point point, Level level)
        {
            //Check if the level is in the document
            if (level.InternalElement.Document != DocumentManager.Instance.CurrentDBDocument)
            {
                throw new ArgumentException("The level does not exist in the given document");
            }

            DB.Level revitLevel = level.InternalElement as DB.Level;
            DB.XYZ   revitPoint = GeometryPrimitiveConverter.ToXyz(point);

            DB.UV uv = new DB.UV(revitPoint.X, revitPoint.Y);

            return(new Space(revitLevel, uv));
        }
        /// <summary>
        /// Initialize a ScheduleOnSheet element
        /// </summary>
        /// <param name="sheet"></param>
        /// <param name="scheduleView"></param>
        /// <param name="location"></param>
        private void InitScheduleOnSheet(Sheet sheet, Revit.Elements.Views.ScheduleView scheduleView, Autodesk.DesignScript.Geometry.Point location)
        {
            ElementId sheetId          = sheet.InternalView.Id;
            ElementId scheduleViewId   = scheduleView.InternalView.Id;
            XYZ       scheduleLocation = GeometryPrimitiveConverter.ToRevitType(location);

            TransactionManager.Instance.EnsureInTransaction(Document);

            var scheduleOnSheetElement = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.ScheduleSheetInstance>(Document);

            scheduleOnSheetElement = Autodesk.Revit.DB.ScheduleSheetInstance.Create(Document, sheetId, scheduleViewId, scheduleLocation);

            InternalSetScheduleOnSheet(scheduleOnSheetElement);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.CleanupAndSetElementForTrace(Document, this.InternalElement);
        }
Exemple #7
0
        /// <summary>
        /// Creates a new Viewport at a given location on a sheet.
        /// </summary>
        /// <param name="sheet">The Sheet on which the new Viewport will be placed.</param>
        /// <param name="view">The view shown in the Viewport.</param>
        /// <param name="location">The new Viewport will be centered on this point.</param>
        /// <returns>The new Viewport.</returns>
        public static Viewport BySheetViewLocation(Sheet sheet, Revit.Elements.Views.View view, Autodesk.DesignScript.Geometry.Point location)
        {
            ElementId sheetId      = sheet.InternalView.Id;
            ElementId viewId       = view.InternalView.Id;
            XYZ       viewLocation = GeometryPrimitiveConverter.ToRevitType(location);

            if (!Autodesk.Revit.DB.Viewport.CanAddViewToSheet(Document, sheetId, viewId))
            {
                throw new InvalidOperationException(Properties.Resources.ViewAlreadyPlacedOnSheet);
            }
            if (IsViewEmpty(view.InternalView))
            {
                throw new InvalidOperationException(Properties.Resources.EmptyView);
            }

            TransactionManager.Instance.EnsureInTransaction(Document);
            var viewport = Autodesk.Revit.DB.Viewport.Create(Document, sheetId, viewId, viewLocation);

            TransactionManager.Instance.TransactionTaskDone();
            return(viewport.ToDSType(true) as Viewport);
        }
Exemple #8
0
        /// <summary>
        /// Return a grid of points in the space
        /// </summary>
        /// <param name="step">Lenght between two points</param>
        public List <Point> Grid(double step)
        {
            step = UnitConverter.DynamoToHostFactor(DB.UnitType.UT_Length) * step;
            List <Point> grid = new List <Point>();

            DB.BoundingBoxXYZ bb = InternalElement.get_BoundingBox(null);

            for (double x = bb.Min.X; x < bb.Max.X;)
            {
                for (double y = bb.Min.Y; y < bb.Max.Y;)
                {
                    DB.XYZ point = new DB.XYZ(x, y, bb.Min.Z);
                    if (InternalSpace.IsPointInSpace(point))
                    {
                        grid.Add(GeometryPrimitiveConverter.ToPoint(InternalTransform.OfPoint(point)));
                    }
                    y = y + step;
                }

                x = x + step;
            }

            return(grid);
        }
        public void ToRevitBoundingBox_Method_PreservesValues()
        {
            var csOrigin = Point.ByCoordinates(1, 2, 3);
            var csX      = Vector.ByCoordinates(0, 1, 0);
            var csY      = Vector.ByCoordinates(0, 0, 1);

            var cs = CoordinateSystem.ByOriginVectors(csOrigin, csX, csY);

            var minPoint = Point.ByCoordinates(-2, -2, -2);
            var maxPoint = Point.ByCoordinates(2, 2, 2);

            Autodesk.Revit.DB.BoundingBoxXYZ boundingBoxXYZ = GeometryPrimitiveConverter.ToRevitBoundingBox(
                cs,
                minPoint,
                maxPoint);

            boundingBoxXYZ.Min.ShouldBeApproximately(minPoint.InHostUnits());
            boundingBoxXYZ.Max.ShouldBeApproximately(maxPoint.InHostUnits());

            boundingBoxXYZ.Transform.Origin.ShouldBeApproximately(csOrigin.InHostUnits());

            boundingBoxXYZ.Transform.BasisX.ShouldBeApproximately(csX);
            boundingBoxXYZ.Transform.BasisY.ShouldBeApproximately(csY);
        }
Exemple #10
0
        /// <summary>
        /// Initialize a Viewport element
        /// </summary>
        /// <param name="sheet"></param>
        /// <param name="view"></param>
        /// <param name="location"></param>
        private void InitViewport(Sheet sheet, Revit.Elements.Views.View view, Autodesk.DesignScript.Geometry.Point location)
        {
            ElementId sheetId      = sheet.InternalView.Id;
            ElementId viewId       = view.InternalView.Id;
            XYZ       viewLocation = GeometryPrimitiveConverter.ToRevitType(location);

            TransactionManager.Instance.EnsureInTransaction(Document);

            var viewportElement = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.Viewport>(Document);

            if (viewportElement == null)
            {
                if (!Autodesk.Revit.DB.Viewport.CanAddViewToSheet(Document, sheetId, viewId))
                {
                    throw new InvalidOperationException(Properties.Resources.ViewAlreadyPlacedOnSheet);
                }
                viewportElement = Autodesk.Revit.DB.Viewport.Create(Document, sheetId, viewId, viewLocation);
            }
            else
            {
                if (!Autodesk.Revit.DB.Viewport.CanAddViewToSheet(Document, sheetId, viewId))
                {
                    viewportElement.SetBoxCenter(viewLocation);
                }
                else
                {
                    viewportElement = Autodesk.Revit.DB.Viewport.Create(Document, sheetId, viewId, viewLocation);
                }
            }

            InternalSetViewport(viewportElement);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.CleanupAndSetElementForTrace(Document, this.InternalElement);
        }
Exemple #11
0
        public static Dictionary <string, object> InstanceByPointAndHost(Point point, FamilyType familyType, Element host)
        {
            AD.Document     currentDBDocument = DocumentManager.Instance.CurrentDBDocument;
            AD.XYZ          xYZ          = GeometryPrimitiveConverter.ToXyz(point, true);
            AD.FamilySymbol familySymbol = (AD.FamilySymbol)(familyType.InternalElement);
            if (!familySymbol.IsActive)
            {
                familySymbol.Activate();
            }
            AD.Element element = host.InternalElement;
            AD.Level   level   = element.Document.GetElement(element.LevelId) as AD.Level;
            TransactionManager.Instance.EnsureInTransaction(currentDBDocument);
            AD.FamilyInstance element2 = currentDBDocument.Create.NewFamilyInstance(xYZ, familySymbol, element, level, 0);
            var ele = element2.ToDSType(false);

            TransactionManager.Instance.TransactionTaskDone();
            return(new Dictionary <string, object>
            {
                {
                    "FamilyInstance",
                    ele
                }
            });
        }
Exemple #12
0
        /// <summary>
        /// Place an instance of a Revit group
        /// </summary>
        /// <param name="point">Location point for the group instance</param>
        /// <param name="groupType">The type of the group</param>
        /// <returns></returns>
        public static Group PlaceGroupInstance(Point point, GroupType groupType)
        {
            DB.XYZ revitPoint = GeometryPrimitiveConverter.ToXyz(point);

            return(new Group(revitPoint, groupType.InternalGroupType));
        }