Exemple #1
0
        /***************************************************/
        /****               Public Methods              ****/
        /***************************************************/

        public static Viewport ToRevitViewport(this oM.Adapters.Revit.Elements.Viewport viewport, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null)
        {
            if (viewport == null || viewport.Location == null)
            {
                return(null);
            }

            Viewport revitViewPort = refObjects.GetValue <Viewport>(document, viewport.BHoM_Guid);

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

            settings = settings.DefaultIfNull();

            if (string.IsNullOrEmpty(viewport.ViewName))
            {
                return(null);
            }

            if (string.IsNullOrEmpty(viewport.SheetNumber))
            {
                return(null);
            }

            List <View> viewList = new FilteredElementCollector(document).OfClass(typeof(View)).Cast <View>().ToList();

#if (REVIT2020 || REVIT2021)
            View view = viewList.FirstOrDefault(x => !x.IsTemplate && x.Name == viewport.ViewName);
#else
            View view = viewList.FirstOrDefault(x => !x.IsTemplate && x.ViewName == viewport.ViewName);
#endif

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

            List <ViewSheet> viewSheetList = new FilteredElementCollector(document).OfClass(typeof(ViewSheet)).Cast <ViewSheet>().ToList();
            ViewSheet        viewSheet     = viewSheetList.FirstOrDefault(x => !x.IsTemplate && !x.IsPlaceholder && x.SheetNumber == viewport.SheetNumber);
            if (viewSheet == null)
            {
                return(null);
            }

            revitViewPort = Viewport.Create(document, viewSheet.Id, view.Id, viewport.Location.ToRevit());

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

            refObjects.AddOrReplace(viewport, revitViewPort);
            return(revitViewPort);
        }