コード例 #1
0
        private IEnumerable <ViewSchedule> getViewSchedulesOnSheets(Element _sheet, Document _source)
        {
            ViewSheet currentSheet = _sheet as ViewSheet;

            FilteredElementCollector collector = new FilteredElementCollector(_source);

            collector.OfClass(typeof(ScheduleSheetInstance));
            //collector.WhereElementIsViewIndependent();

            var scheduleColl = from elements in collector
                               let type = elements as ScheduleSheetInstance
                                          where type.OwnerViewId == currentSheet.Id
                                          select type;
            //ICollection<ElementId> placedViews = currentSheet.GetAllPlacedViews();
            ICollection <ElementId> placedViews = currentSheet.GetAllViewports();
            List <ViewSchedule>     views       = new List <ViewSchedule>();

            foreach (ScheduleSheetInstance ssi in scheduleColl)
            {
                Element temp = _source.GetElement(ssi.ScheduleId);
                if (temp.GetType().ToString() == "Autodesk.Revit.DB.ViewSchedule")
                {
                    ViewSchedule _temp = temp as ViewSchedule;
                    if (!_temp.IsTitleblockRevisionSchedule)
                    {
                        views.Add(temp as ViewSchedule);
                    }
                }
            }
            return(views);
        }
コード例 #2
0
ファイル: Helper.cs プロジェクト: psavine42/rvt-export-loop
        public static void SheetFromOrphanViews(Document doc)
        {
            var views = viewsNotOnSheets(doc);

            ElementId titleBlockId = new FilteredElementCollector(doc)
                                     .OfCategory(BuiltInCategory.OST_TitleBlocks)
                                     .WhereElementIsElementType()
                                     .FirstElementId();

            using (Transaction t = new Transaction(doc, "Create Sheets"))
            {
                t.Start();

                foreach (ElementId eid in views)
                {
                    View view = doc.GetElement(eid) as View;
                    view.CropBoxActive  = true;
                    view.CropBoxVisible = false;

                    ViewSheet sheet = ViewSheet.Create(doc, titleBlockId);
                    Viewport.Create(doc, sheet.Id, eid, XYZ.Zero);

                    doc.Regenerate();

                    ElementId vport = sheet.GetAllViewports().First();
                    Viewport  port  = doc.GetElement(vport) as Viewport;
                    var       max   = port.GetBoxOutline().MaximumPoint;
                    var       min   = port.GetBoxOutline().MinimumPoint;
                }
                t.Commit();
            }
        }
コード例 #3
0
        /// <summary>
        /// Find the viewport at a point on a sheet.
        /// </summary>
        /// <param name="viewSheet">The ViewSheet that was clicked</param>
        /// <param name="click">The click point</param>
        /// <returns>The viewport which was clicked, or null if no viewport was clicked.</returns>
        private static Viewport GetViewportAtClick(ViewSheet viewSheet, XYZ click)
        {
            if (null == viewSheet || null == click)
            {
                return(null);
            }

            Document doc = viewSheet.Document;

            if (null == doc)
            {
                return(null);
            }

            foreach (var vpId in viewSheet.GetAllViewports())
            {
                Viewport viewport = doc.GetElement(vpId) as Viewport;

                if (null != viewport && viewport.GetBoxOutline().Contains(click, CLICK_TOLERANCE))
                {
                    // Click is within the viewport
                    return(viewport);
                }
            }

            // Click was not contained by any viewport
            return(null);
        }
コード例 #4
0
        /// <summary>
        /// List the size and location of the given
        /// sheet, the views it contains, and the
        /// transforms from Revit model space to the view
        /// and from the view to the sheet.
        /// </summary>
        static void ListSheetAndViewTransforms(
            ViewSheet sheet)
        {
            Document doc = sheet.Document;

            // http://thebuildingcoder.typepad.com/blog/2010/09/view-location-on-sheet.html

            GetViewTransform(sheet);

            foreach (ElementId id in sheet.GetAllViewports())
            {
                Viewport vp      = doc.GetElement(id) as Viewport;
                XYZ      center  = vp.GetBoxCenter();
                Outline  outline = vp.GetBoxOutline();

                XYZ diff = outline.MaximumPoint
                           - outline.MinimumPoint;

                Debug.Print(
                    "viewport {0} for view {1} outline {2} "
                    + "diff {3} label outline {4}",
                    vp.Id, vp.ViewId,
                    Util.OutlineString(outline),
                    Util.PointString(diff),
                    Util.OutlineString(vp.GetLabelOutline()));
            }

            foreach (View v in sheet.GetAllPlacedViews()
                     .Select <ElementId, View>(id =>
                                               doc.GetElement(id) as View))
            {
                GetViewTransform(v);
            }
        }
