Пример #1
0
        private static Result createReshoringLayoutSheets(UIDocument uiDoc)
        {
            Document _doc = uiDoc.Document;

            string _titleblockName           = "E1 30 x 42 Horizontal: E1 30x42 Horizontal";
            XYZ    _columnScheduleBottomLeft = new XYZ(2.3354130772204, 2.39482128194158, 0);
            XYZ    _viewCenter = new XYZ(1.45453036348288, 1.18116967618813, 0.871414246948733);
            XYZ    _levelScheduleBottomLeft = new XYZ(0.156336990263879, 2.37688649933288, 0);

            var _levels = Getters.GetLevels(_doc);

            Level _levelAbove  = null;
            Level _topLevel    = _levels.FirstOrDefault();
            Level _bottomLevel = _levels.LastOrDefault();

            List <Tuple <ViewSheet, View> > _sheetsWithViews = new List <Tuple <ViewSheet, View> >();


            foreach (Level _level in _levels)
            {
                if (_levelAbove == null)
                {
                    _levelAbove = _level;
                }

                BoundedViewCreator _boundedViewCreator = new BoundedViewCreator(_level, null, null);
                SheetCreator       _sheetCreator       = new SheetCreator(_doc);
                string             _viewName           = _boundedViewCreator.GetViewName(string.Empty, "FP");
                ViewSheet          _viewSheet          = _sheetCreator.CreateSheet(_titleblockName, _viewName, _viewName);
                ViewPlan           _viewPlan           = _boundedViewCreator.CreateViewPlan(80);
                _sheetsWithViews.Add(new Tuple <ViewSheet, View>(_viewSheet, _viewPlan));

                ViewSchedule          _columnSchedule = ScheduleCreator.CreateLayoutColumnSchedule(_doc, _level.Name, " Reshores");
                ScheduleSheetInstance _columnScheduleSheetInstance = ScheduleSheetInstance.Create(_doc, _viewSheet.Id, _columnSchedule.Id, _columnScheduleBottomLeft);

                ViewSchedule          _levelSchedule = ScheduleCreator.CreateLayoutLoadSchedule(_doc, _level.Name, " Loads");
                ScheduleSheetInstance _levelScheduleSheetInstance = ScheduleSheetInstance.Create(_doc, _viewSheet.Id, _levelSchedule.Id, _levelScheduleBottomLeft);

                _levelAbove = _level;
            }

            _doc.Regenerate();

            FamilySymbol _tagSymbol = new FilteredElementCollector(_doc)
                                      .OfCategory(BuiltInCategory.OST_MultiCategoryTags)
                                      .OfClass(typeof(FamilySymbol)).OfType <FamilySymbol>()
                                      .FirstOrDefault(p => p.FamilyName.Contains("Mark"));


            foreach (var _sheetWithView in _sheetsWithViews)
            {
                DimensionCreator.CreateDimensions(_sheetWithView.Item2);
                TagCreator.CreateTags(_sheetWithView.Item2, _tagSymbol);
                Viewport.Create(_doc, _sheetWithView.Item1.Id, _sheetWithView.Item2.Id, _viewCenter);
            }

            return(Result.Succeeded);
        }
