Exemplo n.º 1
0
        private TitleBlockProperties setSheetParameters(double widthV, TitleBlockProperties tb, BoundingBoxXYZ box)
        {
            //double height = Math.Round(heightV, 1);
            double width = Math.Round(widthV, 1);

            tb = new TitleBlockProperties(width.ToString(), box);
            return(tb);
        }
Exemplo n.º 2
0
        private string getCellID(XYZ LRCorner, TitleBlockProperties tb)
        {
            string foundCell = null;

            foreach (KeyValuePair <string, Outline> cell in tb.CellIDs)
            {
                if (cell.Value.Contains(LRCorner, 0))
                {
                    foundCell = cell.Key;
                    break;
                }
            }

            return(foundCell);
        }
Exemplo n.º 3
0
        private void renumberViewport(Viewport view, Document doc)
        {
            string originalDetailNumber = view.get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER).AsString();
            TitleBlockProperties tbp    = null;
            Outline outline             = view.GetBoxOutline();
            XYZ     LRCorner            = new XYZ(outline.MaximumPoint.X, outline.MinimumPoint.Y, 0);

            ViewSheet vs = doc.GetElement(view.SheetId) as ViewSheet;
            Element   titleBlock;

            FilteredElementCollector col = new FilteredElementCollector(doc);

            col.OfClass(typeof(FamilyInstance));
            col.OfCategory(BuiltInCategory.OST_TitleBlocks);
            col.OwnedByView(vs.Id);

            FilteredElementCollector vpCol = new FilteredElementCollector(doc);

            vpCol.OfCategory(BuiltInCategory.OST_Viewports);
            vpCol.OwnedByView(vs.Id);

            IList <Element> viewPorts = vpCol.ToElements();

            IList <Element> title_blocks = col.ToElements();

            if (title_blocks.Count > 0)
            {
                titleBlock = title_blocks[0];
                var p = titleBlock.get_Parameter(BuiltInParameter.SHEET_WIDTH);
                //This is causing issues.  If the sheet isn't the active view, but a view on a sheet is.
                View activeview = doc.ActiveView;
                if (activeview.ViewType != ViewType.DrawingSheet)
                {
                    //Sets up mapping of sheets with views and views on sheets.
                    GetViewMapping(doc);

                    ElementId viewId = mapViewportToSheet[activeview.Id];

                    activeview = doc.GetElement(viewId) as View;

                    //https://forums.autodesk.com/t5/revit-api-forum/how-do-i-determine-if-the-active-view-is-being-accessed-through/m-p/6449863/highlight/true#M17471
                    //http://thebuildingcoder.typepad.com/blog/2009/01/viewports-and-sheets.html
                    //var sheet = activeview.
                }

                BoundingBoxXYZ box    = titleBlock.get_BoundingBox(activeview);
                double         dwidth = p.AsDouble();
                tbp = setSheetParameters(dwidth, tbp, box);
            }

            string cellId = getCellID(LRCorner, tbp);

            if (originalDetailNumber != cellId)
            {
                if (cellId != null)
                {
                    foreach (Element viewPort in viewPorts)
                    {
                        Viewport v            = viewPort as Viewport;
                        string   detailNumber = v.get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER).AsString();
                        if (cellId == detailNumber)
                        {
                            cellId = cellId + ".1";
                        }
                    }
                    view.get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER).Set(cellId);
                }
            }
        }