コード例 #5
0
        /// <summary>
        /// Return polygon loops representing the size
        /// and location of given sheet and all the
        /// viewports it contains, regardless of type.
        /// </summary>
        static JtLoops GetSheetViewportLoops(
            SheetModelCollections modelCollections,
            ViewSheet sheet)
        {
            Document doc = sheet.Document;

            List <Viewport> viewports = sheet
                                        .GetAllViewports()
                                        .Select <ElementId, Viewport>(
                id => doc.GetElement(id) as Viewport)
                                        .ToList <Viewport>();

            int n = viewports.Count;

            modelCollections.ViewsInSheet[sheet.Id]
                = new List <ViewData>(n);

            JtLoops sheetViewportLoops = new JtLoops(n + 1);

            // sheet.get_BoundingBox( null ) returns (-100,-100),(100,100)

            BoundingBoxUV bb = sheet.Outline;                  // model coordinates (0,0), (2.76,1.95)

            JtBoundingBox2dInt ibb = new JtBoundingBox2dInt(); // millimeters (0,0),(840,...)

            ibb.ExpandToContain(new Point2dInt(bb.Min));
            ibb.ExpandToContain(new Point2dInt(bb.Max));

            JtLoop loop = new JtLoop(ibb.Corners);

            sheetViewportLoops.Add(loop);

            foreach (Viewport vp in viewports)
            {
                XYZ center = vp.GetBoxCenter(); // not used

                Outline outline = vp.GetBoxOutline();

                ibb.Init();

                ibb.ExpandToContain(
                    new Point2dInt(outline.MinimumPoint));

                ibb.ExpandToContain(
                    new Point2dInt(outline.MaximumPoint));

                loop = new JtLoop(ibb.Corners);

                sheetViewportLoops.Add(loop);

                ViewData d = new ViewData();
                d.Id = vp.ViewId;
                d.ViewportBoundingBox = loop.BoundingBox;

                modelCollections.ViewsInSheet[sheet.Id].Add(
                    d);
            }
            return(sheetViewportLoops);
        }
コード例 #6
0
        void CopyViews(ViewSheet source, ViewSheet newSheet)
        {
            var viewportIds = source.GetAllViewports();
            var viewports   = viewportIds.Select(x => doc.GetElement(x) as Viewport);

            foreach (var vp in viewports)
            {
                CopyView(vp, newSheet);
            }
        }
コード例 #7
0
        private static Dictionary <ElementId, XYZ> GetViewportDictionary(ViewSheet srcSheet, Document doc)
        {
            var result = new Dictionary <ElementId, XYZ>();

            foreach (ElementId viewPortId in srcSheet.GetAllViewports())
            {
                var viewPort       = (Viewport)doc.GetElement(viewPortId);
                var viewPortCentre = viewPort.GetBoxCenter();
                result.Add(
                    viewPort.ViewId, viewPortCentre);
            }
            return(result);
        }
コード例 #8
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);
        }
コード例 #9
0
ファイル: Helpers.cs プロジェクト: angelrps/ARP_Toolkit
        // 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);
        }
コード例 #10
0
        private void placeViewsOnNewSheets(Document detailLibrary, Document templateFile, ViewSheet sheet)
        {
            ICollection <ElementId> placedViewports = sheet.GetAllViewports();
            ElementId sourceSheetId = sheet.Id;
            ElementId newSheetId;

            //if (this.sheetIDMap.ContainsKey(sourceSheetId))
            //{
            newSheetId = sheetIDMap[sourceSheetId];
            //}
            ICollection <Viewport> viewsOnSheet = extractViewportsonSheets(detailLibrary, sheet);

            foreach (Viewport viewPort in viewsOnSheet)
            {
                ElementId viewsId = viewPort.ViewId;
                ElementId newViewId;
                //if (this.draftingViewIDMap.ContainsKey(viewsId))
                //{
                newViewId = draftingViewIDMap[viewsId];
                //}
                string      detailNumber = viewPort.get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER).AsString();
                XYZ         temp         = viewPort.GetBoxCenter();
                ElementId   temp2        = viewPort.get_Parameter(BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsElementId();
                ElementType type         = detailLibrary.GetElement(temp2) as ElementType;
                ElementId   typeID       = type.GetTypeId();
                string      typeName     = type.Name;

                ElementId viewTitle = temp2;

                Element vpp = new FilteredElementCollector(templateFile).OfCategory(BuiltInCategory.OST_Viewports).FirstOrDefault(q => q.Name == type.Name);

                ElementType type2 = templateFile.GetElement(viewTitle) as ElementType;


                using (Transaction t = new Transaction(templateFile, "Place View"))
                {
                    t.Start();
                    Viewport newvp = Viewport.Create(templateFile, newSheetId, newViewId, temp);
                    newvp.get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER).Set(detailNumber);
                    newvp.ChangeTypeId(vpp.GetTypeId());
                    t.Commit();
                }
            }
        }
コード例 #11
0
ファイル: SheetInfo.cs プロジェクト: DOCQR/revit
        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));
                }
            }
        }
コード例 #12
0
ファイル: SheetInfo.cs プロジェクト: Revitspace/revit
        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));
                }
            }
        }
