示例#1
0
        /***************************************************/
        /****               Public Methods              ****/
        /***************************************************/

        public static ViewPlan ToRevitViewPlan(this oM.Adapters.Revit.Elements.ViewPlan viewPlan, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null)
        {
            if (viewPlan == null || string.IsNullOrEmpty(viewPlan.LevelName) || string.IsNullOrEmpty(viewPlan.ViewName))
            {
                return(null);
            }

            ViewPlan revitViewPlan = refObjects.GetValue <ViewPlan>(document, viewPlan.BHoM_Guid);

            if (revitViewPlan != null)
            {
                return(revitViewPlan);
            }

            settings = settings.DefaultIfNull();

            ElementId levelElementID = null;

            List <Level> levels = new FilteredElementCollector(document).OfClass(typeof(Level)).Cast <Level>().ToList();

            if (levels == null || levels.Count < 1)
            {
                return(null);
            }

            Level level = levels.Find(x => x.Name == viewPlan.LevelName);

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

            levelElementID = level.Id;

            ElementId viewTemplateId = ElementId.InvalidElementId;

            if (!string.IsNullOrWhiteSpace(viewPlan.TemplateName))
            {
                IEnumerable <ViewPlan> viewPlans = new FilteredElementCollector(document).OfClass(typeof(ViewPlan)).Cast <ViewPlan>();
                ViewPlan viewPlanTemplate        = viewPlans.FirstOrDefault(x => x.IsTemplate && viewPlan.TemplateName == x.Name);
                if (viewPlanTemplate == null)
                {
                    Compute.ViewTemplateNotExistsWarning(viewPlan);
                }
                else
                {
                    viewTemplateId = viewPlanTemplate.Id;
                }
            }

            revitViewPlan = Create.ViewPlan(document, level, viewPlan.ViewName, null, viewTemplateId) as ViewPlan;


            // Copy parameters from BHoM object to Revit element
            revitViewPlan.CopyParameters(viewPlan, settings);

            refObjects.AddOrReplace(viewPlan, revitViewPlan);
            return(revitViewPlan);
        }