Exemplo n.º 1
0
        public static IList<ViewBox> GetViewBoxes(ViewSheet vs)
        {
            ISet<ElementId> views = vs.GetAllPlacedViews();
            List<ViewBox> boxes = new List<ViewBox>();

            foreach (ElementId id in views)
            {
                View v = vs.Document.GetElement(id) as View;
                switch (v.ViewType)
                {
                    case ViewType.AreaPlan:
                    case ViewType.CeilingPlan:
                    case ViewType.Elevation:
                    case ViewType.EngineeringPlan:
                    case ViewType.FloorPlan:
                    case ViewType.Section:
                    case ViewType.ThreeD:
                        ViewBox box = GetViewBox(v);
                        if (box != null) boxes.Add(box);
                        break;
                    default:
                        // skip
                        break;
                }

            }
            return boxes;
        }
Exemplo n.º 2
0
        public List <ViewSheet> GetViewSheets(Document doc)
        {
            List <ViewSheet>         viewSheets = new List <ViewSheet>();
            FilteredElementCollector col        = new FilteredElementCollector(doc).WhereElementIsNotElementType().OfClass(typeof(ViewSheet));
            var bn = col.ToElements();

            foreach (var i in bn)
            {
                ViewSheet sheet = i as ViewSheet;
                if (sheet.SheetNumber.Contains("PC12"))
                {
                    viewSheets.Add(sheet);
                }
            }
            return(viewSheets);
        }
Exemplo n.º 3
0
        /*private void extractViewsonSheets(Document _source)
         * {
         *  foreach (Element vs in this.sourceSheets)
         *  {
         *      //ICollection<ViewDrafting> placedViews = getViewsOnSheets(vs, _source);
         *      this.sourceViews = getViewsPlacedOnSheets(vs, _source);
         *
         *  }
         * }*/

        private ICollection <Viewport> getViewPortsOnSheets(Element _sheet, Document _source)
        {
            ViewSheet currentSheet = _sheet as ViewSheet;
            ICollection <ElementId> placedViewports = currentSheet.GetAllViewports();
            List <Viewport>         viewPorts       = new List <Viewport>();

            foreach (ElementId eId in placedViewports)
            {
                Element temp = _source.GetElement(eId);
                if (temp.GetType().ToString() == "Autodesk.Revit.DB.Viewport")
                {
                    viewPorts.Add(temp as Viewport);
                }
            }
            return(viewPorts);
        }
Exemplo n.º 4
0
        private IEnumerable <ViewDrafting> getViewsOnSheets(Element _sheet, Document _source)
        {
            ViewSheet currentSheet = _sheet as ViewSheet;
            ICollection <ElementId> placedViews = currentSheet.GetAllPlacedViews();
            List <ViewDrafting>     views       = new List <ViewDrafting>();

            foreach (ElementId eId in placedViews)
            {
                Element temp = _source.GetElement(eId);
                if (temp.GetType().ToString() == "Autodesk.Revit.DB.ViewDrafting")
                {
                    views.Add(temp as ViewDrafting);
                }
            }
            return(views);
        }
Exemplo n.º 5
0
        // collect viewports on sheet
        public static List <Element> GetAllViewport(Document doc, ViewSheet viewSheet)
        {
            List <Element> vList = new List <Element>();

            foreach (ElementId vId in viewSheet.GetAllViewports())
            {
                // legend views viewports don´t have detail number so don´t include in the list
                Viewport vp = doc.GetElement(vId) as Viewport;
                View     v  = doc.GetElement(vp.ViewId) as View;
                if (v.ViewType != ViewType.Legend)
                {
                    vList.Add(doc.GetElement(vId));
                }
            }
            return(vList);
        }
Exemplo n.º 6
0
 public MySheet(MySheet oldSheet)
 {
     sheet            = oldSheet.sheet;
     SheetNumberInt   = oldSheet.SheetNumberInt;
     revitPaperSize   = oldSheet.revitPaperSize;
     windowsPaperSize = oldSheet.windowsPaperSize;
     pSetting         = oldSheet.pSetting;
     IsVertical       = oldSheet.IsVertical;
     SheetId          = oldSheet.sheet.Id.IntegerValue;
     IsPrintable      = oldSheet.IsPrintable;
     titleBlocks      = oldSheet.titleBlocks;
     widthMm          = oldSheet.widthMm;
     heigthMm         = oldSheet.heigthMm;
     ForceColored     = oldSheet.ForceColored;
     PdfFileName      = oldSheet.PdfFileName;
 }
        private Autodesk.Revit.DB.ViewSheet createViewSheet(string viewNumber, string viewName, string titleBlockName)
        {
            ElementId titleBlocktId = GetTitleBlockIdByName(requestData.titleBlockName);

            if (titleBlocktId == null)
            {
                titleBlocktId = new ElementId(-1);
            }

            ViewSheet norViewSheet = ViewSheet.Create(doc, titleBlocktId);

            norViewSheet.SheetNumber = viewNumber;
            norViewSheet.Name        = viewName;

            return(norViewSheet);
        }