コード例 #13
0
        /// <summary>
        /// Select a viewport by its associated view name and sheet name.
        /// </summary>
        /// <param name="form">The Form to be updated.</param>
        /// <param name="selectSheetName"> Sheet name.</param>
        /// <param name="selectAssociatedViewName">Associated view name.</param>
        public bool SelectViewport(AllViewsForm form, string selectSheetName, string selectAssociatedViewName)
        {
            m_VP = null;
            form.invalidViewport = true;

            FilteredElementCollector fec = new FilteredElementCollector(m_doc);

            fec.OfClass(typeof(Autodesk.Revit.DB.View));
            var viewSheets = fec.Cast <Autodesk.Revit.DB.View>().Where <Autodesk.Revit.DB.View>(vp => !vp.IsTemplate && vp.ViewType == ViewType.DrawingSheet);

            foreach (var view in viewSheets)
            {
                if (view.Name.Equals(selectSheetName))
                {
                    ViewSheet viewSheet = (ViewSheet)view;
                    foreach (var vp in viewSheet.GetAllViewports())
                    {
                        Viewport VP = (Viewport)(m_doc.GetElement(vp));

                        Autodesk.Revit.DB.View associatedView = m_doc.GetElement(VP.ViewId) as Autodesk.Revit.DB.View;

                        if (associatedView.Name.Equals(selectAssociatedViewName))
                        {
                            m_VP = VP;
                            break;
                        }
                    }
                }
            }

            if (m_VP == null)
            {
                throw new InvalidOperationException("Viewport not found.");
            }

            form.invalidViewport = false;
            UpdateViewportProperties(form);
            return(true);
        }
コード例 #14
0
ファイル: SetTitleblockScale.cs プロジェクト: giobel/ReviTab
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            try
            {
                ViewSheet sheet = doc.ActiveView as ViewSheet;

                FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id);
                collector.OfCategory(BuiltInCategory.OST_TitleBlocks);

                Element sheetTitleblock = collector.ToElements().FirstOrDefault();

                //TaskDialog.Show("result", sheetTitleblock.Name);

                List <int> scaleValues = new List <int>();

                foreach (ElementId idVp in sheet.GetAllViewports())
                {
                    Viewport vp = doc.GetElement(idVp) as Viewport;

                    try
                    {
                        View view = doc.GetElement(vp.ViewId) as View;
                        if (view.ViewType != ViewType.Legend && view.ViewType != ViewType.ThreeD)
                        {
                            Parameter scale = vp.get_Parameter(BuiltInParameter.VIEW_SCALE);
                            scaleValues.Add(scale.AsInteger());
                        }
                    }
                    catch
                    {
                    }
                }

                //int scaleBarValue = scaleValues.GroupBy(x => x).First().First();
                var scaleBarValue = scaleValues.GroupBy(x => x)
                                    .Select(y => new { Element = y.Key, Counter = y.Count() })
                                    .ToList();

                int longestArray = scaleBarValue.OrderBy(x => x.Counter).Last().Element;

                using (Transaction t = new Transaction(doc, "Set scalebar"))
                {
                    t.Start();

                    //TaskDialog.Show("result", scaleBarValue.ToString());
                    Parameter tbScalebar = sheetTitleblock.LookupParameter("Scalebar scale");
                    tbScalebar.Set(longestArray);

                    t.Commit();
                }

                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                TaskDialog.Show("Error", ex.Message);
                return(Result.Failed);
            }
        }
コード例 #15
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //Get the current Document from the Command Data
            Document doc = commandData.Application.ActiveUIDocument.Document;

            //Check to make sure the user is on a sheet before continuing.
            if (doc.ActiveView.ViewType == ViewType.DrawingSheet)
            {
                //Get a new UIDocument from the current document to use to make a selection
                UIDocument uidoc = new UIDocument(doc);
                //Create a new instance of the ViewSelectionFilter to only allow the user to select a Legend Viewport
                ISelectionFilter selectionFilter = new ViewSelectionFilter();
                //A selection of elements from the current Document
                Selection picked = uidoc.Selection;
                //Try block to catch if the user cancels the selection process
                try
                {
                    //Prompt the user to make a single selection in the Revit interface. Only Legend Viewports will be available based onour SelectionFilter. The string is what the status bar displays in the Lower Left
                    Reference selection = picked.PickObject(ObjectType.Element, selectionFilter, "Select Legend on Sheet");
                    //Make sure the user made a selection
                    if (picked != null)
                    {
                        //Set the Class variable to the Viewport the user selected
                        viewPort = doc.GetElement(selection) as Viewport;
                        //Get the Location of the Legend Viewport selected
                        XYZ locPt = viewPort.GetBoxCenter();
                        //Prompt the user with a model dialog to select the sheets to place or update the Legends on
                        WPF.SheetSelectionWPF frm = new WPF.SheetSelectionWPF(doc);
                        //Make sure the Sheet Selection Form returns the correct DialogResult
                        if (frm.ShowDialog().Value)
                        {
                            //Make sure the user selected at least 1 sheet
                            if (frm.ViewSheetIds.Count > 0)
                            {
                                //Use this try to make sure Revit doesn't crash when trying to place or update the Legend Viewports
                                try
                                {
                                    //Create a Transaction within a using block to dispose of everything when complete
                                    using (Transaction Trans = new Transaction(doc))
                                    {
                                        //Provide a name for the transaction in the Undo / Redo List
                                        Trans.Start("Place Multiple Legends");
                                        //Loop through each Sheet Element Id from the sheets selected by the User
                                        foreach (ElementId viewSheetId in frm.ViewSheetIds)
                                        {
                                            //Get the ViewSheet (Sheet) fro each Element Id in the Document
                                            ViewSheet viewSheet = doc.GetElement(viewSheetId) as ViewSheet;
                                            //Get all of the Viewport Element Ids on that ViewSheet
                                            ICollection <ElementId> viewPortIds = viewSheet.GetAllViewports();
                                            //Use this check to see if the viewport already exists or if it needs to be created
                                            bool PlaceViewport = true;
                                            //Loop through each ElementId for all Viewports on the Sheet
                                            foreach (ElementId elementId in viewPortIds)
                                            {
                                                //Get the Viewport from the ElementId so we can get the ViewId
                                                Viewport vp = doc.GetElement(elementId) as Viewport;
                                                //If the Viewport ViewId of the Legend selected matches the ViewId of the current Viewport then we now have the matching legend on the Sheet
                                                if (vp.ViewId == viewPort.ViewId)
                                                {
                                                    //Set the bool parameter to False since we will not need to Place a new viewport
                                                    PlaceViewport = false;
                                                    //Set the location on the sheet to the same location as the Legend selected
                                                    vp.SetBoxCenter(locPt);
                                                    //Break the loop so we don't have to loop through any extra Viewports
                                                    break;
                                                }
                                            }
                                            //If the Legend Viewport wasn't found, then the bool parameters remains True and a new Viewport for the Legend will be created
                                            if (PlaceViewport)
                                            {
                                                //Create a new viewport at the correct location and sheet
                                                Viewport viewport = Viewport.Create(doc, viewSheetId, viewPort.ViewId, locPt);
                                                //Set the Viewport Type to the same as the Legend selected
                                                viewport.ChangeTypeId(viewPort.GetTypeId());
                                            }
                                        }
                                        //Commit the Transaction to keep the changes
                                        Trans.Commit();
                                        //Return a successful result to Revit so the changes are kept
                                        return(Result.Succeeded);
                                    }
                                }
                                //Catch an exceptions when adding or updating the Legend Viewports. Tell the user and return a Failed Result so Revit does not keep any changes
                                catch (Exception ex)
                                {
                                    TaskDialog.Show("Legend Placement Error", ex.ToString());
                                    return(Result.Failed);
                                }
                            }
                            //Tell the user that they did not select any sheets and return a Cancelled result so Revit does not keep any changes
                            else
                            {
                                TaskDialog.Show("Sheet Selection", "No Sheets were selected");
                                return(Result.Cancelled);
                            }
                        }
                        //If the Sheet Selection form was closed or cancelled then return a Cancelled result so Revit does not keep any changes
                        else
                        {
                            return(Result.Cancelled);
                        }
                    }
                    //Retrun a Cancelled Reseult if no eleemnts are picked
                    return(Result.Cancelled);
                }
                //Catch the Operation canceled Exception which is raised when the user "Escapes" during a Pick Object operation and return a Failed result
                catch (Autodesk.Revit.Exceptions.OperationCanceledException)
                {
                    return(Result.Failed);
                }
            }
            //Tell the user that they need to be in a Sheet View to run this Command
            else
            {
                TaskDialog.Show("Sheet Required", "Active view must be a Sheet");
                return(Result.Failed);
            }
        }
