示例#1
0
        /// <summary>
        /// This node will place the given view on the given sheet, if possible. For floor plan views: They cannot be on any other sheets. Now supports schedules!
        /// </summary>
        /// <param name="sheet">The sheet to place views on.</param>
        /// <param name="view">The view to place.</param>
        /// <param name="location">The location of the view.</param>
        /// <returns name="Result">The result</returns>
        /// <search>
        /// viewport, addview,rhythm
        /// </search>
        public static global::Revit.Elements.Element Create(global::Revit.Elements.Views.Sheet sheet, global::Revit.Elements.Element view, Autodesk.DesignScript.Geometry.Point location)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            //obtain the element id from the sheet
            ElementId sheetId = new ElementId(sheet.Id);

            global::Revit.Elements.Element result = null;

            if (view.InternalElement.ToString() == "Autodesk.Revit.DB.ViewSchedule")
            {
                //obtain the element id from the view
                ElementId viewId = new ElementId(view.Id);
                //chane the dynamo point to a revit point
                var revitPoint = location.ToRevitType(true);
                //start the transaction to place views
                TransactionManager.Instance.EnsureInTransaction(doc);
                result = Autodesk.Revit.DB.ScheduleSheetInstance.Create(doc, sheetId, viewId, revitPoint).ToDSType(true);
                TransactionManager.Instance.TransactionTaskDone();
            }
            else
            {
                //obtain the element id from the view
                ElementId viewId = new ElementId(view.Id);
                //chane the dynamo point to a revit point
                var revitPoint = location.ToRevitType(true);
                //start the transaction to place views
                TransactionManager.Instance.EnsureInTransaction(doc);
                result = Autodesk.Revit.DB.Viewport.Create(doc, sheetId, viewId, revitPoint).ToDSType(true);
                TransactionManager.Instance.TransactionTaskDone();
            }

            return(result);
        }
示例#2
0
        public static object Create(global::Revit.Elements.Views.Sheet sheet, global::Revit.Elements.Element view, Autodesk.DesignScript.Geometry.Point location)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            //obtain the element id from the sheet
            ElementId sheetId = new ElementId(sheet.Id);

            Autodesk.Revit.DB.Element result = null;
            //change the dynamo point to a revit point
            var revitPoint = location.ToRevitType(true);
            //obtain the element id from the view
            ElementId viewId = new ElementId(view.Id);



            try
            {
                //start the transaction to place views
                TransactionManager.Instance.EnsureInTransaction(doc);
                if (view.InternalElement.ToString() == "Autodesk.Revit.DB.ViewSchedule")
                {
                    result = Autodesk.Revit.DB.ScheduleSheetInstance.Create(doc, sheetId, viewId, revitPoint);
                }
                else
                {
                    result = Autodesk.Revit.DB.Viewport.Create(doc, sheetId, viewId, revitPoint);
                }

                TransactionManager.Instance.TransactionTaskDone();

                return(result.ToDSType(true));
            }
            catch (Exception e)
            {
                if (!Autodesk.Revit.DB.Viewport.CanAddViewToSheet(doc, sheetId, viewId))
                {
                    return("Error: View " + view.Id + " cannot be added to the sheet because it is already on another sheet.");
                }
                if (result == null)
                {
                    return("Error: View " + view.Id + " cannot be added to the sheet because it is empty.");
                }

                return("Error: View " + view.Id + e.Message);
            }
        }