Exemplo n.º 8
0
        //Checks to see if a viewport with a specific detail number already exists
        private bool CheckViewport(string _detailNumber, ViewSheet _vs)
        {
            ParameterValueProvider    pvp = new ParameterValueProvider(new ElementId(BuiltInParameter.VIEWPORT_DETAIL_NUMBER));
            FilterStringRuleEvaluator fsr = new FilterStringEquals();
            FilterRule             fRule  = new FilterStringRule(pvp, fsr, _detailNumber, true);
            ElementParameterFilter filter = new ElementParameterFilter(fRule);

            if (new FilteredElementCollector(doc, _vs.Id).OfCategory(BuiltInCategory.OST_Viewports).WherePasses(filter).FirstOrDefault() is Viewport vp)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Generate sheet in active document.
        /// </summary>
        /// <param name="doc">the currently active document</param>
        public void GenerateSheet(Document doc)
        {
            if (null == doc)
            {
                throw new ArgumentNullException("doc");
            }

            if (0 == m_selectedViews.Size)
            {
                throw new InvalidOperationException("No view be selected, generate sheet be canceled.");
            }
            ViewSheet sheet = ViewSheet.Create(doc, m_titleBlock.Id);

            sheet.Name = SheetName;
            PlaceViews(m_selectedViews, sheet);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public virtual Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData
                                                        , ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Autodesk.Revit.DB.Document doc = commandData.Application.ActiveUIDocument.Document;

            // get one sheet view to place panel schedule.
            ViewSheet sheet = doc.ActiveView as ViewSheet;

            if (null == sheet)
            {
                message = "please go to a sheet view.";
                return(Result.Failed);
            }

            // get all PanelScheduleView instances in the Revit document.
            FilteredElementCollector fec = new FilteredElementCollector(doc);
            ElementClassFilter       PanelScheduleViewsAreWanted = new ElementClassFilter(typeof(PanelScheduleView));

            fec.WherePasses(PanelScheduleViewsAreWanted);
            List <Element> psViews = fec.ToElements() as List <Element>;

            Transaction placePanelScheduleOnSheet = new Transaction(doc, "placePanelScheduleOnSheet");

            placePanelScheduleOnSheet.Start();

            XYZ nextOrigin = new XYZ(0.0, 0.0, 0.0);

            foreach (Element element in psViews)
            {
                PanelScheduleView psView = element as PanelScheduleView;
                if (psView.IsPanelScheduleTemplate())
                {
                    // ignore the PanelScheduleView instance which is a template.
                    continue;
                }

                PanelScheduleSheetInstance onSheet = PanelScheduleSheetInstance.Create(doc, psView.Id, sheet);
                onSheet.Origin = nextOrigin;
                BoundingBoxXYZ bbox  = onSheet.get_BoundingBox(doc.ActiveView);
                double         width = bbox.Max.X - bbox.Min.X;
                nextOrigin = new XYZ(onSheet.Origin.X + width, onSheet.Origin.Y, onSheet.Origin.Z);
            }

            placePanelScheduleOnSheet.Commit();

            return(Result.Succeeded);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Finds all the views in the active document.
        /// </summary>
        /// <param name="doc">the active document</param>
        ///

        /// <summary>
        /// Assort all views for tree view displaying.
        /// </summary>
        /// <param name="view">The view assorting</param>
        /// <param name="type">The type of view</param>



        /// <summary>
        /// Generate sheet in active document.
        /// </summary>
        /// <param name="doc">the currently active document</param>
        public void GenerateSheet(Document doc)
        {
            Autodesk.Revit.DB.View viewcur = doc.ActiveView;
            if (null == doc)
            {
                throw new ArgumentNullException("doc");
            }

            if (null == viewcur)
            {
                throw new InvalidOperationException("No view be selected, generate sheet be canceled.");
            }
            ViewSheet sheet = ViewSheet.Create(doc, m_titleBlock.Id);

            sheet.Name = SheetName;
            PlaceView(viewcur, sheet);
        }
        // lay sheetname
        public string GetSheetName(ViewSheet viewSheet)
        {
            Document document       = viewSheet.Document;
            string   text           = viewSheet.SheetNumber + "-" + viewSheet.Name;
            bool     isAssemblyView = viewSheet.IsAssemblyView;

            if (isAssemblyView)
            {
                AssemblyInstance assemblyInstance = document.GetElement(viewSheet.AssociatedAssemblyInstanceId) as AssemblyInstance;
                bool             flag             = assemblyInstance != null;
                if (flag)
                {
                    text = text + "-" + assemblyInstance.AssemblyTypeName;
                }
            }
            return(text);
        }
Exemplo n.º 13
0
        void CopyView(Viewport viewport, ViewSheet newSheet)
        {
            var viewId = viewport.ViewId;
            var view   = doc.GetElement(viewport.ViewId) as View;
            var point  = viewport.GetBoxCenter();

            if (view.ViewType == ViewType.Legend)
            {
                Viewport.Create(doc, newSheet.Id, viewId, point);
                return;
            }
            else
            {
                var duplicatedViewId = view.Duplicate(ViewDuplicateOption.WithDetailing);
                Viewport.Create(doc, newSheet.Id, duplicatedViewId, point);
            }
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;

            Doc = uidoc.Document;
            Selection selection = uidoc.Selection;

            InstanceList = CegFindImportInstance.Instance.GetImportInsntaceInfors(Doc);
            using (FindImportInstanceForm form = new FindImportInstanceForm(this))
            {
                if (form.ShowDialog() != DialogResult.OK)
                {
                    return(Result.Cancelled);
                }
            }
            if (GotoView && ViewId != ElementId.InvalidElementId)
            {
                View view = Doc.GetElement(ViewId) as View;
                if (view != null)
                {
                    uidoc.ActiveView = view;
                }
            }
            if (GotoSheet && SheetId != ElementId.InvalidElementId)
            {
                ViewSheet viewSheet = Doc.GetElement(SheetId) as ViewSheet;
                if (viewSheet != null)
                {
                    uidoc.ActiveView = viewSheet;
                }
            }

            if (ImportId != ElementId.InvalidElementId)
            {
                selection.SetElementIds(new List <ElementId> {
                    ImportId
                });
            }
            return(Result.Succeeded);
        }
Exemplo n.º 15
0
        //This is where all of the work is done, and the Data is the information supplied by Revit when new elemnts are created
        public void Execute(UpdaterData data)
        {
            //Get the current Document
            Document doc = data.GetDocument();

            //You can Cycle through the AddedElementIds or the Deleted or Modified
            foreach (ElementId addedElemId in data.GetAddedElementIds()) //data.GetDeletedElementIds, data.GetModifiedElementIds
            {
                //Cast the ElmentIds to the type of element you are working with, Sheets here
                ViewSheet sheet = doc.GetElement(addedElemId) as ViewSheet;
                //This form will ask the User to Input the Name and Number of the New sheet during creation
                using (Forms.ViewSheetUpdaterForm form = new Forms.ViewSheetUpdaterForm(doc, sheet))
                {
                    //Show the form as a modal dialog. This means that it is "Owned" by the Main Window in revit and is the thing active
                    form.ShowDialog();
                }
            }
        }
        public Dictionary <string, ViewSheet> GetViewSheets(Document doc)
        {
            Dictionary <string, ViewSheet> viewSheets = new Dictionary <string, ViewSheet>();
            var col = new FilteredElementCollector(doc).WhereElementIsNotElementType().OfClass(typeof(ViewSheet)).Cast <ViewSheet>().ToList();

            col.OrderBy(x => x.Name).ToList();
            foreach (var i in col)
            {
                ViewSheet sheet    = i as ViewSheet;
                var       nameview = sheet.SheetNumber + " - " + sheet.Name;
                if (viewSheets.ContainsKey(nameview))
                {
                    continue;
                }
                viewSheets.Add(nameview, sheet);
            }
            return(viewSheets);
        }
Exemplo n.º 17
0
        // add an empty sheet to the doc.
        // this comes first before copying titleblock, views etc.
        public ViewSheet AddEmptySheetToDocument(
            string sheetNumber,
            string sheetTitle,
            string viewCategory)
        {
            var result = ViewSheet.Create(doc, ElementId.InvalidElementId);

            result.Name        = sheetTitle;
            result.SheetNumber = sheetNumber;
            var viewCategoryParamList = result.GetParameters(SheetCopierConstants.SheetCategory);

            if (viewCategoryParamList.Count > 0)
            {
                Parameter viewCategoryParam = viewCategoryParamList.First();
                viewCategoryParam.Set(viewCategory);
            }
            return(result);
        }
Exemplo n.º 18
0
        private static void OpenSheetByOrder(UIDocument udoc, ViewSheet view, int offset)
        {
            List <OpenableView> list = ViewsInModel(udoc.Document, false).OrderBy(o => o.SheetNumber).ToList();
            int index = list.IndexOf(list.Find(ov => ov.SheetNumber == view.SheetNumber));

            if (index > -1)
            {
                if (offset < 0 && index + offset < 0)
                {
                    return;
                }
                if (offset > 0 && index + offset >= list.Count)
                {
                    return;
                }
                list[index + offset].Open();
            }
        }
Exemplo n.º 19
0
        public override void SetDataSource(object dataSource)
        {
            try
            {
                if (ViewSheet.ProtectContents)
                {
                    ViewSheet.Unprotect(Type.Missing);
                }

                //searchValue = null;
                CellsThatContainSearchValue.Clear();
                base.SetDataSource(dataSource);
            }
            finally
            {
                ProtectSheet();
            }
        }
Exemplo n.º 20
0
        private void duplicateSheets(Document detailLibrary, Document templateFile, ViewSheet sheet)
        {
            ICollection <ElementId> sheetToCopy = new Collection <ElementId>();

            sheetToCopy.Add(sheet.Id);

            ICollection <ElementId> copyIdsViewSpecific = new Collection <ElementId>();

            foreach (Element e in new FilteredElementCollector(detailLibrary).OwnedByView(sheet.Id))
            {
                // do not put viewports into this collection because they cannot be copied
                if (!(e is Viewport))
                {
                    copyIdsViewSpecific.Add(e.Id);
                }
            }

            ElementId newsheet;

            using (Transaction tDelete = new Transaction(detailLibrary, "Clear Sheet"))
            {
                tDelete.Start();

                IList <Viewport> viewports = new FilteredElementCollector(detailLibrary).OfClass(typeof(Viewport)).Cast <Viewport>()
                                             .Where(q => q.SheetId == sheet.Id).ToList();

                foreach (Viewport vp in viewports)
                {
                    detailLibrary.Delete(vp.Id);
                }

                using (Transaction t = new Transaction(templateFile, "Duplicate Sheet"))
                {
                    t.Start();
                    ViewSheet newSheet = templateFile.GetElement(ElementTransformUtils.CopyElements(detailLibrary, sheetToCopy, templateFile, Transform.Identity, new CopyPasteOptions()).First()) as ViewSheet;
                    newsheet = newSheet.Id;
                    ElementTransformUtils.CopyElements(sheet, copyIdsViewSpecific, newSheet, Transform.Identity, new CopyPasteOptions());
                    t.Commit();
                }
                tDelete.RollBack();
            }

            this.sheetIDMap.Add(sheet.Id, newsheet);
        }
Exemplo n.º 21
0
        //When viewport is placed on sheet the view name will be renamed.
        public void SetViewNameOnSheet(View view, ViewSheet sheet)
        {
            var titleOnSheetParam = view.LookupParameter("Title on Sheet");
            string sheetNumber = sheet.SheetNumber.ToString();
            string viewportNumberParam = view.LookupParameter("Detail Number").AsString();
            var viewNameParam = view.LookupParameter("View Name");

            string titleOnSheet = titleOnSheetParam.AsString();
            string titleOnSheetSet = viewNameParam.AsString();
            string renameViewportSet = sheetNumber + "-" + viewportNumberParam + "-" + titleOnSheet;
            try
            {
                viewNameParam.Set(renameViewportSet);
            }
            catch (Autodesk.Revit.Exceptions.InvalidOperationException)
            {

            }
        }
Exemplo n.º 22
0
 public void copySheets(Document detailLibrary, Document templateFile, UIApplication uiapp)
 {
     this.sourceSheets = GetListOfSheetsToCopy(detailLibrary);
     RetrieveTitleBlock(templateFile, "A2.30");
     this.sheetMap             = new Dictionary <Element, Element>();
     this.sheetIDMap           = new Dictionary <ElementId, ElementId>();
     this.scheduleGraphicIDMap = new Dictionary <ElementId, ElementId>();
     this.draftingViewIDMap    = new Dictionary <ElementId, ElementId>();
     foreach (Element ss in sourceSheets)
     {
         ViewSheet vs = ss as ViewSheet;
         duplicateSheets(detailLibrary, templateFile, vs);
         //duplicateSchedules(detailLibrary, templateFile, vs);
         duplicateDraftingViews(detailLibrary, templateFile, vs);
         placeViewsOnNewSheets(detailLibrary, templateFile, vs);
     }
     //extractViewportsonSheets(detailLibrary);
     //extractViewsonSheets(detailLibrary);
 }
Exemplo n.º 23
0
        //
        public void CreateSheetView(View3D view3D)
        {
            // Get an available title block from document
            FilteredElementCollector collector = new FilteredElementCollector(DocSet.doc);

            collector.OfClass(typeof(FamilySymbol));
            collector.OfCategory(BuiltInCategory.OST_TitleBlocks);

            FamilySymbol fs = collector.FirstElement() as FamilySymbol;

            if (fs != null)
            {
                using (Transaction t = new Transaction(DocSet.doc, "Create a new ViewSheet"))
                {
                    t.Start();
                    try
                    {
                        // Create a sheet view
                        ViewSheet viewSheet = ViewSheet.Create(DocSet.doc, fs.Id);
                        if (null == viewSheet)
                        {
                            throw new Exception("Failed to create new ViewSheet.");
                        }

                        // Add passed in view onto the center of the sheet
                        UV location = new UV((viewSheet.Outline.Max.U - viewSheet.Outline.Min.U) / 2,
                                             (viewSheet.Outline.Max.V - viewSheet.Outline.Min.V) / 2);

                        //viewSheet.AddView(view3D, location);
                        Viewport.Create(DocSet.doc, viewSheet.Id, view3D.Id, new XYZ(location.U, location.V, 0));

                        viewSheet.Name = "123456adasqwe";
                        TaskDialog.Show("idsheet", viewSheet.Id.ToString());

                        t.Commit();
                    }
                    catch
                    {
                        t.RollBack();
                    }
                }
            }
        }
        private static void createSheetsAndViews(Document doc, IEnumerable <VisualizationDeliverable> visualizationDeliverables, BoundingBoxXYZ modelExtents)
        {
            //Setup
            string _titleblockName    = "E1 30 x 42 Horizontal: E1 30x42 Horizontal";
            int    _demandViewScale   = 120;
            int    _combinedViewScale = 120;
            int    _capacityViewScale = 120;

            SheetCreator _sheetCreator = new SheetCreator(doc);

            OverrideGraphicSettings _modelElementsOgs = getModelOgs();

            Level _levelAbove = null;

            foreach (VisualizationDeliverable _visualizationDeliverable in visualizationDeliverables)
            {
                BoundingBoxXYZ _levelBounds = new BoundingBoxXYZ();
                _levelBounds.Min = new XYZ(modelExtents.Min.X, modelExtents.Min.Y, _visualizationDeliverable.Level.Elevation);

                if (_levelAbove == null)
                {
                    _levelBounds.Max = new XYZ(modelExtents.Max.X, modelExtents.Max.Y, modelExtents.Max.Z);
                    _levelAbove      = _visualizationDeliverable.Level;
                }
                else
                {
                    _levelBounds.Max = new XYZ(modelExtents.Max.X, modelExtents.Max.Y, _levelAbove.Elevation);
                }

                //View Creation
                BoundedViewCreator _boundedViewCreator = new BoundedViewCreator(_visualizationDeliverable.Level, null, _levelBounds);

                string    _viewName  = _boundedViewCreator.GetViewName("Visualization", string.Empty);
                ViewSheet _viewSheet = _sheetCreator.CreateSheet(_titleblockName, _viewName, _viewName);

                _visualizationDeliverable.Sheet        = _viewSheet;
                _visualizationDeliverable.DemandView   = createView3D("Demand", _boundedViewCreator, _demandViewScale, _modelElementsOgs);
                _visualizationDeliverable.CombinedView = createView3D("Combined", _boundedViewCreator, _combinedViewScale, _modelElementsOgs);
                _visualizationDeliverable.CapacityView = createView3D("Capacity", _boundedViewCreator, _capacityViewScale, _modelElementsOgs);

                _levelAbove = _visualizationDeliverable.Level;
            }
        }
Exemplo n.º 25
0
        public static void centerViewOnSheet(Viewport curVP, View curView, ViewSheet curSheet, Document m_doc)
        {
            //get center point of viewport
            XYZ           vpCenter     = null;
            Outline       vpOutline    = null;
            BoundingBoxUV sheetOutline = null;
            UV            sheetCenter  = new UV();

            vpCenter  = curVP.GetBoxCenter();
            vpOutline = curVP.GetBoxOutline();

            sheetOutline = curSheet.Outline;
            sheetCenter  = (sheetOutline.Min + sheetOutline.Max) * 0.5;

            XYZ sheetCenterXYZ = new XYZ(sheetCenter.U, sheetCenter.V, 0);

            //move viewport to sheet center
            curVP.SetBoxCenter(sheetCenterXYZ);
        }
Exemplo n.º 26
0
        private void AddLegendToSheetView(View legendView, ElementType viewPortType, ViewSheet viewSheet, string position)
        {
            if (legendView != null)
            {
                Viewport v1               = Viewport.Create(_doc, viewSheet.Id, legendView.Id, XYZ.Zero);
                Outline  lvOutline        = v1.GetBoxOutline();
                XYZ      legendViewCenter = (lvOutline.MaximumPoint + lvOutline.MinimumPoint) / 2.0;

                // The position of the legend is Bottom Right by default
                double refX = Default.LEGEND_POSITION_X_MAX;
                double refY = Default.LEGEND_POSITION_Y_MIN_R;

                XYZ legendRefPointToCenter = legendViewCenter - new XYZ(lvOutline.MaximumPoint.X, lvOutline.MinimumPoint.Y, 0);

                if (position.Equals("TopRight"))
                {
                    refX = Default.LEGEND_POSITION_X_MAX;
                    refY = Default.LEGEND_POSITION_Y_MAX_R;

                    legendRefPointToCenter = legendViewCenter - new XYZ(lvOutline.MaximumPoint.X, lvOutline.MaximumPoint.Y, 0);
                }
                else if (position.Equals("BottomLeft"))
                {
                    refX = Default.LEGEND_POSITION_X_MIN;
                    refY = Default.LEGEND_POSITION_Y_MIN_L;

                    legendRefPointToCenter = legendViewCenter - new XYZ(lvOutline.MinimumPoint.X, lvOutline.MinimumPoint.Y, 0);
                }
                else if (position.Equals("TopLeft"))
                {
                    refX = Default.LEGEND_POSITION_X_MIN;
                    refY = Default.LEGEND_POSITION_Y_MAX_L;

                    legendRefPointToCenter = legendViewCenter - new XYZ(lvOutline.MinimumPoint.X, lvOutline.MaximumPoint.Y, 0);
                }

                XYZ refPoint = new XYZ(refX, refY, 0);

                v1.ChangeTypeId(viewPortType.Id);
                XYZ diffToMove = refPoint + legendRefPointToCenter;
                ElementTransformUtils.MoveElement(_doc, v1.Id, diffToMove);
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Generate a new sheet of the Base Level.
        /// </summary>
        public void CreateNewSheet()
        {
            // create a filter to get all the title block type
            FilteredElementCollector collector = new FilteredElementCollector(doc);

            collector.OfCategory(BuiltInCategory.OST_TitleBlocks);
            collector.WhereElementIsElementType();

            // get elementid of first title block type
            ElementId titleblockid = collector.FirstElementId();

            // create the sheet
            ViewSheet viewSheet = ViewSheet.Create(doc, titleblockid);

            viewSheet.Name        = "NEW SHEET TEST";
            viewSheet.SheetNumber = "A-01";

            Viewport.Create(doc, viewSheet.Id, doc.ActiveView.Id, new XYZ(0, 2, 0));
        }
Exemplo n.º 28
0
        internal void PlaceOnSheet(ViewSheet sheet, IMultitableSchedule multiSchedule)
        {
            XYZ placementPoint = new XYZ(0, 0, 0);

            for (int i = 0; i < multiSchedule.Subschedules.Count; ++i)
            {
                if (multiSchedule.Subschedules[i].Id == ElementId.InvalidElementId)
                {
                    continue;
                }

                ScheduleSheetInstance scheduleInstance =
                    ScheduleSheetInstance
                    .Create(m_doc, sheet.Id, multiSchedule.Subschedules[i].Id, placementPoint);

                placementPoint =
                    new XYZ(0, scheduleInstance.get_BoundingBox(sheet).Min.Y + BORDER_WIDTH, 0);
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Generate sheet in active document.
        /// </summary>
        /// <param name="doc">the currently active document</param>
        public Autodesk.Revit.UI.Result GenerateSheet(Document doc)
        {
            if (null == doc)
            {
                throw new ArgumentNullException("doc");
            }

            if (m_selectedViews.IsEmpty)
            {
                throw new InvalidOperationException("No view be selected, generate sheet be canceled.");
            }

            Result result = Result.Succeeded;

            using (Transaction newTran = new Transaction(doc, "AllViews_Sample"))
            {
                newTran.Start();

                try
                {
                    ViewSheet sheet = ViewSheet.Create(doc, m_titleBlock.Id);
                    sheet.Name = SheetName;
                    PlaceViews(m_selectedViews, sheet);
                }
                catch (Exception)
                {
                    result = Result.Failed;
                }

                if (result == Result.Succeeded)
                {
                    newTran.Commit();
                }
                else
                {
                    newTran.RollBack();
                    throw new InvalidOperationException("Failed to generate sheet view and/or its viewports.");
                }
            }

            return(result);
        }
Exemplo n.º 30
0
        public SheetInfo(Document doc, ViewSheet TempSheet)
        {
            this.ViewPorts = new List<ViewPortInfo>();

            this.sheetId = TempSheet.Id;                     // extract sheet ID
            this.sheet = TempSheet;

            // for each sheet extract each view port
            foreach (ElementId vid in TempSheet.GetAllViewports())
            {
                Viewport vport = (Viewport)doc.GetElement(vid);
                View v = (View)doc.GetElement(vport.ViewId);

                if (v.ViewType == ViewType.AreaPlan || v.ViewType == ViewType.EngineeringPlan || v.ViewType == ViewType.Elevation || v.ViewType == ViewType.FloorPlan || v.ViewType == ViewType.Section || v.ViewType == ViewType.ThreeD)
                {

                    ViewPorts.Add(new ViewPortInfo(v.Id, vport.GetBoxOutline().MinimumPoint, v, vport));
                }
            }
        }
Exemplo n.º 31
0
        public SheetInfo(Document doc, ViewSheet TempSheet)
        {
            this.ViewPorts = new List <ViewPortInfo>();


            this.sheetId = TempSheet.Id;                     // extract sheet ID
            this.sheet   = TempSheet;

            // for each sheet extract each view port
            foreach (ElementId vid in TempSheet.GetAllViewports())
            {
                Viewport vport = (Viewport)doc.GetElement(vid);
                View     v     = (View)doc.GetElement(vport.ViewId);

                if (v.ViewType == ViewType.AreaPlan || v.ViewType == ViewType.EngineeringPlan || v.ViewType == ViewType.Elevation || v.ViewType == ViewType.FloorPlan || v.ViewType == ViewType.Section || v.ViewType == ViewType.ThreeD)
                {
                    ViewPorts.Add(new ViewPortInfo(v.Id, vport.GetBoxOutline().MinimumPoint, v, vport));
                }
            }
        }
Exemplo n.º 32
0
        public ViewSheet FindSheet(string sheetNumber, string sheetName)
        {
            ViewSheet viewSheet = null;

            try
            {
                FilteredElementCollector collector = new FilteredElementCollector(m_doc);
                List <ViewSheet>         elements  = collector.OfClass(typeof(ViewSheet)).WhereElementIsNotElementType().ToElements().Cast <ViewSheet>().ToList();
                var sheets = from elem in elements where elem.SheetNumber == sheetNumber && elem.ViewName == sheetName select elem;
                if (sheets.Count() > 0)
                {
                    viewSheet = sheets.First();
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
            return(viewSheet);
        }
Exemplo n.º 33
0
        private List <View> AllLegendInSheet(ViewSheet viewSheet, Document doc)
        {
            List <View>      list           = new List <View>();
            ISet <ElementId> allPlacedViews = viewSheet.GetAllPlacedViews();

            foreach (ElementId elementId in allPlacedViews)
            {
                View view = doc.GetElement(elementId) as View;
                bool flag = view == null;
                if (!flag)
                {
                    bool flag2 = view.ViewType == ViewType.Legend;
                    if (flag2)
                    {
                        list.Add(view);
                    }
                }
            }
            return(list);
        }
Exemplo n.º 34
0
        void f( TextWriter tw, ViewSheet oViewSheet )
        {
            Document doc = oViewSheet.Document;

              IList<ElementId> oElemIDs = oViewSheet.GetAllRevisionIds();

              if( oElemIDs.Count == 0 )
            return;

              foreach( ElementId elemID in oElemIDs )
              {
            Element oEl = doc.GetElement( elemID );

            Revision oRev = oEl as Revision;

            // Add text line to text file
            tw.WriteLine( "Rev Category Name: " + oRev.Category.Name );

            // Add text line to text file
            tw.WriteLine( "Rev Description: " + oRev.Description );

            // Add text line to text file
            tw.WriteLine( "Rev Issued: " + oRev.Issued.ToString() );

            // Add text line to text file
            tw.WriteLine( "Rev Issued By: " + oRev.IssuedBy.ToString() );

            // Add text line to text file
            tw.WriteLine( "Rev Issued To: " + oRev.IssuedTo.ToString() );

            // Add text line to text file
            tw.WriteLine( "Rev Number Type: " + oRev.NumberType.ToString() );

            // Add text line to text file
            tw.WriteLine( "Rev Date: " + oRev.RevisionDate );

            // Add text line to text file
            tw.WriteLine( "Rev Visibility: " + oRev.Visibility.ToString() );

            // Add text line to text file
            tw.WriteLine( "Rev Sequence Number: " + oRev.SequenceNumber.ToString() );

            // Add text line to text file
            tw.WriteLine( "Rev Number: " + oRev.RevisionNumber );
              }
        }
        /// <summary>
        /// Return the viewport on the given
        /// sheet displaying the given view.
        /// </summary>
        Element GetViewport( ViewSheet sheet, View view )
        {
            Document doc = sheet.Document;

              // filter for view name:

              BuiltInParameter bip
            = BuiltInParameter.VIEW_NAME;

              ParameterValueProvider provider
            = new ParameterValueProvider(
              new ElementId( bip ) );

              FilterStringRuleEvaluator evaluator
            = new FilterStringEquals();

              FilterRule rule = new FilterStringRule(
            provider, evaluator, view.Name, true );

              ElementParameterFilter name_filter
            = new ElementParameterFilter( rule );

              BuiltInCategory bic
            = BuiltInCategory.OST_Viewports;

              // retrieve the specific named viewport:

              //Element viewport
              //  = new FilteredElementCollector( doc )
              //    .OfCategory( bic )
              //    .WherePasses( name_filter )
              //    .FirstElement();
              //return viewport;

              // unfortunately, there are not just one,
              // but two candidate elements. apparently,
              // we can distibuish them using the
              // owner view id property:

              List<Element> viewports
            = new List<Element>(
              new FilteredElementCollector( doc )
            .OfCategory( bic )
            .WherePasses( name_filter )
            .ToElements() );

              Debug.Assert( viewports[0].OwnerViewId.Equals( ElementId.InvalidElementId ),
            "expected the first viewport to have an invalid owner view id" );

              Debug.Assert( !viewports[1].OwnerViewId.Equals( ElementId.InvalidElementId ),
            "expected the second viewport to have a valid owner view id" );

              int i = 1;

              return viewports[i];
        }
        /// <summary>
        /// Bring viewport to front by 
        /// deleting and recreating it.
        /// </summary>
        void ViewportBringToFront( 
            ViewSheet sheet,
            Viewport viewport)
        {
            Document doc = sheet.Document;

              // Element id of the view in the viewport.

              ElementId viewId = viewport.ViewId;
              ElementId typeId = viewport.GetTypeId();
              XYZ boxCenter = viewport.GetBoxCenter();

              // The viewport might be pinned. Most overlayed
              // viewports are maintained pinned to prevent
              // accidental displacement. Record that state so
              // the replacement viewport can reproduce it.

               bool pinnedState = viewport.Pinned;

              //View view = doc.ActiveView;

              using( Transaction t = new Transaction( doc ) )
              {
            t.Start( "Delete and Recreate Viewport" );

            // At least in Revit 2016, pinned viewports
            // can be deleted without error.

            sheet.DeleteViewport( viewport );

            Viewport vvp = Viewport.Create( doc,
              sheet.Id, viewId, boxCenter );

            vvp.ChangeTypeId( typeId );
            vvp.Pinned = pinnedState;

            t.Commit();
              }
        }
Exemplo n.º 37
0
        /// <summary>
        /// Place all selected views on this sheet's appropriate location.
        /// </summary>
        /// <param name="views">all selected views</param>
        /// <param name="sheet">all views located sheet</param>
        private void PlaceViews(ViewSet views, ViewSheet sheet)
        {
            double xDistance = 0;
            double yDistance = 0;
            CalculateDistance(sheet.Outline, views.Size, ref xDistance, ref yDistance);

            Autodesk.Revit.DB.UV origin = GetOffSet(sheet.Outline, xDistance, yDistance);
            //Autodesk.Revit.DB.UV temp = new Autodesk.Revit.DB.UV (origin.U, origin.V);
            double tempU = origin.U;
            double tempV = origin.V;
            int n = 1;
            foreach (Autodesk.Revit.DB.View v in views)
            {
                Autodesk.Revit.DB.UV location = new Autodesk.Revit.DB.UV (tempU, tempV);
                Autodesk.Revit.DB.View view = v;
                Rescale(view, xDistance, yDistance);
                try
                {
                    sheet.AddView(view, location);
                }
                catch (ArgumentException /*ae*/)
                {
                    throw new InvalidOperationException("The view '" + view.Name +
                        "' can't be added, it may have already been placed in another sheet.");
                }

                if (0 != n++ % m_rows)
                {
                    tempU = tempU + xDistance * (1 - TITLEBAR);
                }
                else
                {
                    tempU = origin.U;
                    tempV = tempV + yDistance;
                }
            }
        }
Exemplo n.º 38
0
 private void Stream( ArrayList data, ViewSheet view )
 {
     data.Add( new Snoop.Data.ClassSeparator( typeof( ViewSheet ) ) );
       Utils.StreamWithReflection( data, typeof( ViewSheet ), view );
       //data.Add(new Snoop.Data.String("Sheet number", view.SheetNumber));
       //data.Add(new Snoop.Data.Enumerable("Views", view.Views));
 }
Exemplo n.º 39
0
        PlaceViews(ViewSet views, ViewSheet sheet)
        {
            double xDistance = 0;
            double yDistance = 0;
            CalculateDistance(sheet.Outline, views.Size, ref xDistance, ref yDistance);

            UV origin = GetOffset(sheet.Outline, xDistance, yDistance);
            UV temp = new UV(origin.U, origin.V);

            int n = 1;
            foreach (Autodesk.Revit.DB.View v in views) {
                UV location = new UV(temp.U, temp.V);
                Autodesk.Revit.DB.View view = v;
                Rescale(view, xDistance, yDistance);
                Viewport.Create(view.Document, sheet.Id, view.Id, new XYZ(location.U, location.V, 0));

                if (0 != n++ % m_rows) {
                    temp = new UV( temp.U + xDistance * (1 - TITLEBAR), temp.V );                    
                }
                else {
                    temp = new UV( origin.U,temp.V + yDistance);
                }
            }
        }
 public SheetData( ViewSheet v )
 {
     IsPlaceholder = v.IsPlaceholder;
       Name = v.Name;
       SheetNumber = v.SheetNumber;
 }