コード例 #16
0
ファイル: All_Macros.cs プロジェクト: argram30/Revit-Macros
        public void DuplicateSheet()
        {
            UIDocument uidoc    = this.ActiveUIDocument;
            Document   revDoc   = uidoc.Document;
            ViewSheet  revSheet = revDoc.ActiveView as ViewSheet;

            #region do stuff
            if (null != revSheet)
            {
                TaskDialog.Show("Title", revSheet.Name + "  " + revSheet.SheetNumber);
                using (Transaction t = new Transaction(revDoc, "Duplicating sheet with parameters"))
                {
                    var title = new FilteredElementCollector(revDoc).OfClass(typeof(FamilyInstance))
                                .OfCategory(BuiltInCategory.OST_TitleBlocks).Cast <FamilyInstance>()
                                .First(block => block.OwnerViewId == revSheet.Id);


                    var newSheet = ViewSheet.Create(revDoc, title.GetTypeId());
                    newSheet.SheetNumber = revSheet.SheetNumber + "1";
                    newSheet.Name        = revSheet.Name;

                    foreach (var item in revSheet.GetAllViewports())
                    {
                        View newView        = null;
                        var  actualViewport = revDoc.GetElement(item) as Viewport;
                        var  actualView     = revDoc.GetElement(actualViewport.ViewId) as View;
                        var  actualViewTemp = actualView.ViewTemplateId;


                        if (actualView.ViewType != ViewType.Legend)
                        {
                            var newViewId = actualView.Duplicate(ViewDuplicateOption.WithDetailing);
                            newView      = revDoc.GetElement(newViewId) as View;
                            newView.Name = actualView.Name + "Suffix";
                            if (null != actualViewTemp)
                            {
                                newView.ViewTemplateId = actualViewTemp;
                            }
                        }

                        else
                        {
                            newView = actualView;
                        }

                        var newViewport = Viewport
                                          .Create(revDoc, newSheet.Id, newView.Id, actualViewport.GetBoxCenter());
                    }

                    #region Getting User Created Parameters from the Project
                    var defList = new List <Definition>();
                    var it      = revSheet.ParametersMap.ForwardIterator();
                    it.Reset();

                    while (it.MoveNext())
                    {
                        var param      = it.Current as Parameter;
                        var definition = param.Definition as InternalDefinition;

                        if (definition.BuiltInParameter == BuiltInParameter.INVALID)
                        {
                            defList.Add(definition);
                        }
                    }
                    #endregion                     //Getting User Created Parameters from the Project

                    string parameters = null;

                    foreach (var definition in defList)
                    {
                        var actualParam = revSheet.get_Parameter(definition);
                        var newParam    = newSheet.get_Parameter(definition);
                        parameters += actualParam;

                        if (actualParam.HasValue)
                        {
                            newParam.SetValueString(actualParam.AsString());
                        }
                    }

                    TaskDialog.Show("Parameters", parameters);
                }
            }

            else
            {
                TaskDialog.Show("Title", "This view is not a sheet");
            }
            #endregion
        }
コード例 #17
0
        public void ProcessSelection()
        {
            using (Transaction trans = new Transaction(activeDoc, "CopyLegends"))
            {
                trans.Start();
                foreach (SheetWrapper sw in Sheets)
                {
                    if (sw.SelectSheet)
                    {
                        // extract elements from element references
                        foreach (Reference r in selectedViews)
                        {
                            Element e = activeDoc.GetElement(r.ElementId);

                            // check if element is schedule or legend 
                            if (e.Category.Id.IntegerValue.Equals((int)BuiltInCategory.OST_ScheduleGraphics))
                            {
                                // process as schedule
                                try
                                {
                                    ScheduleSheetInstance sch = (ScheduleSheetInstance)e;
                                    bool scheduleOnSheet = false;

                                    // get viewsheet and check if schedule already on sheet
                                    // if schedule on sheet adjust position else create new
                                    foreach (ScheduleSheetInstance si in new FilteredElementCollector(activeDoc)
                                        .OfClass(typeof(ScheduleSheetInstance)))
                                    {
                                        if (si.OwnerViewId == sw.ID
                                            && si.ScheduleId == sch.ScheduleId)
                                        {
                                            si.Point = sch.Point;
                                            scheduleOnSheet = true;
                                        }
                                        else
                                        {
                                            continue;
                                        }
                                    }

                                    if (!scheduleOnSheet)
                                    {
                                        // create new schedule instance
                                        ScheduleSheetInstance.Create(activeDoc, sw.ID, sch.ScheduleId, sch.Point);
                                    }
                                }
                                catch (Exception) { }
                            }
                            else
                            {
                                // process as legend
                                try
                                {
                                    Viewport vp = (Viewport)e;
                                    bool legendOnSheet = false;

                                    // get all viewports on this sheet and check if legend already on sheet
                                    // if legend on sheet adjust position else add new one
                                    ViewSheet vs = activeDoc.GetElement(sw.ID) as ViewSheet;
                                    ICollection<ElementId> allViewports = vs.GetAllViewports();
                                    foreach (ElementId id in allViewports)
                                    {
                                        Viewport currentVp = activeDoc.GetElement(id) as Viewport;
                                        if (currentVp.ViewId == vp.ViewId)
                                        {
                                            currentVp.SetBoxCenter(vp.GetBoxCenter());
                                            legendOnSheet = true;
                                        }
                                        else
                                        {
                                            continue;
                                        }
                                    }

                                    if (!legendOnSheet)
                                    {
                                        // create new legend on sheet
                                        Viewport.Create(activeDoc, sw.ID, vp.ViewId, vp.GetBoxCenter());
                                    }
                                }
                                catch (Exception) { }
                            }
                        }
                    }
                }
                trans.Commit();
            }
        }
