private Autodesk.Revit.DB.ViewPlan createViewPlan(Level level, string viewName)
        {
            ViewFamilyType           viewFamilyType          = null;
            FilteredElementCollector collectorViewFamilyType = new FilteredElementCollector(uidoc.Document);
            var viewFamilyTypes = collectorViewFamilyType.OfClass(typeof(ViewFamilyType)).ToElements();

            foreach (Element e in viewFamilyTypes)
            {
                ViewFamilyType v = e as ViewFamilyType;
                if (v.ViewFamily == ViewFamily.FloorPlan)
                {
                    viewFamilyType = v;
                    break;
                }
            }

            if ((viewFamilyType != null) && (level != null))
            {
                ViewPlan viewPlan = ViewPlan.Create(uidoc.Document, viewFamilyType.Id, level.Id);
                viewPlan.Name = viewName;

                return(viewPlan);
            }

            return(null);
        }
        private void UpdateLevels()
        {
            ViewFamilyType viewType = filterUtils.SelectViewFamilyType(ViewFamily.FloorPlan);

            //首先全部删除(00层不能删。在REVIT中,必须至少有一个标高)
            foreach (var level in acturalLevels)
            {
                if (level.Elevation != 0)
                {
                    doc.Delete(level.Id);
                }
                else
                {
                    level.Name = "0.000米层(建筑)";
                }
            }
            //然后根据MockLevels,全部重新生成
            foreach (var mockLevel in MockLevels)
            {
                if (mockLevel.Elevation != 0)
                {
                    Level  level = Level.Create(doc, mockLevel.Elevation);
                    string name  = (level.Elevation * 304.8 / 1000).ToString("#0.000");
                    if (mockLevel.IsStructural)
                    {
                        level.Name = name + "米层(结构)";
                    }
                    else
                    {
                        level.Name = name + "米层(建筑)";
                    }
                    ViewPlan floorview = ViewPlan.Create(doc, viewType.Id, level.Id);
                }
            }
        }
Exemplo n.º 3
0
        public ViewPlan CreateViewPlan(int scale, string viewName)
        {
            Document _doc = Level?.Document;

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

            ViewPlan _viewPlan = ViewPlan.Create(_doc, _floorPlanViewFamilyType.Id, Level.Id);

            if (ScopeBox != null)
            {
                _viewPlan.get_Parameter(BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP)?.Set(ScopeBox.Id);
            }
            else if (ScopeBox == null && Bounds != null)
            {
                _viewPlan.CropBoxActive = true;
                _viewPlan.CropBox       = Bounds;
            }

            if (string.IsNullOrWhiteSpace(viewName) == false)
            {
                _viewPlan.Name = viewName;
            }
            _viewPlan.Scale = scale;

            return(_viewPlan);
        }
Exemplo n.º 4
0
      public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
      {
          Document    doc       = commandData.Application.ActiveUIDocument.Document;
          double      elevation = 3;
          Transaction trans     = new Transaction(doc);

          trans.Start("creatlevel");
          Level level = Level.Create(doc, elevation);

          trans.Commit();

          var classFilter = new ElementClassFilter(typeof(ViewFamilyType));
          FilteredElementCollector filterElements = new FilteredElementCollector(doc);

          filterElements.WherePasses(classFilter);
          foreach (ViewFamilyType viewFamilyType in filterElements)
          {
              if ((viewFamilyType.ViewFamily == ViewFamily.FloorPlan) || (viewFamilyType.ViewFamily == ViewFamily.CeilingPlan))
              {
                  trans.Start("creat view of type" + viewFamilyType.ViewFamily);
                  ViewPlan view = ViewPlan.Create(doc, viewFamilyType.Id, level.Id);
                  trans.Commit();
              }
          }

          return(Autodesk.Revit.UI.Result.Succeeded);
      }