Пример #2
0
        private static Result createDeliverableSheets(UIDocument uiDoc)
        {
            //ToDo: these might be good as settings in a future UI
            string _titleblockName = "E1 30 x 42 Horizontal: E1 30x42 Horizontal";
            //string _elementName = "C-2"; // "EllisShore_LumberWithClamps";
            //
            //int _3dViewScale = 48;
            //XYZ _3dViewportCenter = new XYZ(2.21129429621462, 0.656294714474886, 0);
            //
            //int _sectionViewScale = 32;
            //XYZ _sectionViewportCenter = new XYZ(0.7791340191012, 1.72774616204266, 0);

            int _floorplanViewScale      = 20;
            XYZ _floorplanViewportCenter = new XYZ(1.13879414318027, 1.16675126090371, -0.025);

            XYZ _scheduleBottomLeft = new XYZ(1.9435380772204, 2.43263378194158, 0);

            Document _doc = uiDoc.Document;

            //Get a BoundedView3DDefinition for each Level - Scope Box in the project
            var _levels = Getters.GetLevels(_doc);

            var _scopeBoxes = Getters.GetScopeBoxes(_doc);

            var    _boundedViewCreators = new List <BoundedViewCreator>();
            double _extraExtents        = 0.5;

            foreach (Level _level in _levels)
            {
                Level _levelAbove = _levels.FirstOrDefault(p => p.Elevation > _level.Elevation);
                if (_levelAbove == null)
                {
                    continue;
                }

                foreach (Element _scopeBox in _scopeBoxes)
                {
                    BoundingBoxXYZ _scopeBoxBounds = _scopeBox.get_BoundingBox(null);
                    BoundingBoxXYZ _viewBounds     = new BoundingBoxXYZ
                    {
                        Min = new XYZ(
                            _scopeBoxBounds.Min.X - _extraExtents,
                            _scopeBoxBounds.Min.Y - _extraExtents,
                            _level.Elevation - _extraExtents),
                        Max = new XYZ(
                            _scopeBoxBounds.Max.X + _extraExtents,
                            _scopeBoxBounds.Max.Y + _extraExtents,
                            _levelAbove.Elevation + _extraExtents)
                    };

                    _boundedViewCreators.Add(new BoundedViewCreator(_level, _scopeBox, _viewBounds));
                }
            }

            //Generate Views, set their Boundaries & Names, Adjust Visiblity Graphics
            OverrideGraphicSettings _70Transparent = new OverrideGraphicSettings();

            _70Transparent.SetSurfaceTransparency(70);

            List <Tuple <ElementId, string, List <View> > > _createdSheetIdViewIdSets = new List <Tuple <ElementId, string, List <View> > >();

            foreach (var _boundedViewCreator in _boundedViewCreators)
            {
                SheetCreator    _sheetCreator    = new SheetCreator(_doc);
                ScheduleCreator _scheduleCreator = new ScheduleCreator(_doc);

                //Create Sheet
                string    _pourName  = _boundedViewCreator.GetViewName(string.Empty);
                ViewSheet _sheetView = _sheetCreator.CreateSheet(_titleblockName, _pourName, _pourName);

                ////Create 3D View
                //View3D _3DView = _boundedViewCreator.CreateView3D(_3dViewScale);
                //_3DView.SetCategoryHidden(new ElementId(BuiltInCategory.OST_VolumeOfInterest), true);
                //_3DView.SetCategoryOverrides(new ElementId(BuiltInCategory.OST_Floors), _70Transparent);

                //Create Floorplan View
                ViewPlan _floorPlanView = _boundedViewCreator.CreateViewPlan(_floorplanViewScale);
                _floorPlanView.SetCategoryHidden(new ElementId(BuiltInCategory.OST_VolumeOfInterest), true);
                _floorPlanView.SetCategoryOverrides(new ElementId(BuiltInCategory.OST_Floors), _70Transparent);

                ////Create Section View
                //ViewSection _sectionView = _boundedViewCreator.CreateViewSection(_sectionViewScale);
                //_sectionView.SetCategoryHidden(new ElementId(BuiltInCategory.OST_VolumeOfInterest), true);
                //_sectionView.SetCategoryOverrides(new ElementId(BuiltInCategory.OST_Floors), _70Transparent);

                //ToDo: get necessary parameters into shared parameters, so that they are visible in Project
                // //Create Schedule
                // ViewSchedule _viewSchedule = _scheduleCreator.CreateSchedule(false, _pourName + " Shoring");
                // ScheduleField _comments = _scheduleCreator.AppendField(_viewSchedule, "Comments"); //Pour Name
                // ScheduleField _count = _scheduleCreator.AppendField(_viewSchedule, "Count");
                // ScheduleField _familyAndType = _scheduleCreator.AppendField(_viewSchedule, "Family and Type");
                // //ScheduleField _material = _scheduleCreator.AppendField(_viewSchedule, "Material");
                // //ScheduleField _clampSpacing = _scheduleCreator.AppendField(_viewSchedule, "Clamp Spacing");
                // //ScheduleField _lowerShoreLength = _scheduleCreator.AppendField(_viewSchedule, "Lower Shore Length");
                // //ScheduleField _upperShoreLength = _scheduleCreator.AppendField(_viewSchedule, "Upper Shore Length");
                // ScheduleField _height = _scheduleCreator.AppendField(_viewSchedule, "Height");
                // ScheduleField _clearShoreHeight = _scheduleCreator.AppendField(_viewSchedule, "Clear Shore Height"); //Total Shore Length
                // //ScheduleField _shoreLength = _scheduleCreator.AppendField(_viewSchedule, "Shore Overlap");
                // //ScheduleField _lumberWidth = _scheduleCreator.AppendField(_viewSchedule, "Lumber Width");
                // //ScheduleField _lumberThickness = _scheduleCreator.AppendField(_viewSchedule, "Lumber Thickness");
                // ScheduleField _loadCapacity = _scheduleCreator.AppendField(_viewSchedule, "Load Capacity"); //Safe Working Load
                //
                // _scheduleCreator.AppendSortField(_viewSchedule, _familyAndType);
                // //_scheduleCreator.AppendSortField(_viewSchedule, _lowerShoreLength);
                // //_scheduleCreator.AppendSortField(_viewSchedule, _upperShoreLength);
                // _scheduleCreator.AppendSortField(_viewSchedule, _clearShoreHeight);
                //
                // _scheduleCreator.AppendFilter(_viewSchedule, _comments, ScheduleFilterType.Equal, _pourName);
                //
                // ScheduleSheetInstance _scheduleSheetInstance = ScheduleSheetInstance.Create(_doc, _sheetView.Id, _viewSchedule.Id, _scheduleBottomLeft);

                _createdSheetIdViewIdSets.Add(new Tuple <ElementId, string, List <View> >(
                                                  _sheetView.Id,
                                                  _pourName,
                                                  new List <View> { /*_3DView,*/
                    _floorPlanView,                                 /*_sectionView*/
                }
                                                  ));
            }

            _doc.Regenerate();

            foreach (var _createdSheetIdViewIdSet in _createdSheetIdViewIdSets)
            {
                foreach (View _view in _createdSheetIdViewIdSet.Item3)
                {
                    if (_view == null)
                    {
                        continue;
                    }

                    //if (_view is View3D) Viewport.Create(_doc, _createdSheetIdViewIdSet.Item1, _view.Id, _3dViewportCenter);
                    else if (_view is ViewPlan)
                    {
                        DimensionCreator.CreateDimensions(_view, _createdSheetIdViewIdSet.Item2);
                        Viewport.Create(_doc, _createdSheetIdViewIdSet.Item1, _view.Id, _floorplanViewportCenter);
                    }
                    //else if (_view is ViewSection) Viewport.Create(_doc, _createdSheetIdViewIdSet.Item1, _view.Id, _sectionViewportCenter);
                }
            }

            return(Result.Succeeded);
        }
        private static Result createVisualizationSheets(UIDocument uiDoc, BuildingLoadModel buildingLoadModel, IEnumerable <ILoadModel> levelLiveLoadPerSquareFoots)
        {
            //Setup
            Document _doc = uiDoc.Document;

            double _concreteDensityPoundsForcePerCubicFoot = 153.0;

            XYZ _capacityViewCoordinate = new XYZ(2.17649771769026, 0.766954561856788, 0);
            XYZ _combinedViewCoordinate = new XYZ(0.780872717690263, 0.766954561856788, 0);
            XYZ _demandViewCoordinate   = new XYZ(0.780872717690263, 1.83481042377296, 0);

            var _levels = Getters.GetLevels(_doc).OrderByDescending(p => p.Elevation).ToList();

            var _floors            = Getters.GetFloors(_doc).OrderBy(p => p.get_BoundingBox(null)?.Max.Z).ToList();
            var _structuralColumns = new FilteredElementCollector(_doc).OfCategory(BuiltInCategory.OST_StructuralColumns).OfType <FamilyInstance>().OrderBy(p => p.get_BoundingBox(null)?.Max.Z).ToList();
            var _structuralFraming = new FilteredElementCollector(_doc).OfCategory(BuiltInCategory.OST_StructuralFraming).OfType <FamilyInstance>().OrderBy(p => p.get_BoundingBox(null)?.Max.Z).ToList();
            var _walls             = new FilteredElementCollector(_doc).OfClass(typeof(Wall)).OfType <Wall>().OrderBy(p => p.get_BoundingBox(null)?.Max.Z).ToList();

            BoundingBoxXYZ _modelExtents =
                GeometryHelpers.GetElementsBBox(
                    new FilteredElementCollector(_doc).WhereElementIsViewIndependent().WhereElementIsNotElementType().ToList());

            _modelExtents.Min = new XYZ(_modelExtents.Min.X, _modelExtents.Min.Y, _levels.LastOrDefault().Elevation - 1.0);

            Category _directShapeCategory = Category.GetCategory(_doc, BuiltInCategory.OST_GenericModel);

            Level _levelAbove  = null;
            Level _bottomLevel = _levels.LastOrDefault();
            Level _topLevel    = _levels.FirstOrDefault();

            //Begin to generate our VisualizationDeliverables - these are sheets with 3 plan-orientation isometric views.
            //  NOTE - isometric views were used so that semi-transparent color overrides can be overlayed over each other to represent demands vs capacities
            //  ToDo: it would be valuable to scale transparency by percentage of overall demand/capacity
            List <VisualizationDeliverable> _visualizationDeliverables = new List <VisualizationDeliverable>();

            foreach (Level _level in _levels)
            {
                if (_levelAbove == null)
                {
                    _levelAbove = _level;
                }

                //Get the elements that are on our current Level
                List <Floor>          _currentLevelFloors            = _floors.Where(p => p.LevelId == _level.Id).ToList();
                List <FamilyInstance> _currentLevelStructuralColumns = new List <FamilyInstance>();
                List <FamilyInstance> _currentLevelStructuralFraming = new List <FamilyInstance>();
                List <Wall>           _currentLevelWalls             = new List <Wall>();

                BoundingBoxXYZ _levelBounds = new BoundingBoxXYZ
                {
                    Min = new XYZ(_modelExtents.Min.X, _modelExtents.Min.Y, _level.Elevation),
                    Max = new XYZ(_modelExtents.Max.X, _modelExtents.Max.Y, _levelAbove.Elevation)
                };

                BoundingBoxIsInsideFilter   _withinLevelBoundsFilter     = new BoundingBoxIsInsideFilter(new Outline(_levelBounds.Min, _levelBounds.Max));
                BoundingBoxIntersectsFilter _intersectsLevelBoundsFilter = new BoundingBoxIntersectsFilter(new Outline(_levelBounds.Min, _levelBounds.Max));

                if (_structuralColumns.Count > 0)
                {
                    _currentLevelStructuralColumns = new FilteredElementCollector(_doc, _structuralColumns.Select(p => p.Id).ToList()).WherePasses(_intersectsLevelBoundsFilter).OfType <FamilyInstance>().ToList();
                }
                else
                {
                    _currentLevelStructuralColumns = new List <FamilyInstance>();
                }

                if (_structuralFraming.Count > 0)
                {
                    _currentLevelStructuralFraming = new FilteredElementCollector(_doc, _structuralFraming.Select(p => p.Id).ToList()).WherePasses(_withinLevelBoundsFilter).OfType <FamilyInstance>().ToList();
                }
                else
                {
                    _currentLevelStructuralFraming = new List <FamilyInstance>();
                }

                if (_walls.Count > 0)
                {
                    _currentLevelWalls = new FilteredElementCollector(_doc, _walls.Select(p => p.Id).ToList()).WherePasses(_withinLevelBoundsFilter).OfType <Wall>().ToList();
                }
                else
                {
                    _currentLevelWalls = new List <Wall>();
                }

                //Generate LoadModels to populate a full LevelLoadModel
                LevelLoadModel _currentLevelLoadModel = LevelLoadModel.Create(_level);
                foreach (Floor _floor in _currentLevelFloors)
                {
                    //The "top" floor is where the initial Demand is determined, which is to be supported via reshores propagating down through the building
                    //ToDo: it would be valuable to be able to pick which Level to start from
                    if (_level.Id == _topLevel.Id)
                    {
                        Parameter _floorThicknessParameter = _floor.get_Parameter(BuiltInParameter.FLOOR_ATTR_THICKNESS_PARAM);
                        double    _floorThickness          = _floorThicknessParameter == null
                            ? 0.0
                            : _floorThicknessParameter.AsDouble();

                        _currentLevelLoadModel.addFloorDemandLoadModel(_floor, _concreteDensityPoundsForcePerCubicFoot * _floorThickness);
                    }

                    //Add loads from other sources that are also distributed evenly along a level
                    ILoadModel _floorCapacityLoadModel = levelLiveLoadPerSquareFoots.FirstOrDefault(p => p.Name == _level.Name);
                    if (_floorCapacityLoadModel == null)
                    {
                        continue;
                    }

                    List <LoadModel> _floorLoadModels = _currentLevelLoadModel.addFloorCapacityLoadModel(_floor, _floorCapacityLoadModel.PoundsForcePerSquareFoot);

                    foreach (ILoadModel _loadModel in levelLiveLoadPerSquareFoots.Where(p => p.Name.Equals(_level.Name)))
                    {
                        List <ILoadModel> _otherLoadModels = new List <ILoadModel>();
                        foreach (LoadModel _floorLoadModel in _floorLoadModels)
                        {
                            LoadModel _otherLoadModel = LoadModel.Create();
                            _otherLoadModel.Name     = _loadModel.Name;
                            _otherLoadModel.LoadType = _loadModel.LoadType;
                            _otherLoadModel.PoundsForcePerSquareFoot = _loadModel.PoundsForcePerSquareFoot;
                            _otherLoadModel.AreaSquareFeetXY         = _floorLoadModel.AreaSquareFeetXY;
                            _otherLoadModel.HeightFeetZ = _floorLoadModel.HeightFeetZ;
                            _otherLoadModel.OriginXFeet = _floorLoadModel.OriginXFeet;
                            _otherLoadModel.OriginYFeet = _floorLoadModel.OriginYFeet;

                            _otherLoadModel.Curves     = _floorLoadModel.Curves;
                            _otherLoadModel.PlanarFace = _floorLoadModel.PlanarFace;
                            _otherLoadModel.Element    = _floorLoadModel.Element;

                            _currentLevelLoadModel.addLoadModel(_otherLoadModel);
                        }
                    }
                }
                foreach (FamilyInstance _structuralColumn in _currentLevelStructuralColumns)
                {
                    _currentLevelLoadModel.addFamilyInstanceLoadModel(_structuralColumn, LoadType.Demand, buildingLoadModel.StructuralColumnWeightPerSquareFoot);
                    _currentLevelLoadModel.addFamilyInstanceLoadModel(_structuralColumn, LoadType.Capacity, buildingLoadModel.StructuralColumnWeightPerSquareFoot);
                }
                foreach (FamilyInstance _structuralFrame in _currentLevelStructuralFraming)
                {
                    _currentLevelLoadModel.addFamilyInstanceLoadModel(_structuralFrame, LoadType.Demand, buildingLoadModel.StructuralBeamWeightPerSquareFoot);
                }
                foreach (Wall _wall in _currentLevelWalls)
                {
                    _currentLevelLoadModel.addWallLoadModel(_wall, LoadType.Demand, buildingLoadModel.StructuralWallWeightPerSquareFoot);
                    _currentLevelLoadModel.addWallLoadModel(_wall, LoadType.Capacity, buildingLoadModel.StructuralWallWeightPerSquareFoot);
                }

                //Set the Solid elements that we will project through the building, to represent demands/capacities
                LoadModel.SetSolids(_currentLevelLoadModel.LoadModels.OfType <LoadModel>(), _level, _topLevel, _bottomLevel);

                VisualizationDeliverable _visualizationDeliverable = new VisualizationDeliverable(_currentLevelLoadModel)
                {
                    Floors            = _currentLevelFloors,
                    StructuralColumns = _currentLevelStructuralColumns,
                    StructuralFraming = _currentLevelStructuralFraming,
                    Walls             = _currentLevelWalls,
                };
                _visualizationDeliverables.Add(_visualizationDeliverable);

                _levelAbove = _level;
            }

            //Now that we've gathered all of our LoadModels, let's read the data about their actual demands/capacities
            buildingLoadModel.LevelLoadModels = _visualizationDeliverables.Select(p => p.LevelLoadModel as ILevelLoadModel).Where(p => p != null).ToList();

            buildingLoadModel.ReadLoads();

            foreach (LoadModel _loadModel in _visualizationDeliverables.Select(p => p.LevelLoadModel).SelectMany(p => p.LoadModels))
            {
                _loadModel.SetDirectShapeWithParameters(_doc, _directShapeCategory.Id, _loadModel.Name);
            }

            //Update Levels in the model with Load details
            foreach (LevelLoadModel _levelLoadModel in _visualizationDeliverables.Select(p => p.LevelLoadModel))
            {
                _levelLoadModel.SetLevelParameters();
            }

            //Color our active View for the visualization
            colorActiveView(_doc, _visualizationDeliverables);

            //ToDo: something happened which broke colors being correctly applied to these sheets - will need to sort this out
            //createSheetsAndViews(_doc, _visualizationDeliverables, _modelExtents);
            //
            //colorViews(_doc, _visualizationDeliverables);
            //
            //createViewports(_doc, _visualizationDeliverables, _capacityViewCoordinate, _combinedViewCoordinate, _demandViewCoordinate);

            return(Result.Succeeded);
        }
