Exemplo n.º 1
0
        public void DuplicateViewOntoSheet(
            SheetCopierView view,
            SheetCopierViewHost sheet,
            XYZ sourceViewCentre)
        {
            var destViewId = DuplicateView(view);

            if (Settings.Default.DeleteRevisionClouds)
            {
                DeleteRevisionClouds(destViewId, doc);
            }

            var elem = doc.GetElement(destViewId);

            if (elem == null)
            {
                return;
            }
            var v = elem as View;

            string newName = sheet.GetNewViewName(view.OldView.Id);

            if (newName != null)
            {
                v.Name = newName;
            }
            else
            {
                SCaddinsApp.WindowManager.ShowMessageBox("ERROR", "New view name could not be set to: " + newName);
            }

            TryAssignViewTemplate(v, view.ViewTemplateName, view.OldView.ViewTemplateId);

            PlaceViewPortOnSheet(sheet.DestinationSheet, destViewId, sourceViewCentre);
        }
Exemplo n.º 2
0
        public void CreateViews(SheetCopierViewHost host, StringBuilder summaryText)
        {
            Dictionary <ElementId, XYZ> viewPorts = null;

            if (host.Type == ViewHostType.Sheet)
            {
                viewPorts = GetViewportDictionary(host.SourceSheet, doc);
            }

            foreach (SheetCopierView view in host.ChildViews)
            {
                if (host.Type == ViewHostType.Model)
                {
                    var id   = DuplicateView(view);
                    var elem = doc.GetElement(id);
                    if (elem != null)
                    {
                        var    v       = elem as View;
                        string newName = host.GetNewViewName(view.OldView.Id);
                        if (newName != null)
                        {
                            v.Name = newName;
                            var msg = " View: " + view.OldView.Name + " copied to: " + newName;
                            if (summaryText != null)
                            {
                                summaryText.Append(msg + Environment.NewLine);
                            }
                        }
                        else
                        {
                            SCaddinsApp.WindowManager.ShowMessageBox("ERROR", "New view name could not be set to: " + newName);
                        }
                    }
                }
                else
                {
                    XYZ sourceViewPortCentre = null;
                    if (!viewPorts.TryGetValue(view.OldId, out sourceViewPortCentre))
                    {
                    }
                    else
                    {
                        switch (view.CreationMode)
                        {
                        case ViewPortPlacementMode.Copy:
                            DuplicateViewOntoSheet(view, host, sourceViewPortCentre);
                            break;

                        case ViewPortPlacementMode.New:
                            PlaceNewViewOnSheet(view, host, sourceViewPortCentre);
                            break;

                        case ViewPortPlacementMode.Legend:
                            PlaceViewPortOnSheet(host.DestinationSheet, view.OldView.Id, sourceViewPortCentre);
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Place a newly created view on a sheet.
        /// User this when copying a sheet AND assigning a new associated level.
        /// </summary>
        public void PlaceNewViewOnSheet(
            SheetCopierView view,
            SheetCopierViewHost sheet,
            XYZ sourceViewCentre)
        {
            Level level = null;

            try
            {
                Levels.TryGetValue(view.AssociatedLevelName, out level);
            }
            catch
            {
                SCaddinsApp.WindowManager.ShowErrorMessageBox("Error", "level not found");
                return;
            }

            if (level != null)
            {
                var floorPlanViewFamilyTypeId = GetFloorPlanViewFamilyTypeId(Doc, view.OldView.ViewType);
                if (Autodesk.Revit.DB.ElementId.InvalidElementId == floorPlanViewFamilyTypeId)
                {
                    SCaddinsApp.WindowManager.ShowErrorMessageBox("Error getting viewtype", "Error getting viewtype");
                    return;
                }

                using (ViewPlan vp = ViewPlan.Create(doc, floorPlanViewFamilyTypeId, level.Id))
                {
                    try
                    {
                        vp.CropBox        = view.OldView.CropBox;
                        vp.CropBoxActive  = view.OldView.CropBoxActive;
                        vp.CropBoxVisible = view.OldView.CropBoxVisible;
                        vp.Name           = view.Title;
                        var oldAnno = view.OldView.AreAnnotationCategoriesHidden;
                        vp.AreAnnotationCategoriesHidden = true;
                        TryAssignViewTemplate(vp, view.ViewTemplateName, view.OldView.ViewTemplateId);
                        PlaceViewPortOnSheet(sheet.DestinationSheet, vp.Id, sourceViewCentre);
                        vp.AreAnnotationCategoriesHidden = oldAnno;
                    }
                    catch (Exception ex)
                    {
                        SCaddinsApp.WindowManager.ShowErrorMessageBox("Error in PlaceNewViewOnSheet", ex.Message);
                    }
                }
            }
            else
            {
                SCaddinsApp.WindowManager.ShowErrorMessageBox("Error", "level not found");
            }
        }
Exemplo n.º 4
0
        public SheetCopierViewHost GetFirstModelHost()
        {
            var modelHost = ViewHosts.Where(s => s.Type == ViewHostType.Model);

            if (modelHost.Count() > 0)
            {
                return(modelHost.First());
            }
            else
            {
                var newModelHost = new SheetCopierViewHost(this);
                ViewHosts.Add(newModelHost);
                return(newModelHost);
            }
        }
Exemplo n.º 5
0
        public void CopyElementsBetweenSheets(SheetCopierViewHost sheet)
        {
            IList <ElementId> list = new List <ElementId>();

            using (var collector = new FilteredElementCollector(doc))
            {
                collector.OwnedByView(sheet.SourceSheet.Id);
                foreach (Element e in collector)
                {
                    if (!(e is Viewport))
                    {
                        if (e is CurveElement)
                        {
                            continue;
                        }
                        if (e.IsValidObject && e.ViewSpecific)
                        {
                            list.Add(e.Id);
                        }
                    }
                }
            }
            if (list.Count > 0)
            {
                Transform        transform;
                CopyPasteOptions options;
                ElementTransformUtils.CopyElements(
                    sheet.SourceSheet,
                    list,
                    sheet.DestinationSheet,
                    transform = new Transform(ElementTransformUtils.GetTransformFromViewToView(sheet.SourceSheet, sheet.DestinationSheet)),
                    options   = new CopyPasteOptions());
                if (Settings.Default.DeleteRevisionClouds)
                {
                    DeleteRevisionClouds(sheet.DestinationSheet.Id, doc);
                }
                options.Dispose();
                transform.Dispose();
            }
        }
Exemplo n.º 6
0
        // this is where the action happens
        public bool CreateAndPopulateNewSheet(SheetCopierViewHost host, StringBuilder summaryText)
        {
            if (host == null)
            {
                return(false);
            }

            // Run this is there is no host sheet
            // i.e. individual views are selected.
            if (host.Type == ViewHostType.Model)
            {
                CreateViews(host, summaryText);
                return(true);
            }

            // turn on hidden revisions, if option set
            if (Settings.Default.DeleteRevisionClouds)
            {
                foreach (Revision rev in hiddenRevisionClouds)
                {
                    try
                    {
                        rev.Visibility = RevisionVisibility.CloudAndTagVisible;
                    }
                    catch (Autodesk.Revit.Exceptions.ArgumentOutOfRangeException ex)
                    {
                        SCaddinsApp.WindowManager.ShowMessageBox(ex.Message);
                    }
                }
            }

            try
            {
                host.DestinationSheet = AddEmptySheetToDocument(
                    host.Number,
                    host.Title,
                    host.PrimaryCustomSheetParameter,
                    host.SecondaryCustomSheetParameter,
                    host.TertiaryCustomSheetParameter);
            }
            catch (Exception ex)
            {
                SCaddinsApp.WindowManager.ShowMessageBox(ex.Message);
                SCaddinsApp.WindowManager.ShowMessageBox(ex.StackTrace);
            }

            if (host.DestinationSheet != null)
            {
                CreateViews(host, summaryText);
            }
            else
            {
                return(false);
            }

            try
            {
                CopyElementsBetweenSheets(host);
            }
            catch (InvalidOperationException e)
            {
                Debug.WriteLine(e.Message);
            }

            if (Settings.Default.DeleteRevisionClouds)
            {
                foreach (Revision rev in hiddenRevisionClouds)
                {
                    rev.Visibility = RevisionVisibility.Hidden;
                }
            }

            var oldNumber = host.SourceSheet.SheetNumber;
            var msg       = " Sheet: " + oldNumber + " copied to: " + host.Number;

            if (summaryText != null)
            {
                summaryText.Append(msg + Environment.NewLine);
            }

            return(true);
        }