Exemplo n.º 5
0
        private List <ViewPlan> CreatePlans(Document doc, List <Level> levels)
        {
            /*
             * This method create three view plans for levels:
             * stractural plan, floor plan and ceileng plan
             */

            List <ViewPlan> viewPlans = new List <ViewPlan>();

            using (Transaction transaction = new Transaction(doc))
            {
                transaction.Start("Create plans");

                List <ElementId> plansId = new List <ElementId>()
                {
                    GetViewFamilyTypeId(doc, ViewFamily.StructuralPlan),
                    GetViewFamilyTypeId(doc, ViewFamily.FloorPlan),
                    GetViewFamilyTypeId(doc, ViewFamily.CeilingPlan)
                };

                foreach (Level level in levels)
                {
                    foreach (ElementId planId in plansId)
                    {
                        ViewPlan plan = ViewPlan.Create(doc, planId, level.Id);
                        viewPlans.Add(plan);
                    }
                }
                transaction.Commit();
            }
            return(viewPlans);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 为选中房间创建专门的floorPlan和ceilingPlan
        /// Ctrate a New FloorPlan and CeilingPlan for the selected selRoom
        /// </summary>
        /// <param name="viewOffseet"></param>
        /// <param name="view3d"></param>
        public void CreateNewViewPlan(double viewOffseet, View3D view3d)
        {
            //过滤所有的ViewFamilyType
            var classFilter = new ElementClassFilter(typeof(ViewFamilyType));
            FilteredElementCollector collector = new FilteredElementCollector(DocSet.doc);

            collector = collector.WherePasses(classFilter);
            ViewPlan view = null;

            using (Transaction tran = new Transaction(DocSet.doc))
            {
                foreach (ViewFamilyType viewFamilyType in collector)
                {
                    //当类型为FloorPlan或者CeilingPlan时创建同类型视图
                    if (viewFamilyType.ViewFamily == ViewFamily.FloorPlan ||
                        viewFamilyType.ViewFamily == ViewFamily.CeilingPlan)
                    {
                        tran.Start("Creat view of type " + viewFamilyType.ViewFamily);
                        //创建视图时需要 视图类型ID 相关标高ID
                        view = ViewPlan.Create(DocSet.doc, viewFamilyType.Id, DocSet.selRoom.LevelId);

                        //TaskDialog.Show("CreatLevelView", "A new level's view has been Created");

                        view.Name = DocSet.selRoom.Name;//生成平面的名称

                        view.get_Parameter(BuiltInParameter.VIEWER_CROP_REGION).Set(1);
                        view.AreAnalyticalModelCategoriesHidden = false;
                        view.PartsVisibility = PartsVisibility.ShowPartsAndOriginal;
                        view.Scale           = 50;
                        view.CropBoxActive   = true;
                        view.CropBoxVisible  = true;

                        string viewName = "PLAN ";
                        view.get_Parameter(BuiltInParameter.VIEW_DESCRIPTION).Set(DocSet.selRoom.Name);

                        if (viewFamilyType.ViewFamily == ViewFamily.CeilingPlan)
                        {
                            PlanViewRange range = view.GetViewRange();
                            range.SetLevelId(PlanViewPlane.TopClipPlane, DocSet.selRoom.UpperLimit.Id);
                            range.SetLevelId(PlanViewPlane.ViewDepthPlane, DocSet.selRoom.UpperLimit.Id);
                            range.SetLevelId(PlanViewPlane.CutPlane, DocSet.selRoom.LevelId);
                            range.SetLevelId(PlanViewPlane.BottomClipPlane, DocSet.selRoom.LevelId);
                            range.SetOffset(PlanViewPlane.CutPlane, 7.874);
                            range.SetOffset(PlanViewPlane.BottomClipPlane, 7.874);
                            view.get_Parameter(BuiltInParameter.VIEW_DESCRIPTION).Set(DocSet.selRoom.Name);
                            view.SetViewRange(range);

                            viewName = "RCP ";
                            view.get_Parameter(BuiltInParameter.VIEW_DESCRIPTION).Set(DocSet.selRoom.Name + " - RCP");
                        }
                        viewName     += _SoANumber + "_" + DocSet.selRoom.Level.Name;
                        view.ViewName = viewName;
                        tran.Commit();
                        ChangeViewFitRoom(view, tran, viewOffseet);
                    }
                }
            }
        }
Exemplo n.º 7
0
        public static ViewPlan CreatePhaseFloorPlan(Document doc, ItemInfo itemInfo, ViewFamilyType viewPlanFamilyType, Level planLevel, bool overwrite)
        {
            ViewPlan viewPlan = null;

            try
            {
                string viewName = planLevel.Name + " - " + itemInfo.ItemName;
                using (Transaction trans = new Transaction(doc))
                {
                    try
                    {
                        FilteredElementCollector collector = new FilteredElementCollector(doc);
                        List <ViewPlan>          viewPlans = collector.OfClass(typeof(ViewPlan)).ToElements().Cast <ViewPlan>().ToList();
                        var views = from view in viewPlans where view.Name == viewName select view;
                        if (views.Count() > 0)
                        {
                            if (overwrite)
                            {
                                viewPlan = views.First();
                            }
                            else
                            {
                                return(viewPlan);
                            }
                        }

                        if (null == viewPlan)
                        {
                            trans.Start("Create Plan View");
                            viewPlan      = ViewPlan.Create(doc, viewPlanFamilyType.Id, planLevel.Id);
                            viewPlan.Name = viewName;
                            Parameter param = viewPlan.get_Parameter(BuiltInParameter.VIEW_PHASE);
                            if (null != param)
                            {
                                if (!param.IsReadOnly)
                                {
                                    param.Set(itemInfo.ItemId);
                                }
                            }
                            trans.Commit();
                        }
                    }
                    catch (Exception ex)
                    {
                        trans.RollBack();
                        MessageBox.Show("Failed to create a plan view for the phase, " + itemInfo.ItemName + "\n" + ex.Message, "Create Plan View", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create floor plans by phases.\n" + ex.Message, "Create Floor Plans by Phases", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(viewPlan);
        }
Exemplo n.º 8
0
        private void CreateViewPlan(string name, ElementId levelId)
        {
            var vt = new FilteredElementCollector(Doc).OfClass(typeof(ViewFamilyType)).Where(el => ((ViewFamilyType)el).ViewFamily == ViewFamily.FloorPlan).First();

            var view = ViewPlan.Create(Doc, vt.Id, levelId);

            try
            {
                view.Name = name;
            }
            catch { }
        }
Exemplo n.º 9
0
        /// <summary>
        /// need open transaction.
        /// </summary>
        private static ViewPlan createViewsOfLevel(Document doc, ElementId _levelId)
        {
            var viewType = new FilteredElementCollector(doc)
                           .WhereElementIsElementType()
                           .OfClass(typeof(ViewFamilyType))
                           .Cast <ViewFamilyType>()
                           .Where(x => x.ViewFamily == ViewFamily.FloorPlan ||
                                  x.ViewFamily == ViewFamily.AreaPlan)
                           .First();

            return(ViewPlan.Create(doc, viewType.Id, _levelId));
        }
Exemplo n.º 10
0
        protected static ViewPlan CreatePlanView(Autodesk.Revit.DB.Level level, Autodesk.Revit.DB.ViewFamily planType)
        {
            var viewFam = DocumentManager.Instance.ElementsOfType <ViewFamilyType>()
                          .FirstOrDefault(x => x.ViewFamily == planType);

            if (viewFam == null)
            {
                throw new Exception("There is no such ViewFamily in the document");
            }

            return(ViewPlan.Create(Document, viewFam.Id, level.Id));;
        }
Exemplo n.º 11
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.º 12
0
        public void PlaceNewViewOnSheet(
            SheetCopierViewOnSheet view,
            SheetCopierSheet sheet,
            XYZ sourceViewCentre)
        {
            Level level = null;

            levels.TryGetValue(view.AssociatedLevelName, out level);
            if (level != null)
            {
                using (ViewPlan vp = ViewPlan.Create(doc, floorPlanViewFamilyTypeId, level.Id)) {
                    vp.CropBox        = view.OldView.CropBox;
                    vp.CropBoxActive  = view.OldView.CropBoxActive;
                    vp.CropBoxVisible = view.OldView.CropBoxVisible;
                    TryAssignViewTemplate(vp, view.ViewTemplateName);
                    PlaceViewPortOnSheet(sheet.DestinationSheet, vp.Id, sourceViewCentre);
                }
            }
            level.Dispose();
        }
Exemplo n.º 13
0
        /// <summary>
        /// add more levels so that level number can meet floor number
        /// </summary>
        public void UpdateLevels()
        {
            double baseElevation = m_levels.Values[m_levels.Count - 1].Elevation;

            Autodesk.Revit.Creation.Document createDoc = m_commandData.Application.ActiveUIDocument.Document.Create;
            Autodesk.Revit.DB.Document       m_Doc     = m_commandData.Application.ActiveUIDocument.Document;

            FilteredElementCollector collector       = new FilteredElementCollector(m_Doc);
            IList <Element>          viewFamilyTypes = collector.OfClass(typeof(ViewFamilyType)).ToElements();
            ElementId floorPlanId = new ElementId(-1);

            foreach (Element e in viewFamilyTypes)
            {
                ViewFamilyType v = e as ViewFamilyType;

                if (v != null && v.ViewFamily == ViewFamily.FloorPlan)
                {
                    floorPlanId = e.Id;
                    break;
                }
            }

            int newLevelSize = (m_floorNumber + 1) - m_levels.Count;

            if (newLevelSize == 0)
            {
                return;
            }

            for (int ii = 0; ii < newLevelSize; ii++)
            {
                double elevation = baseElevation + m_levelHeight * (ii + 1);
                Level  newLevel  = Level.Create(m_commandData.Application.ActiveUIDocument.Document, elevation);
                //createDoc.NewViewPlan(newLevel.Name, newLevel, Autodesk.Revit.DB.ViewPlanType.FloorPlan);
                ViewPlan viewPlan = ViewPlan.Create(m_Doc, floorPlanId, newLevel.Id);
                viewPlan.Name = newLevel.Name;
                m_levels.Add(elevation, newLevel);
            }
            m_originalLevelSize = m_levels.Count;
        }
Exemplo n.º 14
0
        ////[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
        private bool CreateShadowPlanViews(ModelSetupWizard.TransactionLog log)
        {
            var id      = GetViewFamilyId(doc, ViewFamily.FloorPlan);
            var levelId = GetHighestLevel(doc);

            if (id == null || levelId == null)
            {
                log.AddFailure("Could not gererate shadow plans. FamilyId or LevelId not found");
                return(false);
            }

            while (StartTime <= EndTime)
            {
                using (var t = new Transaction(doc))
                {
                    if (t.Start("Create Shadow Plans") == TransactionStatus.Started)
                    {
                        View view = ViewPlan.Create(doc, id, levelId);
                        view.ViewTemplateId = ElementId.InvalidElementId;
                        var niceMinutes = "00";
                        if (StartTime.Minute > 0)
                        {
                            niceMinutes = StartTime.Minute.ToString(CultureInfo.CurrentCulture);
                        }
                        var vname = "SHADOW PLAN - " + StartTime.ToShortDateString() + "-" + StartTime.Hour + "." +
                                    niceMinutes;
                        view.Name = GetNiceViewName(doc, vname);
                        var sunSettings = view.SunAndShadowSettings;
                        sunSettings.StartDateAndTime = StartTime;
                        sunSettings.SunAndShadowType = SunAndShadowType.StillImage;
                        view.SunlightIntensity       = 50;
                        log.AddSuccess("Shadow Plan created: " + vname);
                        t.Commit();
                        StartTime = StartTime.Add(ExportTimeInterval);
                    }
                }
            }
            return(true);
        }
        protected override Result ProcessCommand(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var collector = new FilteredElementCollector(_activeDocument);
            var level     = collector.OfCategory(BuiltInCategory.OST_Levels)
                            .WhereElementIsNotElementType()
                            .Cast <Level>()
                            .First(x => x.Name == "Level 1");

            var viewFamily = new FilteredElementCollector(_activeDocument)
                             .OfClass(typeof(ViewFamilyType))
                             .Cast <ViewFamilyType>()
                             .First(x => x.ViewFamily == ViewFamily.FloorPlan);

            using (Transaction trans = new Transaction(_activeDocument, "Create View Plan"))
            {
                trans.Start();
                var viewPlan = ViewPlan.Create(_activeDocument, viewFamily.Id, level.Id);
                viewPlan.Name = "My Floor Plan";
                trans.Commit();
            }
            return(Result.Succeeded);
        }
        public ViewPlan CreateViewPlan(int scale)
        {
            Document _doc = Level?.Document;

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

            ViewPlan _viewPlan = ViewPlan.Create(_doc, _floorPlanViewFamilyType.Id, Level.Id);

            _viewPlan.get_Parameter(BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP)?.Set(ScopeBox.Id);
            string _viewName = GetViewName("FloorPlan");

            if (string.IsNullOrWhiteSpace(_viewName) == false)
            {
                _viewPlan.Name = _viewName;
            }
            _viewPlan.Scale = scale;

            return(_viewPlan);
        }
Exemplo n.º 17
0
        public Level CreateLevelAtElevation(Length elevation)
        {
            Level level = Level.Create(doc, elevation);

            level.Name = "Level " + levelCounter;
            levelCounter++;
            IEnumerable <ViewFamilyType> viewFamilyTypes;

            viewFamilyTypes                       = from elem in new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType))
                                         let type = elem as ViewFamilyType
                                                    where type.ViewFamily == ViewFamily.FloorPlan
                                                    select type;
            ViewPlan floorView = ViewPlan.Create(doc, viewFamilyTypes.First().Id, level.Id);

            viewFamilyTypes                       = from elem in new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType))
                                         let type = elem as ViewFamilyType
                                                    where type.ViewFamily == ViewFamily.CeilingPlan
                                                    select type;
            ViewPlan ceilingView = ViewPlan.Create(doc, viewFamilyTypes.First().Id, level.Id);

            return(level);
        }
        /// <summary>
        /// Sample code from Revit API help file What's New
        /// section on View API and View Creation.
        /// </summary>
        void ViewApiCreateViewSample()
        {
            Document  doc          = null;
            Level     level        = null;
            ElementId viewFamily3d = ElementId.InvalidElementId;

            IEnumerable <ViewFamilyType> viewFamilyTypes
                = from e in new FilteredElementCollector(doc)
                  .OfClass(typeof(ViewFamilyType))
                  let type = e as ViewFamilyType
                             where type.ViewFamily == ViewFamily.CeilingPlan
                             select type;

            ViewPlan ceilingPlan = ViewPlan.Create(doc,
                                                   viewFamilyTypes.First().Id, level.Id);

            ceilingPlan.Name = "New Ceiling Plan for "
                               + level.Name;

            ceilingPlan.DetailLevel = ViewDetailLevel.Fine;

            // 3D views can be created with
            // View3D.CreateIsometric and
            // View3D.CreatePerspective.
            // The new ViewOrientation3D object is used to
            // get or set the orientation of 3D views.

            View3D view = View3D.CreateIsometric(
                doc, viewFamily3d);

            XYZ eyePosition      = new XYZ(10, 10, 10);
            XYZ upDirection      = new XYZ(-1, 0, 1);
            XYZ forwardDirection = new XYZ(1, 0, 1);

            view.SetOrientation(new ViewOrientation3D(
                                    eyePosition, upDirection, forwardDirection));
        }
Exemplo n.º 19
0
        ////[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
        private void CreateViewAndSheet(RoomConversionCandidate candidate)
        {
            // Create plans
            var sheet = ViewSheet.Create(doc, TitleBlockId);

            sheet.Name        = candidate.DestinationSheetName;
            sheet.SheetNumber = candidate.DestinationSheetNumber;

            // Get Centre before placing any views
            var sheetCentre = CentreOfSheet(sheet, doc);

            // Create plan of room
            var plan = ViewPlan.Create(doc, GetFloorPlanViewFamilyTypeId(doc), candidate.Room.Level.Id);

            plan.CropBoxActive  = true;
            plan.ViewTemplateId = ElementId.InvalidElementId;
            plan.Scale          = Scale;
            var originalBoundingBox = candidate.Room.get_BoundingBox(plan);

            // Put them on sheets
            plan.CropBox = CreateOffsetBoundingBox(50000, originalBoundingBox);
            plan.Name    = candidate.DestinationViewName;

            // Shrink the bounding box now that it is placed
            var vp = Viewport.Create(doc, sheet.Id, plan.Id, sheetCentre);

            // Shrink the bounding box now that it is placed
            plan.CropBox = CreateOffsetBoundingBox(CropRegionEdgeOffset, originalBoundingBox);

            // FIXME - To set an empty view title - so far this seems to work with the standard revit template...
            vp.ChangeTypeId(vp.GetValidTypes().Last());

            // FIXME Apply a view template
            // NOTE This could cause trouble with view scales
            plan.ViewTemplateId = ViewTemplateId;
        }
Exemplo n.º 20
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp  = commandData.Application;
            UIDocument    uidoc  = uiapp.ActiveUIDocument;
            Document      doc    = uidoc.Document;
            Selection     sel    = uidoc.Selection;
            var           acview = doc.ActiveView;

            var viewfamilytypes    = doc.TCollector <ViewFamilyType>();
            var viewplanfamilytype = viewfamilytypes.Where(m => m.ViewFamily == ViewFamily.FloorPlan).First();
            var view3Dfamilytype   = viewfamilytypes.Where(m => m.ViewFamily == ViewFamily.ThreeDimensional).First();

            var levels = doc.TCollector <Level>();

            FloorSelector fsui = FloorSelector.Instance;

            fsui.FloorBox.ItemsSource       = levels;
            fsui.FloorBox.DisplayMemberPath = "Name";
            fsui.FloorBox.SelectedIndex     = 0;
            fsui.ShowDialog();

            var targetfloor = fsui.FloorBox.SelectionBoxItem as Level;
            var upperfloor  = levels.Where(m => m.Elevation > targetfloor.Elevation)?.OrderBy(m => m.Elevation)?.FirstOrDefault();

            var categories      = doc.Settings.Categories;
            var modelcategories = categories.Cast <Category>().Where(m => m.CategoryType == CategoryType.Model).ToList();

            var filterslist = new List <ElementFilter>();

            foreach (var modelcategory in modelcategories)
            {
                var categoryfilter = new ElementCategoryFilter(modelcategory.Id);
                filterslist.Add(categoryfilter);
            }
            var logicOrFilter = new LogicalOrFilter(filterslist);
            var collector     = new FilteredElementCollector(doc);
            var modelelements = collector.WherePasses(logicOrFilter).WhereElementIsNotElementType().Where(m => m.Category.CategoryType == CategoryType.Model);

            var modelelementsids = modelelements.Select(m => m.Id).ToList();

            var temboundingbox = default(BoundingBoxXYZ);

            Transaction temtran = new Transaction(doc, "temtransaction");

            temtran.Start();
            var temgroup = doc.Create.NewGroup(modelelementsids);
            var temview  = ViewPlan.Create(doc, viewplanfamilytype.Id, targetfloor.Id);

            temboundingbox = temgroup.get_BoundingBox(temview);
            temtran.RollBack();

            var zMin = targetfloor.Elevation;
            var zMax = upperfloor?.Elevation ?? temboundingbox.Max.Z;

            var oldmin = temboundingbox.Min;
            var oldmax = temboundingbox.Max;

            BoundingBoxXYZ newbox = new BoundingBoxXYZ();

            newbox.Min = new XYZ(oldmin.X, oldmin.Y, zMin);
            newbox.Max = new XYZ(oldmax.X, oldmax.Y, zMax);
            var new3dview = default(View3D);

            doc.Invoke(m =>
            {
                new3dview = View3D.CreateIsometric(doc, view3Dfamilytype.Id);
                new3dview.SetSectionBox(newbox);
            }, "楼层三维");

            uidoc.ActiveView = new3dview;

            return(Result.Succeeded);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Creates or populates Revit elements based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        protected override void Create(Document doc)
        {
            // We may re-use the ActiveView Level and View, since we can't delete them.
            // We will consider that we "created" this level and view for creation metrics.
            Level level = Importer.TheCache.UseElementByGUID <Level>(doc, GlobalId);

            bool reusedLevel = false;
            bool foundLevel  = false;

            if (level == null)
            {
                if (ExistingLevelIdToReuse != ElementId.InvalidElementId)
                {
                    level = doc.GetElement(ExistingLevelIdToReuse) as Level;
                    Importer.TheCache.UseElement(level);
                    ExistingLevelIdToReuse = ElementId.InvalidElementId;
                    reusedLevel            = true;
                }
            }
            else
            {
                foundLevel = true;
            }

            if (level == null)
            {
                level = Level.Create(doc, m_Elevation);
            }
            else
            {
                level.Elevation = m_Elevation;
            }

            if (level != null)
            {
                CreatedElementId = level.Id;
            }

            if (CreatedElementId != ElementId.InvalidElementId)
            {
                if (!foundLevel)
                {
                    if (!reusedLevel)
                    {
                        ElementId viewPlanTypeId = IFCBuildingStorey.GetViewPlanTypeId(doc);
                        if (viewPlanTypeId != ElementId.InvalidElementId)
                        {
                            ViewPlan viewPlan = ViewPlan.Create(doc, viewPlanTypeId, CreatedElementId);
                            if (viewPlan != null)
                            {
                                CreatedViewId = viewPlan.Id;
                            }
                        }

                        if (CreatedViewId == ElementId.InvalidElementId)
                        {
                            Importer.TheLog.LogAssociatedCreationError(this, typeof(ViewPlan));
                        }
                    }
                    else
                    {
                        if (doc.ActiveView != null)
                        {
                            CreatedViewId = doc.ActiveView.Id;
                        }
                    }
                }
            }
            else
            {
                Importer.TheLog.LogCreationError(this, null, false);
            }

            TraverseSubElements(doc);
        }
Exemplo n.º 22
0
        private void CreateLevelsAndMainViewSheets(int id)
        {
            if (uidoc.Document != null)
            {
                if (requestData != null)
                {
                    List <Element> allNonViewElements = getAllNonViewElementsOfDoc();

                    if (requestData.mainSheetsInfo.Count == (requestData.levelsAmount * requestData.mainSheetsAmount))
                    {
                        for (int l = 0; l < requestData.levelsAmount; l++)
                        {
                            double norLevelElevation = l * requestData.levelsDistance;

                            Level  norLevel  = Level.Create(uidoc.Document, norLevelElevation);
                            string levelName = "Level-" + (l + 1).ToString();
                            norLevel.Name = levelName;

                            for (int m = 0; m < requestData.mainSheetsAmount; m++)
                            {
                                Tuple <string, string, string> curMainSheetInfo = requestData.mainSheetsInfo[l * requestData.mainSheetsAmount + m];

                                ElementId titleBlocktId = GetTitleBlockIdByName(requestData.titleBlockName);
                                if (titleBlocktId == null)
                                {
                                    titleBlocktId = new ElementId(-1);
                                }
                                ViewSheet norViewSheet = ViewSheet.Create(uidoc.Document, titleBlocktId);

                                norViewSheet.SheetNumber = curMainSheetInfo.Item1;
                                norViewSheet.Name        = curMainSheetInfo.Item2;

                                View           norSheetViewPlan = null;
                                ViewFamilyType viewFamilyType   = null;

                                FilteredElementCollector collector = new FilteredElementCollector(uidoc.Document);
                                var viewFamilyTypes = collector.OfClass(typeof(ViewFamilyType)).ToElements();

                                foreach (Element e in viewFamilyTypes)
                                {
                                    ViewFamilyType v = e as ViewFamilyType;
                                    if (v.ViewFamily == ViewFamily.FloorPlan)
                                    {
                                        viewFamilyType = v;
                                        break;
                                    }
                                }

                                if ((viewFamilyType != null) && (norLevel != null))
                                {
                                    norSheetViewPlan      = ViewPlan.Create(uidoc.Document, viewFamilyType.Id, norLevel.Id);
                                    norSheetViewPlan.Name = norViewSheet.Name;
                                }

                                if (norSheetViewPlan != null)
                                {
                                    View viewTemplate    = GetViewTemplateByName(curMainSheetInfo.Item3);
                                    bool templateApplied = false;

                                    if (viewTemplate != default(View))
                                    {
                                        List <ElementId> hiddenElemsIds = new List <ElementId>();
                                        foreach (Element curHidVisElem in allNonViewElements)
                                        {
                                            if (curHidVisElem.IsHidden(viewTemplate))
                                            {
                                                hiddenElemsIds.Add(curHidVisElem.Id);
                                            }
                                        }

                                        try
                                        {
                                            norSheetViewPlan.HideElements(hiddenElemsIds);
                                        }
                                        catch (Exception ex)
                                        {
                                        }
                                        try
                                        {
                                            norSheetViewPlan.ViewTemplateId = viewTemplate.Id;
                                            templateApplied = true;
                                        }
                                        catch
                                        {
                                        }
                                    }

                                    try
                                    {
                                        int curMainScale;
                                        if (!templateApplied)
                                        {
                                            curMainScale = GetScaleFromString(requestData.mainSheetsScale);
                                        }
                                        else
                                        {
                                            if (uidoc.Document.DisplayUnitSystem == DisplayUnit.IMPERIAL)
                                            {
                                                curMainScale = GetScaleFromString(viewTemplate.get_Parameter(BuiltInParameter.VIEW_SCALE_PULLDOWN_IMPERIAL).AsValueString());
                                            }
                                            else
                                            {
                                                curMainScale = GetScaleFromString(viewTemplate.get_Parameter(BuiltInParameter.VIEW_SCALE_PULLDOWN_METRIC).AsValueString());
                                            }
                                        }

                                        SetViewForSheet(norSheetViewPlan, norViewSheet, curMainScale);
                                    }
                                    catch (Exception ex)
                                    {
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                    }

                    uidoc.RefreshActiveView();
                }
            }
            else
            {
                TaskDialog.Show("Info", "doc is null");
            }
        }
Exemplo n.º 23
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 viewFamilyTypeElementID = ElementId.InvalidElementId;

            IEnumerable <ElementType> viewFamilyTypes = new FilteredElementCollector(document).OfClass(typeof(ViewFamilyType)).Cast <ElementType>();

            foreach (ViewFamilyType viewFamilyType in viewFamilyTypes)
            {
                if (viewFamilyType.FamilyName == "Floor Plan")
                {
                    viewFamilyTypeElementID = viewFamilyType.Id;
                    break;
                }
            }

            if (viewFamilyTypeElementID == ElementId.InvalidElementId)
            {
                return(null);
            }

            revitViewPlan = ViewPlan.Create(document, viewFamilyTypeElementID, levelElementID);
#if (REVIT2020 || REVIT2021)
            revitViewPlan.Name = viewPlan.ViewName;
#else
            revitViewPlan.ViewName = viewPlan.ViewName;
#endif

            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
                {
                    revitViewPlan.ViewTemplateId = viewPlanTemplate.Id;
                }
            }

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

            refObjects.AddOrReplace(viewPlan, revitViewPlan);
            return(revitViewPlan);
        }
Exemplo n.º 24
0
        private void CreateFrontViewSheets(int id)
        {
            if (uidoc.Document != null)
            {
                if (requestData != null)
                {
                    List <Element> allNonViewElements = getAllNonViewElementsOfDoc();

                    for (int f = 0; f < requestData.frontSheetsInfo.Count; f++)
                    {
                        Tuple <string, string, string> curFrontSheetInfo = requestData.frontSheetsInfo[f];

                        ElementId titleBlocktId = GetTitleBlockIdByName(requestData.titleBlockName);
                        if (titleBlocktId == null)
                        {
                            titleBlocktId = new ElementId(-1);
                        }
                        ViewSheet norViewSheet = ViewSheet.Create(uidoc.Document, titleBlocktId);

                        norViewSheet.SheetNumber = curFrontSheetInfo.Item1;
                        norViewSheet.Name        = curFrontSheetInfo.Item2;

                        View                     norSheetViewPlan        = null;
                        ViewFamilyType           viewFamilyType          = null;
                        FilteredElementCollector collectorViewFamilyType = new FilteredElementCollector(uidoc.Document);
                        var viewFamilyTypes = collectorViewFamilyType.OfClass(typeof(ViewFamilyType)).ToElements();
                        foreach (Element e in viewFamilyTypes)
                        {
                            ViewFamilyType v = e as ViewFamilyType;
                            if (v.ViewFamily == ViewFamily.FloorPlan)
                            {
                                viewFamilyType = v;
                                break;
                            }
                        }

                        Level exLevel = null;
                        FilteredElementCollector collectorLevel = new FilteredElementCollector(uidoc.Document);
                        var levels = collectorLevel.OfClass(typeof(Level)).ToElements();
                        foreach (Element e in levels)
                        {
                            exLevel = e as Level;
                        }

                        if ((viewFamilyType != null) && (exLevel != null))
                        {
                            norSheetViewPlan      = ViewPlan.Create(uidoc.Document, viewFamilyType.Id, exLevel.Id);
                            norSheetViewPlan.Name = norViewSheet.Name;
                        }

                        if (norSheetViewPlan != null)
                        {
                            View viewTemplate = GetViewByName(curFrontSheetInfo.Item3);
                            if (viewTemplate != null)
                            {
                                List <ElementId> hiddenElemsIds = new List <ElementId>();
                                foreach (Element curHidVisElem in allNonViewElements)
                                {
                                    if (curHidVisElem.IsHidden(viewTemplate))
                                    {
                                        hiddenElemsIds.Add(curHidVisElem.Id);
                                    }
                                }

                                try
                                {
                                    norSheetViewPlan.HideElements(hiddenElemsIds);
                                }
                                catch (Exception ex)
                                {
                                }
                            }

                            try
                            {
                                SetViewForSheet(norSheetViewPlan, norViewSheet, 1);
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                        else
                        {
                        }
                    }

                    uidoc.RefreshActiveView();
                }
            }
            else
            {
                TaskDialog.Show("Info", "doc is null");
            }
        }
Exemplo n.º 25
0
        public static void CreateViews(Document curDoc, string viewType, string viewFamilyType, string viewTemplate, string scopeBox, string designOpt, List <Level> m_levels)
        {
            //creates plan or RCP views for each floor level in the supplied model

            //set view type
            ViewFamily viewTypeSetting = default(ViewFamily);

            if (viewType == "CeilingPlan")
            {
                viewTypeSetting = ViewFamily.CeilingPlan;
            }
            else if (viewType == "AreaPlan")
            {
                viewTypeSetting = ViewFamily.AreaPlan;
            }
            else if (viewType == "StructuralPlan")
            {
                viewTypeSetting = ViewFamily.StructuralPlan;
            }
            else
            {
                viewTypeSetting = ViewFamily.FloorPlan;
            }

            //get list of view types
            List <ViewFamilyType> m_vt = new List <ViewFamilyType>();

            m_vt = mFunctions.getViewTypes(curDoc);

            //success and error list
            List <string> m_s = new List <string>();
            List <string> m_e = new List <string>();

            //new transaction
            using (Transaction t = new Transaction(curDoc, "Create views")) {
                //start transaction
                if (t.Start() == TransactionStatus.Started)
                {
                    //create a plan or RCP for specified levels
                    foreach (Level lev in m_levels)
                    {
                        //views for plan only
                        foreach (ViewFamilyType vt in m_vt)
                        {
                            if (vt.Name == viewFamilyType)
                            {
                                try {
                                    //create the plan view
                                    ViewPlan m_fp = null;
                                    m_fp = ViewPlan.Create(curDoc, vt.Id, lev.Id);

                                    //rename the view
                                    m_fp.Name = lev.Name.ToUpper() + " " + vt.Name.ToUpper();
                                    m_s.Add(lev.Name.ToUpper() + " " + vt.Name.ToUpper());

                                    //modify the view as needed
                                    //-----------------------------------------------------
                                    //add view template to view
                                    if (viewTemplate != "None")
                                    {
                                        m_fp.ViewTemplateId = mFunctions.getViewTemplateID(viewTemplate, curDoc);
                                    }

                                    //add scope box to view
                                    if (scopeBox != "None")
                                    {
                                        Parameter curParam = null;
                                        curParam = m_fp.get_Parameter(BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP);

                                        if (curParam.Definition.Name.ToString() == "Scope Box")
                                        {
                                            //check if scope box exist
                                            if (mFunctions.doesScopeBoxExist(scopeBox, curDoc))
                                            {
                                                try {
                                                    //set scope box value
                                                    curParam.Set(mFunctions.getScopeBoxID(scopeBox, curDoc));
                                                } catch (Exception ex) {
                                                    Debug.Print(ex.Message);
                                                }
                                            }
                                            else
                                            {
                                                Debug.Print("SCOPE BOX DOESN'T EXIST");
                                            }
                                        }
                                    }

                                    //add design option to view
                                    if (designOpt != "None")
                                    {
                                        //assign selected design option to view
                                        DesignOption curDesignOption = mFunctions.getDesignOptionByName(curDoc, designOpt);

                                        Parameter desOptParam = m_fp.get_Parameter(BuiltInParameter.VIEWER_OPTION_VISIBILITY);

                                        try {
                                            desOptParam.Set(curDesignOption.Id);
                                        } catch (Exception ex) {
                                            TaskDialog.Show("error", "could not set design option paramerter");
                                        }
                                    }
                                } catch (Exception ex) {
                                    m_e.Add(ex.Message + ": " + lev.Name.ToUpper() + " " + vt.Name.ToUpper());
                                }
                            }
                        }
                    }

                    //report views created
                    if (m_s.Count > 0)
                    {
                        using (TaskDialog m_td = new TaskDialog("Success")) {
                            m_td.MainInstruction = "Created views:";
                            foreach (string x_loopVariable in m_s)
                            {
                                m_td.MainContent += x_loopVariable + Constants.vbCr;
                            }
                            m_td.Show();
                        }
                    }

                    //report errors if any
                    if (m_e.Count > 0)
                    {
                        using (TaskDialog m_td = new TaskDialog("Errors")) {
                            m_td.MainInstruction = "Issues with views:";
                            foreach (string x_loopVariable in m_e)
                            {
                                m_td.MainContent += x_loopVariable + Constants.vbCr;
                            }
                            m_td.Show();
                        }
                    }

                    //commit
                    t.Commit();
                }
            }
        }
Exemplo n.º 26
0
        public static ViewPlan CreateWorksetFloorPlan(Document doc, ItemInfo itemInfo, ViewFamilyType viewPlanFamilyType, Level planLevel, bool overwrite)
        {
            ViewPlan viewPlan = null;
            string   viewName = planLevel.Name + " - " + itemInfo.ItemName;

            using (TransactionGroup tg = new TransactionGroup(doc))
            {
                tg.Start("Create Floor Plan");
                try
                {
                    FilteredElementCollector collector = new FilteredElementCollector(doc);
                    List <ViewPlan>          viewPlans = collector.OfClass(typeof(ViewPlan)).ToElements().Cast <ViewPlan>().ToList();
                    var views = from view in viewPlans where view.Name == viewName select view;
                    if (views.Count() > 0)
                    {
                        if (overwrite)
                        {
                            viewPlan = views.First();
                        }
                        else
                        {
                            return(viewPlan);
                        }
                    }

                    if (null == viewPlan)
                    {
                        using (Transaction trans = new Transaction(doc))
                        {
                            trans.Start("Create Plan View");
                            try
                            {
                                viewPlan      = ViewPlan.Create(doc, viewPlanFamilyType.Id, planLevel.Id);
                                viewPlan.Name = viewName;
                                trans.Commit();
                            }
                            catch (Exception ex)
                            {
                                trans.RollBack();
                                MessageBox.Show("Failed to create plan view.\n" + ex.Message, "Create Plan View", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                    }


                    using (Transaction trans = new Transaction(doc))
                    {
                        trans.Start("Set Visibility");
                        try
                        {
                            FilteredWorksetCollector worksetCollector = new FilteredWorksetCollector(doc);
                            IList <Workset>          worksetList      = worksetCollector.ToWorksets();
                            var worksets = from workset in worksetList where workset.Kind == WorksetKind.UserWorkset select workset;
                            foreach (Workset ws in worksets)
                            {
                                if (ws.Kind == WorksetKind.UserWorkset)
                                {
                                    if (ws.Id.IntegerValue == itemInfo.ItemId)
                                    {
                                        viewPlan.SetWorksetVisibility(ws.Id, WorksetVisibility.Visible);
                                    }
                                    else
                                    {
                                        viewPlan.SetWorksetVisibility(ws.Id, WorksetVisibility.Hidden);
                                    }
                                }
                            }
                            trans.Commit();
                        }
                        catch (Exception ex)
                        {
                            trans.RollBack();
                            MessageBox.Show("Failed to set visibility.\n" + ex.Message, "Set Visibility", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
                catch (Exception ex)
                {
                    tg.RollBack();
                    MessageBox.Show("Failed to create floor plans by worksets.\n" + ex.Message, "Create Floor Plans by Worksets", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                tg.Assimilate();
            }
            return(viewPlan);
        }
Exemplo n.º 27
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;


            List <Element> levels = new List <Element>(new FilteredElementCollector(doc)
                                                       .OfClass(typeof(Level))
                                                       .ToElements());
            List <Element> viewFamilyTypes = new List <Element>(new FilteredElementCollector(doc)
                                                                .OfClass(typeof(ViewFamilyType))
                                                                .ToElements());

            // Get Floor Plan Family Type element

            ViewFamilyType viewFamilyFloorPlanType = null;

            foreach (ViewFamilyType viewFamilyType in viewFamilyTypes)
            {
                if (viewFamilyType.ViewFamily.Equals(ViewFamily.FloorPlan))
                {
                    viewFamilyFloorPlanType = viewFamilyType;
                    break;
                }
            }

            // Asserting viewFamilyFloorPlanType got the familyType
            if (viewFamilyFloorPlanType == null)
            {
                _ = System.Windows.Forms.MessageBox.Show("Não foi encontrado o tipo de planta de piso.",
                                                         "Criar plantas");
                return(Result.Failed);
            }

            // Select levels with SelectFromList form
            SelectFromList selectFromList = new SelectFromList(levels);

            selectFromList.ShowDialog();

            if (selectFromList.DialogResult == System.Windows.Forms.DialogResult.Cancel)
            {
                return(Result.Cancelled);
            }
            levels = selectFromList.GetChoosedElements();

            // Filtered element collector is iterable
            using (Transaction tx = new Transaction(doc))
            {
                foreach (Element level in levels)
                {
                    tx.Start("Planta " + level.Name);
                    _ = ViewPlan.Create(doc, viewFamilyFloorPlanType.Id, level.Id);
                    tx.Commit();
                }
            }

            return(Result.Succeeded);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Main function to create all views
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        private bool makeViews(Document doc)
        {
            // Get all View Type Families for Floor Plans
            IEnumerable <Element> viewFTypesFP =
                from e in new FilteredElementCollector(_doc).OfClass(typeof(ViewFamilyType))
                let type = e as ViewFamilyType
                           where type.ViewFamily == ViewFamily.FloorPlan
                           select type;

            // Get all View Type Families for Floor Plans
            IEnumerable <Element> viewFTypesCP =
                from e in new FilteredElementCollector(_doc).OfClass(typeof(ViewFamilyType))
                let type = e as ViewFamilyType
                           where type.ViewFamily == ViewFamily.CeilingPlan
                           select type;

            // Failures and Success
            string m_fails  = "";
            string m_sucess = "";

            // Check that atleast on level is checked
            if (this.checkedListBox1.CheckedItems.Count == 0)
            {
                MessageBox.Show("Please choose at least one Level to create a view.", "Hold On Silly...");
                return(false);
            }
            else
            {
                // Loop through each item checked
                foreach (Object obj in this.checkedListBox1.CheckedItems)
                {
                    // Step Progress
                    this.progressBar1.Increment(1);
                    System.Windows.Forms.Application.DoEvents();

                    // Get the level
                    Level  level          = obj as Level;
                    string viewdiscipline = this.cbViewDiscipline.SelectedValue.ToString();
                    string viewtype       = this.cbViewType.SelectedValue.ToString();
                    string viewtypename   = this.cbViewType.SelectedValue.ToString();
                    string subdiscipline  = this.textSubDiscipline.Text;
                    string viewname       = "";

                    if (app.myProduct == "MEP")
                    {
                        viewname = subdiscipline + " " + level.Name + " " + viewtypename;
                    }
                    else
                    {
                        viewname = viewdiscipline + " " + level.Name + " " + viewtypename;
                    }

                    viewname = viewname.ToUpper();

                    // Check that sub-discipline box has been filled
                    if (app.myProduct == "MEP" && subdiscipline.Trim() == "")
                    {
                        MessageBox.Show("Sub-Discipline can not be blank.", "Hold On ...");
                        return(false);
                    }
                    else
                    {
                        // Start Transaction
                        Transaction t = new Transaction(doc, "Create " + viewdiscipline + " " + level.Name + " " + viewtype);
                        t.Start();

                        // View Name (for errors)
                        string m_viewName = viewdiscipline + " " + level.Name + " " + viewtype;

                        try
                        {
                            // Chcek viewtype
                            if (viewtype == "Floor Plan")
                            {
                                // Create the view
                                ViewPlan viewplan = ViewPlan.Create(_doc, viewFTypesFP.First().Id, level.Id);

                                // Set the discipline based on combobox selection
                                if (viewdiscipline == "Architectural")
                                {
                                    viewplan.get_Parameter(BuiltInParameter.VIEW_DISCIPLINE).Set(1);
                                }
                                else if (viewdiscipline == "Structural")
                                {
                                    viewplan.get_Parameter(BuiltInParameter.VIEW_DISCIPLINE).Set(2);
                                }
                                else if (viewdiscipline == "Mechanical")
                                {
                                    viewplan.get_Parameter(BuiltInParameter.VIEW_DISCIPLINE).Set(4);
                                }
                                else if (viewdiscipline == "Electrical")
                                {
                                    viewplan.get_Parameter(BuiltInParameter.VIEW_DISCIPLINE).Set(8);
                                }
                                else if (viewdiscipline == "Coordination")
                                {
                                    viewplan.get_Parameter(BuiltInParameter.VIEW_DISCIPLINE).Set(4095);
                                }
                                else
                                {
                                    MessageBox.Show("Invalid Discipline", "Error");
                                    break;
                                }

                                if (app.myProduct == "MEP")
                                {
                                    // Set Sub-Discipline based on text box entry
                                    clsParameterData.GetParameterByName(viewplan, "Sub-Discipline").Set(subdiscipline);
                                }
                            }
                            else
                            {
                                // Check viewtype
                                ViewPlan viewplan = ViewPlan.Create(_doc, viewFTypesCP.First().Id, level.Id);

                                // Set the discipline based on combobox selection
                                if (viewdiscipline == "Architectural")
                                {
                                    viewplan.get_Parameter(BuiltInParameter.VIEW_DISCIPLINE).Set(1);
                                }
                                else if (viewdiscipline == "Structural")
                                {
                                    viewplan.get_Parameter(BuiltInParameter.VIEW_DISCIPLINE).Set(2);
                                }
                                else if (viewdiscipline == "Mechanical")
                                {
                                    viewplan.get_Parameter(BuiltInParameter.VIEW_DISCIPLINE).Set(4);
                                }
                                else if (viewdiscipline == "Electrical")
                                {
                                    viewplan.get_Parameter(BuiltInParameter.VIEW_DISCIPLINE).Set(8);
                                }
                                else if (viewdiscipline == "Coordination")
                                {
                                    viewplan.get_Parameter(BuiltInParameter.VIEW_DISCIPLINE).Set(4095);
                                }
                                else
                                {
                                    MessageBox.Show("Invalid Discipline", "Error");
                                    break;
                                }

                                if (app.myProduct == "MEP")
                                {
                                    // Set the discipline based on combobox selection
                                    clsParameterData.GetParameterByName(viewplan, "Sub-Discipline").Set(subdiscipline);
                                }
                            }

                            // Commit
                            m_sucess += "\n" + m_viewName.ToUpper();
                            t.Commit();
                        }
                        catch
                        {
                            // Rollback on Failure
                            t.RollBack();
                            m_fails += "\n" + m_viewName.ToUpper();
                            // return false;
                        }
                    }
                }
            }

            // Report to the user
            TaskDialog m_td = new TaskDialog("Here's What Happend:");

            m_td.MainContent     = "Successful Views:" + m_sucess + "\n\nFailed Views:" + m_fails;
            m_td.MainInstruction = "Created Some Views... or Not:";
            m_td.Show();
            return(true);
        }
Exemplo n.º 29
0
        private void AddNewViewSheets(int id)
        {
            if (uidoc.Document != null)
            {
                if (requestData != null)
                {
                    Level firstLevel = getFirstLevel(uidoc.Document);
                    if (firstLevel != null)
                    {
                        for (int i = 0; i < requestData.viewSheetsInfo.Count; i++)
                        {
                            Tuple <string, string, string, string, string> curViewSheetInfo = requestData.viewSheetsInfo[i];

                            ElementId titleBlocktId = GetTitleBlockIdByName(curViewSheetInfo.Item5);
                            if (titleBlocktId == null)
                            {
                                titleBlocktId = new ElementId(-1);
                            }
                            ViewSheet norViewSheet = ViewSheet.Create(uidoc.Document, titleBlocktId);

                            norViewSheet.SheetNumber = curViewSheetInfo.Item1;
                            norViewSheet.Name        = curViewSheetInfo.Item2;


                            List <Element> allNonViewElements = getAllNonViewElementsOfDoc();

                            View                     norSheetViewPlan = null;
                            ViewFamilyType           viewFamilyType   = null;
                            FilteredElementCollector collector        = new FilteredElementCollector(uidoc.Document);
                            var viewFamilyTypes = collector.OfClass(typeof(ViewFamilyType)).ToElements();
                            foreach (Element e in viewFamilyTypes)
                            {
                                ViewFamilyType v = e as ViewFamilyType;
                                if (v.ViewFamily == ViewFamily.FloorPlan)
                                {
                                    viewFamilyType = v;
                                    break;
                                }
                            }



                            int curMainScale = GetScaleFromString(curViewSheetInfo.Item3);

                            if ((viewFamilyType != null) && (firstLevel != null))
                            {
                                norSheetViewPlan      = ViewPlan.Create(uidoc.Document, viewFamilyType.Id, firstLevel.Id);
                                norSheetViewPlan.Name = norViewSheet.Name + "_" + norViewSheet.SheetNumber;
                            }

                            if (norSheetViewPlan != null)
                            {
                                View viewTemplate = GetViewByName(curViewSheetInfo.Item4);
                                if (viewTemplate != null)
                                {
                                    List <ElementId> hiddenElemsIds = new List <ElementId>();
                                    foreach (Element curHidVisElem in allNonViewElements)
                                    {
                                        if (curHidVisElem.IsHidden(viewTemplate))
                                        {
                                            hiddenElemsIds.Add(curHidVisElem.Id);
                                        }
                                    }

                                    try
                                    {
                                        norSheetViewPlan.HideElements(hiddenElemsIds);
                                    }
                                    catch (Exception ex)
                                    {
                                    }
                                }

                                try
                                {
                                    SetViewForSheet(norSheetViewPlan, norViewSheet, curMainScale);
                                }
                                catch (Exception ex)
                                {
                                    TaskDialog.Show("Info", "Exception:" + ex.ToString());
                                }
                            }
                        }

                        uidoc.Document.Regenerate();
                        uidoc.RefreshActiveView();
                    }
                    else
                    {
                        TaskDialog.Show("Info", "firstLevel is null");
                    }
                }
                else
                {
                    TaskDialog.Show("Info", "requestData is null");
                }
            }
            else
            {
                TaskDialog.Show("Info", "doc is null");
            }
        }
Exemplo n.º 30
0
        private void AddNewViewSheets_OLD(int id)
        {
            if (uidoc.Document != null)
            {
                if (requestData != null)
                {
                    for (int i = 0; i < requestData.viewSheetsInfo.Count; i++)
                    {
                        Tuple <string, string, string, string, string> curViewSheetInfo = requestData.viewSheetsInfo[i];

                        ElementId titleBlocktId = GetTitleBlockIdByName(curViewSheetInfo.Item5);
                        if (titleBlocktId == null)
                        {
                            titleBlocktId = new ElementId(-1);
                        }
                        ViewSheet norViewSheet = ViewSheet.Create(uidoc.Document, titleBlocktId);

                        norViewSheet.SheetNumber = curViewSheetInfo.Item1;
                        norViewSheet.Name        = curViewSheetInfo.Item2;


                        View viewPlan = GetViewByName(curViewSheetInfo.Item4);
                        if (viewPlan == null)
                        {
                            ViewFamilyType           viewFamilyType = null;
                            FilteredElementCollector collector      = new FilteredElementCollector(uidoc.Document);
                            var viewFamilyTypes = collector.OfClass(typeof(ViewFamilyType)).ToElements();
                            foreach (Element e in viewFamilyTypes)
                            {
                                ViewFamilyType v = e as ViewFamilyType;
                                if (v.ViewFamily == ViewFamily.FloorPlan)
                                {
                                    viewFamilyType = v;
                                    break;
                                }
                            }
                            Level exLevel = null;
                            FilteredElementCollector collectorLevel = new FilteredElementCollector(uidoc.Document);
                            var levels = collectorLevel.OfClass(typeof(Level)).ToElements();
                            foreach (Element e in levels)
                            {
                                exLevel = e as Level;
                            }

                            if ((viewFamilyType != null) && (exLevel != null))
                            {
                                viewPlan      = ViewPlan.Create(uidoc.Document, viewFamilyType.Id, exLevel.Id);
                                viewPlan.Name = curViewSheetInfo.Item4;
                            }
                        }
                        else
                        {
                        }


                        if (viewPlan != null)
                        {
                            try
                            {
                                int curMainScale = GetScaleFromString(curViewSheetInfo.Item3);
                                SetViewForSheet(viewPlan, norViewSheet, curMainScale);
                            }
                            catch (Exception ex)
                            {
                                TaskDialog.Show("Exc", ex.Message + " " + norViewSheet.SheetNumber);
                            }
                        }
                    }

                    uidoc.RefreshActiveView();
                }
            }
            else
            {
                TaskDialog.Show("Info", "doc is null");
            }
        }