Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }