Esempio n. 1
0
        //复制视图
        public Autodesk.Revit.DB.View CreateDependentCopy(Document doc, ElementId eleId)
        {
            Autodesk.Revit.DB.View vie        = doc.GetElement(eleId) as Autodesk.Revit.DB.View;
            Autodesk.Revit.DB.View dependView = null;
            ElementId newViewId = null;

            if (vie.CanViewBeDuplicated(ViewDuplicateOption.Duplicate))
            {
                newViewId  = vie.Duplicate(ViewDuplicateOption.Duplicate);
                dependView = doc.GetElement(newViewId) as Autodesk.Revit.DB.View;
                return(dependView);
            }
            else
            {
                TaskDialog.Show("Wrong", "该视图不能被带细节复制");
                return(dependView);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Duplicate one existing sheet
        /// </summary>
        /// <param name="shtNumber">The new sheet number</param>
        /// <param name="shtName">The new sheet name</param>
        /// <param name="tbName">The title block for the new sheet</param>
        /// <param name="vsSourceSheet">The ViewSheet to copy</param>
//		public void DuplicateOneSheet(string shtNumber, string shtName, string tbName, ViewSheet vsSourceSheet)
        public void DuplicateOneSheet(NewSheetFormat nsf)
        {
            ViewSheet vsDestinationSheet;

            try
            {
                // try to create the sheet
                // see below about copy parameters
                vsDestinationSheet = CreateOneEmptySheet(nsf);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }

            // at this point we have a source and destination ViewSheet
            // here we copy the elements on the source ViewSheet and
            // place them onto the destination ViewSheet
            // except, we don't copy the title block as this was added
            // when the ViewSheet was created

            // first, get a collection of elements that exist on the source sheet
            FilteredElementCollector colViewSheet =
                new FilteredElementCollector(_doc, nsf.FcSelViewSht.Id);

            // prepare for the elements to "copy" and "paste"
            ICollection <ElementId> copyIds = new List <ElementId>();

            // this may fail, prepare for the failure and capture the failure message
            try
            {
                // in order to copy detail lines directly onto the sheet, we need to
                // setup a SketchPlane on the "blank" sheet

                SketchPlane sketch = CreateSketchPlane(vsDestinationSheet);

                List <Viewport> vpList       = new List <Viewport>(10);
                List <Viewport> vpListNoCopy = new List <Viewport>(10);

                copyIds.Clear();

                // the ViewSheet has been setup to copy / paste or duplicate the elements
                // held by the ViewSheet - with the exceptions that ViewPorts cannot be copied
                foreach (Element sourceElem in colViewSheet)
                {
                    // ignore GuideGrids
                    if (sourceElem.Category.Id == _cats.get_Item(BuiltInCategory.OST_GuideGrid).Id)
                    {
                        continue;
                    }

                    // is the current element a titleblock? - this is the source titleblock
                    if (sourceElem.Category.Id == _cats.get_Item(BuiltInCategory.OST_TitleBlocks).Id)
                    {
                        ConfigureNewTitleBlock(sourceElem, vsDestinationSheet);
                        continue;
                    }

                    // we cannot copy some viewports or GuideGrids
                    if (sourceElem.Category.Id == _cats.get_Item(BuiltInCategory.OST_Viewports).Id)
                    {
                        Viewport vp = (Viewport)sourceElem;
                        View     vw = (View)_doc.GetElement(vp.ViewId);

                        if (Viewport.CanAddViewToSheet(_doc, vsDestinationSheet.Id, vw.Id))
                        {
                            vpList.Add(vp);                             // got a viewport to copy
                        }
                        else
                        {
                            vpListNoCopy.Add(vp);                             // got a viewport I cannot copy
                        }
                        continue;
                    }

                    // process a not viewport items
                    copyIds.Add(sourceElem.Id);
                }

                // preform the actual copy of the elements
                if (copyIds.Count > 0)
                {
                    ElementTransformUtils.CopyElements((ViewSheet)nsf.SelectedSheet.SheetView, copyIds, vsDestinationSheet,
                                                       Transform.Identity, new CopyPasteOptions());
                }

                // processed all of the items on the view sheet except for the viewports
                // we have a list of viewports we can copy and place onto the sheet
                // here we process the list of viewports that cannot be copy / pasted and replicate
                // them matching their original location
                if (vpList.Count > 0)
                {
                    foreach (Viewport vpSource in vpList)
                    {
                        View vw = _doc.GetElement(vpSource.ViewId) as View;

                        PlaceViewportOnSheet(vsDestinationSheet, vpSource, vw);
                    }
                }

                if (vpListNoCopy.Count > 0 && nsf.OperationOption == OperOpType.DupSheetAndViews)
                {
                    // get all of the view names here to make sure it is current
                    GetAllViewNames();

                    foreach (Viewport vpSource in vpListNoCopy)
                    {
                        View vwSource = _doc.GetElement(vpSource.ViewId) as View;

                        if (!vwSource.CanViewBeDuplicated(ViewDuplicateOption.WithDetailing))
                        {
                            continue;
                        }

                        View vwCopy;

                        // if PrimaryViewId is not InvalidElementId, view is dependant
                        if (vwSource.GetPrimaryViewId() == ElementId.InvalidElementId)
                        {
                            vwCopy = _doc.GetElement(vwSource.Duplicate(ViewDuplicateOption.WithDetailing)) as View;
                        }
                        else
                        {
                            vwCopy = _doc.GetElement(vwSource.Duplicate(ViewDuplicateOption.AsDependent)) as View;
                        }

                        if (vwCopy != null)
                        {
                            vwCopy.Name = FindNextViewName(vwSource.Name, nsf);
//							vwCopy.Name = FindNextViewName(vwSource.Name, nsf.newSheetNumber);

                            PlaceViewportOnSheet(vsDestinationSheet, vpSource, vwCopy);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception(AppStrings.R_ErrDupSheetFailDesc + nl + e.Message);
            }
        }