Пример #4
0
        private static Result placeTemporaryShoring(UIDocument uiDoc, BuildingLoadModel buildingLoadModel, List <ILoadModel> loadModels, string reshoringFamilyPathName, string reshoringFamilySymbol)
        {
            //Setup
            Document _doc = uiDoc.Document;

            //ToDo: it would be valuable to let users pick which Family & Type they want to use - so they can rapidly understand differences in layout for different reshores
            Dictionary <string, FamilyDefinition> _familyMappings = new List <string> {
                @"C:\ProgramData\Autodesk\Revit\Addins\2021\ApatosReshoring\Reshoring Poles 6x6.rfa",
                @"C:\ProgramData\Autodesk\Revit\Addins\2021\ApatosReshoring\Reshoring Poles Ellis 4x4.rfa",
                @"C:\ProgramData\Autodesk\Revit\Addins\2021\ApatosReshoring\Reshoring Poles Titan-HV.rfa",
                @"C:\ProgramData\Autodesk\Revit\Addins\2021\ApatosReshoring\Reshoring Poles Titan-XL.rfa",
            }.ToDictionary(p => Path.GetFileNameWithoutExtension(p),
                           p => FamilyHelpers.GetOrLoadFamilyDefinition(_doc, p));

            string       _familyName           = Path.GetFileNameWithoutExtension(reshoringFamilyPathName);
            FamilySymbol _temporaryShoreSymbol = null;

            if (_familyMappings.ContainsKey(_familyName))
            {
                Family _family = _familyMappings[_familyName]?.Family;
                foreach (ElementId _symbolID in _family.GetFamilySymbolIds())
                {
                    FamilySymbol _familySymbol = _doc.GetElement(_symbolID) as FamilySymbol;
                    if (_familySymbol == null)
                    {
                        continue;
                    }

                    if (_familySymbol.Name != reshoringFamilySymbol)
                    {
                        continue;
                    }

                    _temporaryShoreSymbol = _familySymbol;
                    if (_temporaryShoreSymbol != null)
                    {
                        break;
                    }
                }
            }

            if (_temporaryShoreSymbol == null)
            {
                return(Result.Failed);
            }
            if (_temporaryShoreSymbol.IsActive == false)
            {
                _temporaryShoreSymbol.Activate();
            }

            var _levels = Getters.GetLevels(uiDoc.Document).OrderByDescending(p => p.Elevation).ToList();
            var _floors = Getters.GetFloors(_doc).OrderBy(p => p.get_BoundingBox(null)?.Max.Z).ToList();

            Level _topLevel = _levels.FirstOrDefault();

            //Add Level Loads
            addLevelLoadModels(buildingLoadModel, _levels, _floors, _topLevel, loadModels);
            buildingLoadModel.ReadLoads();

            //Place Temporary Shores
            Dictionary <double, double> _clearShoreHeightCapacityMappings = getClearShoreHeightCapacityMappings(buildingLoadModel, _topLevel, _temporaryShoreSymbol);

            LevelLoadModel _levelLoadModelAbove = buildingLoadModel.LevelLoadModels.OfType <LevelLoadModel>().FirstOrDefault(p => p.Level.Id == _topLevel.Id);

            if (_levelLoadModelAbove == null)
            {
                return(Result.Failed);
            }

            Dictionary <LevelLoadModel, double> _levelLoadModelXDistances = new Dictionary <LevelLoadModel, double>();
            Dictionary <LevelLoadModel, double> _levelLoadModelYDistances = new Dictionary <LevelLoadModel, double>();
            LevelLoadModel _lowestReshoredLevelLoadModel = null;
            double         _levelAboveDemand             = _levelLoadModelAbove.ReshoreDemandPoundsForcePerSquareFoot;

            foreach (LevelLoadModel _levelLoadModel in buildingLoadModel.LevelLoadModels)
            {
                if (_levelAboveDemand > 0.0)
                {
                    if (_levelLoadModel.Level.Id == _topLevel.Id)
                    {
                        continue;
                    }

                    double _roundedClearShoreHeight = Math.Round(_levelLoadModel.ClearShoreHeight, 9);
                    if (_clearShoreHeightCapacityMappings.ContainsKey(_roundedClearShoreHeight) == false)
                    {
                        continue;
                    }

                    double _loadCapacityPerShore = _clearShoreHeightCapacityMappings[_roundedClearShoreHeight];
                    double _minimumAreaPerShore  = _loadCapacityPerShore / _levelAboveDemand;

                    double _allowedAreaSquareSideLength = Math.Sqrt(_minimumAreaPerShore);
                    double _roundedSideLength           = Math.Floor(_allowedAreaSquareSideLength);

                    //safer to round both down & have a smaller area
                    _levelLoadModelXDistances.Add(_levelLoadModel, _roundedSideLength);
                    _levelLoadModelYDistances.Add(_levelLoadModel, _roundedSideLength);

                    //Adjust our Capacity & Demand, then determine if we can stop adding temportary reshoring
                    _levelLoadModel.ReshoreDemandPoundsForcePerSquareFoot = _levelAboveDemand;

                    _levelAboveDemand -= _levelLoadModel.CapacityPoundsForcePerSquareFoot;
                }
                else
                {
                    if (_lowestReshoredLevelLoadModel == null)
                    {
                        _lowestReshoredLevelLoadModel = _levelLoadModelAbove;
                    }
                    _levelLoadModel.ReshoreDemandPoundsForcePerSquareFoot = 0.0;
                }

                _levelLoadModelAbove = _levelLoadModel;
            }

            //Update Level parameters
            foreach (LevelLoadModel _levelLoadModel in buildingLoadModel.LevelLoadModels)
            {
                _levelLoadModel.SetLevelParameters();
            }

            //Place temporary reshoring
            List <FamilyInstance> _temporaryShores = new List <FamilyInstance>();

            _levelLoadModelAbove = buildingLoadModel.LevelLoadModels.OfType <LevelLoadModel>().FirstOrDefault(p => p.Level.Id == _topLevel.Id);
            foreach (LevelLoadModel _levelLoadModel in buildingLoadModel.LevelLoadModels.Where(p => p.ReshoreDemandPoundsForcePerSquareFoot > 0.0))
            {
                if (_levelLoadModel.Level.Id == _topLevel.Id)
                {
                    continue;
                }

                if (_levelLoadModelXDistances.ContainsKey(_levelLoadModel) == false || _levelLoadModelYDistances.ContainsKey(_levelLoadModel) == false)
                {
                    break;
                }

                double _sideXLength = _levelLoadModelXDistances[_levelLoadModel];
                double _sideYLength = _levelLoadModelYDistances[_levelLoadModel];

                //ToDo: add 1, subtract 1 from each side & check if their total area is closer to the calculated area than a square
                //ToDo: do this twice, and take the "middle" option

                List <Floor> _levelAboveFloors = _floors.Where(p => p.LevelId == _levelLoadModelAbove.Level.Id).ToList();

                List <FamilyInstance> _temporaryReshores = new List <FamilyInstance>();

                foreach (Floor _floor in _levelAboveFloors)
                {
                    BoundingBoxXYZ _currentFloorBounds = _floor.get_BoundingBox(null);

                    List <double> _xCoords = new List <double>();
                    for (double _x = 0.0; _x <= _currentFloorBounds.Max.X - _currentFloorBounds.Min.X; _x += _sideXLength)
                    {
                        _xCoords.Add(_x);
                    }

                    List <double> _yCoords = new List <double>();
                    for (double _y = 0.0; _y <= _currentFloorBounds.Max.Y - _currentFloorBounds.Min.Y; _y += _sideYLength)
                    {
                        _yCoords.Add(_y);
                    }

                    foreach (double _x in _xCoords)
                    {
                        foreach (double _y in _yCoords)
                        {
                            XYZ _insertionCoordinate = new XYZ(
                                _currentFloorBounds.Min.X + _x,
                                _currentFloorBounds.Min.Y + _y,
                                _levelLoadModel.ElevationFeet);

                            FamilyInstance _temporaryShore = _doc.Create.NewFamilyInstance(_insertionCoordinate, _temporaryShoreSymbol, Autodesk.Revit.DB.Structure.StructuralType.Column);

                            Parameter _heightParam = _temporaryShore.LookupParameter("Height");
                            if (_heightParam != null && _heightParam.IsReadOnly == false)
                            {
                                _heightParam.Set(_levelLoadModel.ClearShoreHeight);
                            }

                            _temporaryShores.Add(_temporaryShore);
                        }
                    }
                }
            }


            //Regenerate so that the latest locations are updated in the model for our newly placed reshores - the intersects filters below will fail without this
            _doc.Regenerate();

            var _scopeBoxes = Getters.GetScopeBoxes(_doc);
            Dictionary <ElementId, string> _shoreIdScopeBoxNames = new Dictionary <ElementId, string>();

            foreach (Element _scopeBox in _scopeBoxes)
            {
                List <Element> _columnsInScopeBox = Getters.GetInsideElements(_doc, _temporaryShores, _scopeBox.get_BoundingBox(null));

                foreach (Level _level in _levels)
                {
                    List <Element> _columnsInScopeBoxOnLevel = _columnsInScopeBox.Where(p => ((p.Location as LocationPoint)?.Point.Z - _level.Elevation) <= 1.0).ToList();

                    string _pourName = Helpers.Views.BoundedViewCreator.GetViewName(_level, _scopeBox, string.Empty, string.Empty);

                    foreach (Element _column in _columnsInScopeBoxOnLevel)
                    {
                        _column.get_Parameter(Ids.PourNameParameterId)?.Set(_pourName);
                    }
                }
            }

            return(Result.Succeeded);
        }
Пример #5
0
        private static Result createPourSheets(UIDocument uiDoc)
        {
            //ToDo: these might be good as settings in a future UI
            string _titleblockName = "E1 30 x 42 Horizontal: E1 30x42 Horizontal";
            //string _elementName = "C-2"; // "EllisShore_LumberWithClamps";
            //
            //int _3dViewScale = 48;
            //XYZ _3dViewportCenter = new XYZ(2.21129429621462, 0.656294714474886, 0);
            //
            //int _sectionViewScale = 32;
            //XYZ _sectionViewportCenter = new XYZ(0.7791340191012, 1.72774616204266, 0);

            int _floorplanViewScale      = 24;
            XYZ _floorplanViewportCenter = new XYZ(1.23473112570493, 1.15208223453682, 0);

            XYZ _columnScheduleBottomLeft = new XYZ(2.31721454780864, 2.37688649933288, 0);
            XYZ _levelScheduleBottomLeft  = new XYZ(0.156336990263879, 2.37688649933288, 0);

            Document _doc = uiDoc.Document;

            //Get a BoundedView3DDefinition for each Level - Scope Box in the project
            var _levels = Getters.GetLevels(_doc);

            var _scopeBoxes = Getters.GetScopeBoxes(_doc);

            var    _boundedViewCreators = new List <BoundedViewCreator>();
            double _extraExtents        = 0.5;

            foreach (Level _level in _levels)
            {
                Level _levelAbove = _levels.FirstOrDefault(p => p.Elevation > _level.Elevation);
                if (_levelAbove == null)
                {
                    continue;
                }

                foreach (Element _scopeBox in _scopeBoxes)
                {
                    BoundingBoxXYZ _scopeBoxBounds = _scopeBox.get_BoundingBox(null);
                    BoundingBoxXYZ _viewBounds     = new BoundingBoxXYZ
                    {
                        Min = new XYZ(
                            _scopeBoxBounds.Min.X - _extraExtents,
                            _scopeBoxBounds.Min.Y - _extraExtents,
                            _level.Elevation - _extraExtents),
                        Max = new XYZ(
                            _scopeBoxBounds.Max.X + _extraExtents,
                            _scopeBoxBounds.Max.Y + _extraExtents,
                            _levelAbove.Elevation + _extraExtents)
                    };

                    _boundedViewCreators.Add(new BoundedViewCreator(_level, _scopeBox, _viewBounds));
                }
            }

            //Generate Views, set their Boundaries & Names, Adjust Visiblity Graphics
            OverrideGraphicSettings _70Transparent = new OverrideGraphicSettings();

            _70Transparent.SetSurfaceTransparency(70);

            List <Tuple <ElementId, string, List <View> > > _createdSheetIdViewIdSets = new List <Tuple <ElementId, string, List <View> > >();

            foreach (var _boundedViewCreator in _boundedViewCreators)
            {
                SheetCreator _sheetCreator = new SheetCreator(_doc);


                //Create Sheet
                string    _pourName  = _boundedViewCreator.GetViewName(string.Empty, string.Empty);
                ViewSheet _viewSheet = _sheetCreator.CreateSheet(_titleblockName, _pourName, _pourName);

                ////Create 3D View
                //View3D _3DView = _boundedViewCreator.CreateView3D(_3dViewScale);
                //_3DView.SetCategoryHidden(new ElementId(BuiltInCategory.OST_VolumeOfInterest), true);
                //_3DView.SetCategoryOverrides(new ElementId(BuiltInCategory.OST_Floors), _70Transparent);

                //Create Floorplan View
                ViewPlan _floorPlanView = _boundedViewCreator.CreateViewPlan(_floorplanViewScale);
                _floorPlanView.SetCategoryHidden(new ElementId(BuiltInCategory.OST_VolumeOfInterest), true);
                _floorPlanView.SetCategoryOverrides(new ElementId(BuiltInCategory.OST_Floors), _70Transparent);

                ////Create Section View
                //ViewSection _sectionView = _boundedViewCreator.CreateViewSection(_sectionViewScale);
                //_sectionView.SetCategoryHidden(new ElementId(BuiltInCategory.OST_VolumeOfInterest), true);
                //_sectionView.SetCategoryOverrides(new ElementId(BuiltInCategory.OST_Floors), _70Transparent);

                //Create Schedules
                ViewSchedule          _columnSchedule = ScheduleCreator.CreatePourColumnSchedule(_doc, _pourName, " Reshores");
                ScheduleSheetInstance _columnScheduleSheetInstance = ScheduleSheetInstance.Create(_doc, _viewSheet.Id, _columnSchedule.Id, _columnScheduleBottomLeft);

                ViewSchedule          _levelSchedule = ScheduleCreator.CreatePourLoadSchedule(_doc, _boundedViewCreator.Level?.Name, " - " + _boundedViewCreator.ScopeBox?.Name + " Loads");
                ScheduleSheetInstance _levelScheduleSheetInstance = ScheduleSheetInstance.Create(_doc, _viewSheet.Id, _levelSchedule.Id, _levelScheduleBottomLeft);

                _createdSheetIdViewIdSets.Add(new Tuple <ElementId, string, List <View> >(
                                                  _viewSheet.Id,
                                                  _pourName,
                                                  new List <View> { /*_3DView,*/
                    _floorPlanView,                                 /*_sectionView*/
                }
                                                  ));
            }

            _doc.Regenerate();

            FamilySymbol _tagSymbol = new FilteredElementCollector(_doc)
                                      .OfCategory(BuiltInCategory.OST_MultiCategoryTags)
                                      .OfClass(typeof(FamilySymbol)).OfType <FamilySymbol>()
                                      .FirstOrDefault(p => p.FamilyName.Contains("Mark"));

            foreach (var _createdSheetIdViewIdSet in _createdSheetIdViewIdSets)
            {
                foreach (View _view in _createdSheetIdViewIdSet.Item3)
                {
                    if (_view == null)
                    {
                        continue;
                    }

                    //if (_view is View3D) Viewport.Create(_doc, _createdSheetIdViewIdSet.Item1, _view.Id, _3dViewportCenter);
                    else if (_view is ViewPlan)
                    {
                        DimensionCreator.CreateDimensions(_view);
                        TagCreator.CreateTags(_view, _tagSymbol);
                        Viewport.Create(_doc, _createdSheetIdViewIdSet.Item1, _view.Id, _floorplanViewportCenter);
                    }
                    //else if (_view is ViewSection) Viewport.Create(_doc, _createdSheetIdViewIdSet.Item1, _view.Id, _sectionViewportCenter);
                }
            }

            return(Result.Succeeded);
        }