コード例 #18
0
        public void QTO_2_PlaceHoldersFromDWFMarkups(
            Document doc,
            string activityId)
        {
            View activeView = doc.ActiveView;

            if (!(activeView is ViewSheet))
            {
                TaskDialog.Show("QTO",
                                "The current view must be a Sheet View with DWF markups");
                return;
            }

            ViewSheet vs = activeView as ViewSheet;

            Viewport vp = doc.GetElement(
                vs.GetAllViewports().First()) as Viewport;

            View plan = doc.GetElement(vp.ViewId) as View;

            int scale = vp.Parameters.Cast <Parameter>()
                        .First(x => x.Id.IntegerValue.Equals(
                                   (int)BuiltInParameter.VIEW_SCALE))
                        .AsInteger();

            IEnumerable <Element> dwfMarkups
                = new FilteredElementCollector(doc)
                  .OfClass(typeof(ImportInstance))
                  .WhereElementIsNotElementType()
                  .Where(x => x.Name.StartsWith("Markup") &&
                         x.OwnerViewId.IntegerValue.Equals(
                             activeView.Id.IntegerValue));

            using (TransactionGroup tg = new TransactionGroup(doc))
            {
                tg.Start("DWF markups placeholders");

                using (Transaction t = new Transaction(doc))
                {
                    t.Start("DWF Transfer");

                    plan.Parameters.Cast <Parameter>()
                    .First(x => x.Id.IntegerValue.Equals(
                               (int)BuiltInParameter.VIEWER_CROP_REGION))
                    .Set(1);

                    XYZ VC = (plan.CropBox.Min + plan.CropBox.Max) / 2;

                    XYZ BC = vp.GetBoxCenter();

                    t.RollBack();

                    foreach (Element e in dwfMarkups)
                    {
                        GeometryElement GeoElem = e.get_Geometry(new Options());

                        GeometryInstance gi = GeoElem.Cast <GeometryInstance>().First();

                        GeometryElement gei = gi.GetSymbolGeometry();

                        IList <GeometryObject> gos = new List <GeometryObject>();

                        if (gei.Cast <GeometryObject>().Count(x => x is Arc) > 0)
                        {
                            continue;
                        }

                        foreach (GeometryObject go in gei)
                        {
                            XYZ med = new XYZ();

                            if (go is PolyLine)
                            {
                                PolyLine pl = go as PolyLine;

                                XYZ min = new XYZ(pl.GetCoordinates().Min(p => p.X),
                                                  pl.GetCoordinates().Min(p => p.Y),
                                                  pl.GetCoordinates().Min(p => p.Z));

                                XYZ max = new XYZ(pl.GetCoordinates().Max(p => p.X),
                                                  pl.GetCoordinates().Max(p => p.Y),
                                                  pl.GetCoordinates().Max(p => p.Z));

                                med = (min + max) / 2;
                            }

                            med = med - BC;

                            // Convert DWF sheet coordinates into model coordinates

                            XYZ a = VC + new XYZ(med.X * scale, med.Y * scale, 0);
                        }
                    }

                    t.Start("DWF Transfer");

                    foreach (Element e in dwfMarkups)
                    {
                        GeometryElement GeoElem = e.get_Geometry(new Options());

                        GeometryInstance gi = GeoElem.Cast <GeometryInstance>().First();

                        GeometryElement gei = gi.GetSymbolGeometry();

                        IList <GeometryObject> gos = new List <GeometryObject>();

                        if (gei.Cast <GeometryObject>().Count(x => x is Arc) == 0)
                        {
                            continue;
                        }

                        foreach (GeometryObject go in gei)
                        {
                            if (go is Arc)
                            {
                                Curve c = go as Curve;

                                XYZ med = c.Evaluate(0.5, true);

                                med = med - BC;

                                XYZ a = VC + new XYZ(med.X * scale, med.Y * scale, 0);

                                // Warning CS0618:
                                // Autodesk.Revit.Creation.ItemFactoryBase.NewTextNote(
                                //   View, XYZ, XYZ, XYZ, double, TextAlignFlags, string)
                                // is obsolete:
                                // This method is deprecated in Revit 2016.
                                // Please use one of the TextNote.Create methods instead.

                                //doc.Create.NewTextNote( plan,
                                //                       a,
                                //                       XYZ.BasisX,
                                //                       XYZ.BasisY,
                                //                       MMtoFeet( 5 ),
                                //                       TextAlignFlags.TEF_ALIGN_CENTER,
                                //                       activityId );

                                ElementId textTypeId = new FilteredElementCollector(doc)
                                                       .OfClass(typeof(TextNoteType))
                                                       .FirstElementId();

                                TextNote.Create(doc, plan.Id, a, activityId, textTypeId);
                            }
                        }

                        t.Commit();
                    }
                }

                tg.Assimilate();
            }
        }
コード例 #19
0
        Result IExternalCommand.Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            // cache admin data
            _appUI = commandData.Application;
            _app   = _appUI.Application;
            _docUI = commandData.Application.ActiveUIDocument;
            _doc   = _docUI.Document;

            try // generic
            {
                // Current View must be Sheet
                ViewSheet sheet = _doc.ActiveView as ViewSheet;
                if (null == sheet)
                {
                    Util.ErrorMsg("Current View is NOT a Sheet!");
                    return(Result.Cancelled);
                }

                // There must be a Floor Plan named "Level 0"
                // which is the "master" to align to
                Viewport vpMaster = null;
                // There must be at least one more Floor Plan
                // View to align (move)
                List <Viewport> vpsSlave = new List <Viewport>();
                // Find them:
                foreach (ElementId idVp in sheet.GetAllViewports())
                {
                    Viewport vp = _doc.GetElement(idVp) as Viewport;
                    ViewRvt  v  = _doc.GetElement(vp.ViewId) as ViewRvt;
                    if (v.ViewType == ViewType.FloorPlan)
                    {
                        if (v.Name.Equals("Level 0", StringComparison
                                          .CurrentCultureIgnoreCase))
                        {
                            vpMaster = vp;
                        }
                        else
                        {
                            vpsSlave.Add(vp);
                        }
                    } //if FloorPlan
                }     //foreeach idVp

                // Check if got them all
                if (null == vpMaster)
                {
                    Util.ErrorMsg("NO 'Level 0' Floor Plan on the Sheet!");
                    return(Result.Cancelled);
                }
                else if (vpsSlave.Count == 0)
                {
                    Util.ErrorMsg("NO other Floor Plans to adjust on the Sheet!");
                    return(Result.Cancelled);
                }

                // Process Master
                // --------------

                XYZ     ptMasterVpCenter = vpMaster.GetBoxCenter();
                ViewRvt viewMaster       = _doc.GetElement(
                    vpMaster.ViewId) as ViewRvt;
                double scaleMaster = viewMaster.Scale;

                // Process Slaves
                // --------------

                using (Transaction t = new Transaction(_doc))
                {
                    t.Start("Set Box Centres");

                    foreach (Viewport vpSlave in vpsSlave)
                    {
                        XYZ     ptSlaveVpCenter = vpSlave.GetBoxCenter();
                        ViewRvt viewSlave       = _doc.GetElement(
                            vpSlave.ViewId) as ViewRvt;
                        double scaleSlave = viewSlave.Scale;
                        // MUST be the same scale, otherwise can't really overlap
                        if (scaleSlave != scaleMaster)
                        {
                            continue;
                        }

                        // Work out how to move the center of Slave
                        // Viewport to coincide model-wise with Master
                        // (must use center as only Viewport.SetBoxCenter
                        // is provided in API)
                        // We can ignore View.Outline as Viewport.GetBoxOutline
                        // is ALWAYS the same dimensions enlarged by
                        // 0.01 ft in each direction.
                        // This guarantees that the center of View is
                        // also center of Viewport, BUT there is a
                        // problem when any Elevation Symbols outside
                        // the crop box are visible (can't work out why
                        // - BUG?, or how to calculate it all if BY-DESIGN)

                        BoundingBoxXYZ bbm = viewMaster.CropBox;
                        BoundingBoxXYZ bbs = viewSlave.CropBox;

                        // 0) Center points in WCS
                        XYZ wcsCenterMaster = 0.5 * bbm.Min.Add(bbm.Max);
                        XYZ wcsCenterSlave  = 0.5 * bbs.Min.Add(bbs.Max);

                        // 1) Delta (in model's feet) of the slave center w.r.t master center
                        double deltaX = wcsCenterSlave.X - wcsCenterMaster.X;
                        double deltaY = wcsCenterSlave.Y - wcsCenterMaster.Y;

                        // 1a) Scale to Delta in Sheet's paper-space feet
                        deltaX *= 1.0 / (double)scaleMaster;
                        deltaY *= 1.0 / (double)scaleMaster;

                        // 2) New center point for the slave viewport, so *models* "overlap":
                        XYZ newCenter = new XYZ(
                            ptMasterVpCenter.X + deltaX,
                            ptMasterVpCenter.Y + deltaY,
                            ptSlaveVpCenter.Z);
                        vpSlave.SetBoxCenter(newCenter);
                    }
                    t.Commit();
                }
            }
            catch (Exception ex)
            {
                Util.ErrorMsg("Generic exception: " + ex.Message);
                return(Result.Failed);
            }
            return(Result.Succeeded);
        }
コード例 #20
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            //下面代码可直接拷贝到外部事件excute的uiapp内,注释掉return;
            Document  doc            = uiapp.ActiveUIDocument.Document;
            Selection sel            = uiapp.ActiveUIDocument.Selection;
            View      activeView     = doc.ActiveView;
            ElementId activeViewId   = doc.ActiveView.Id;
            string    activeViewName = activeView.Name;

            FilteredElementCollector familySymbolSet = (new FilteredElementCollector(doc)).OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_TitleBlocks);

            if (familySymbolSet.Count() < 0)
            {
                TaskDialog.Show("Revit2020", "当前文档不存在标题栏");
            }
            FamilySymbol familySymbol = null;

            foreach (FamilySymbol fs in familySymbolSet)
            {
                string fsNmae = fs.Name;
                if (fsNmae == "A1 公制")
                {
                    familySymbol = fs;
                }
            }

            //寻找已经创建的视图
            FilteredElementCollector viewSheetSet = (new FilteredElementCollector(doc)).OfClass(typeof(ViewSheet)).WhereElementIsNotElementType();

            if (viewSheetSet.Count() < 0)
            {
                TaskDialog.Show("Revit2020", "当前文档不存在图纸");
            }
            ViewSheet viewSheet = null;

            foreach (ViewSheet vs in viewSheetSet)
            {
                string vsNmae_NUMBER = vs.get_Parameter(BuiltInParameter.SHEET_NUMBER).AsString();
                string vsNmae_NAME   = vs.get_Parameter(BuiltInParameter.SHEET_NAME).AsString();
                if (vsNmae_NUMBER == "A101" && vsNmae_NAME == "未命名")
                {
                    viewSheet = vs;
                }
            }
            ICollection <ElementId> viewportIds = viewSheet.GetAllViewports();

            XYZ maximumpoint = null;
            XYZ minimumpoint = null;
            XYZ viewportXYz  = new XYZ(0, 0, 0);

            if (viewportIds.Count() <= 0)
            {
                TaskDialog.Show("Revit2020", viewSheet.Name + "不存在视口");
            }
            else
            {
                foreach (ElementId viewportId in viewportIds)
                {
                    Viewport viewport = doc.GetElement(viewportId) as Viewport;

                    //Outline outline = viewport.GetBoxOutline();
                    Outline outline = viewport.GetLabelOutline();
                    //获取源图纸上指定视口的位置
                    maximumpoint = outline.MaximumPoint;
                    minimumpoint = outline.MinimumPoint;

                    viewportXYz = viewport.GetBoxCenter();

                    viewportXYz = (maximumpoint + minimumpoint) / 2;
                }
            }
            //创建目标图纸,添加视图
            ViewSheet _viewSheet = CreatViewSheetPort(doc, familySymbol, activeViewId, activeViewName, viewportXYz);

            //修改目标视图上的目标视口
            //ICollection<ElementId> _viewportIds = _viewSheet.GetAllViewports();

            //using (Transaction setViewportOutline = new Transaction(doc))
            //{
            //    if (_viewportIds.Count() <= 0)
            //    {
            //        TaskDialog.Show("Revit2020", _viewSheet.Name + "不存在视口");
            //    }
            //    else
            //    {
            //        TaskDialog.Show("Revit2020", "123");

            //        foreach (ElementId viewportId in _viewportIds)
            //        {
            //            Viewport viewport = doc.GetElement(viewportId) as Viewport;

            //            Outline outline = viewport.GetBoxOutline();
            //            TaskDialog.Show("Revit2020", "453");

            //            //获取源图纸上指定视口的位置
            //            outline.MaximumPoint = maximumpoint;
            //            outline.MinimumPoint = minimumpoint;
            //        }
            //    }
            //}
            return(Result.Succeeded);
        }
コード例 #21
0
        public static StringBuilder ExportSheetStats(Document doc, ViewSheet vs, StringBuilder sb)
        {
            var dictlist = new List <Dictionary <string, string> >();
            //List<ElementId> viewsInSHeet = vs.GetAllPlacedViews().ToList();
            List <ElementId> viewports = vs.GetAllViewports().ToList();
            string           sheethash = Helper.AndHash(vs.Name);
            string           num       = vs.SheetNumber;

            var a = new FilteredElementCollector(doc, vs.Id)
                    .OfCategory(BuiltInCategory.OST_TitleBlocks)
                    .OfClass(typeof(FamilyInstance));

            string w = String.Empty;
            string h = String.Empty;

            if (a.Count() > 0)
            {
                FamilyInstance titleblock = a.First() as FamilyInstance;
                w = prmhelper.GetParameterValueString(titleblock, BuiltInParameter.SHEET_WIDTH);
                h = prmhelper.GetParameterValueString(titleblock, BuiltInParameter.SHEET_HEIGHT);
            }

            foreach (ElementId eil in viewports)
            {
                Viewport vport    = doc.GetElement(eil) as Viewport;
                View     view     = doc.GetElement(vport.ViewId) as View;
                string   viewhash = Helper.AndHash(view.Name);

                string vt     = "";
                string vscale = "";
                try
                {
                    vt     = view.ViewType.ToString();
                    vscale = view.Scale.ToString();
                }
                catch (Exception e) { }

                string v1 = "";
                string v2 = "";
                string v3 = "";
                string v4 = "";
                try
                {
                    var bbx = vport.GetBoxOutline();
                    v1 = bbx.MinimumPoint.X.ToString();
                    v2 = bbx.MaximumPoint.X.ToString();
                    v3 = bbx.MinimumPoint.Y.ToString();
                    v4 = bbx.MaximumPoint.Y.ToString();
                }
                catch (Exception) { }

                string l1 = "";
                string l2 = "";
                string l3 = "";
                string l4 = "";
                try
                {
                    var bbl = vport.GetLabelOutline();
                    l1 = bbl.MinimumPoint.X.ToString();
                    l2 = bbl.MaximumPoint.X.ToString();
                    l3 = bbl.MinimumPoint.Y.ToString();
                    l4 = bbl.MaximumPoint.Y.ToString();
                }
                catch (Exception) { }

                string newLine =
                    String.Format("{0},{1},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17}",
                                  doc.Title, sheethash, viewhash, vs.Name, num, w, h, view.ViewName,
                                  v1, v2, v3, v4, l1, l2, l3, l4, vt, vscale);
                //dictlist.Add(ds);
                sb.AppendLine(newLine);
            }
            return(sb);
        }