Exemplo n.º 1
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);
                    }
                }
            }
        }
        private void settingCompleted()
        {
            if (!double.TryParse(this.ObstacleSetting.Text, out this.MinimumHeight))
            {
                MessageBox.Show("Enter a valid number for the 'Minimum Height of Visual Obstacles'!\n(Larger than zero)");
                return;
            }
            else if (this.MinimumHeight < 0)
            {
                MessageBox.Show("Enter a valid number for the 'Minimum Height of Visual Obstacles'!\n(Larger than zero)");
                return;
            }
            if (!double.TryParse(this.CurveApproximationLength_.Text, out this.CurveApproximationLength))
            {
                MessageBox.Show("Enter a valid number for 'Curve Approximation Length'!");
                return;
            }
            if (!double.TryParse(this.MinimumCurveLength_.Text, out this.MinimumCurveLength))
            {
                MessageBox.Show("Enter a valid number for 'Minimum Curve Approximation Length'!\n(This length should be smaller than curve approximation length and larger than zero)");
                return;
            }
            else if (this.MinimumCurveLength >= this.CurveApproximationLength || this.MinimumCurveLength <= 0f)
            {
                MessageBox.Show("Enter a valid number for 'Minimum Curve Approximation Length'!\n(This length should be smaller than curve approximation length and larger than zero)");
                return;
            }
            if (this.FloorPlan == null)
            {
                MessageBox.Show("Select a floor plan to continue!");
                return;
            }
            using (Transaction t = new Transaction(this.uidoc.Document, "Update View Range"))
            {
                t.Start();
                try
                {
                    PlanViewRange viewRange          = this.FloorPlan.GetViewRange();
                    ElementId     topClipPlane       = viewRange.GetLevelId(PlanViewPlane.TopClipPlane);
                    double        revitMinimumHeight = UnitConversion.Convert(this.MinimumHeight, this.unitType, Length_Unit_Types.FEET);


                    if (viewRange.GetOffset(PlanViewPlane.TopClipPlane) < revitMinimumHeight)
                    {
                        viewRange.SetOffset(PlanViewPlane.CutPlane, revitMinimumHeight);
                        viewRange.SetOffset(PlanViewPlane.TopClipPlane, revitMinimumHeight);
                    }
                    else
                    {
                        viewRange.SetOffset(PlanViewPlane.CutPlane, revitMinimumHeight);
                    }
                    this.FloorPlan.SetViewRange(viewRange);
                }
                catch (Exception ex)
                {
                    t.Commit();
                    MessageBox.Show(ex.Report());
                }
                t.Commit();
            }
            uidoc.ActiveView    = this.FloorPlan;
            this.floorPlanNames = null;
            this.DialogResult   = true;
            this.Close();
        }
Exemplo n.º 3
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;

            if (!(doc.ActiveView is ViewPlan viewPlan))
            {
                TaskDialog.Show("Please select Plan view", "Select Plan view to change it's View Range");
                return(Result.Succeeded);
            }
            PlanViewRange viewRange  = viewPlan.GetViewRange();
            double        CCut       = viewRange.GetOffset(PlanViewPlane.CutPlane);
            double        CTop       = viewRange.GetOffset(PlanViewPlane.TopClipPlane);
            RibbonPanel   inputpanel = null;
            ComboBox      inputbox   = null;

            foreach (RibbonPanel panel in uiapp.GetRibbonPanels("Exp. Add-Ins"))
            {
                if (panel.Name == "View Tools")
                {
                    inputpanel = panel;
                }
            }
            foreach (RibbonItem item in inputpanel.GetItems())
            {
                if (item.Name == "ShiftRange")
                {
                    inputbox = (ComboBox)item;
                }
            }
            List <Double> vrOpts = new List <Double> {
                StoreExp.vrOpt1, StoreExp.vrOpt2, StoreExp.vrOpt3,
                StoreExp.vrOpt4, StoreExp.vrOpt5, StoreExp.vrOpt6
            };
            double mod = vrOpts[Int32.Parse(inputbox.Current.Name)];

            if (viewPlan.ViewType != ViewType.CeilingPlan)
            {
                viewRange.SetOffset(PlanViewPlane.CutPlane, CCut + mod);
                viewRange.SetOffset(PlanViewPlane.TopClipPlane, CCut + mod);
            }
            if (viewPlan.ViewType == ViewType.CeilingPlan)
            {
                viewRange.SetOffset(PlanViewPlane.TopClipPlane, CTop + mod);
                viewRange.SetOffset(PlanViewPlane.ViewDepthPlane, CTop + mod);
            }
            using (Transaction t = new Transaction(doc, "Set View Range"))
            {
                try
                {
                    t.Start();
                    viewPlan.SetViewRange(viewRange);
                    t.Commit();
                }
                catch
                { TaskDialog.Show("Error", "Cannot shift ViewRange this way."); }
            }
            return(Result.Succeeded);
        }
Exemplo n.º 4
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;

            if (!(doc.ActiveView is ViewPlan viewPlan))
            {
                TaskDialog.Show("Please select Plan view", "Select Plan view to change it's View Range");
                return(Result.Succeeded);
            }
            Level  level    = viewPlan.GenLevel;
            View3D view3d   = null;
            string source3d = StoreExp.ThreeDview;

            if (source3d == "Same Name")
            {
                source3d = viewPlan.Name;
            }
            try
            {
                view3d = (from v in new FilteredElementCollector(doc).OfClass(typeof(View3D)).Cast <View3D>() where v.Name == source3d select v).First();
            }
            catch
            {
                TaskDialog.Show("Please rename 3D view or Select in Options", "Rename 3D view to match:" + Environment.NewLine + "'" + viewPlan.Name +
                                "'" + Environment.NewLine + " or, Select source 3D view in Options");
                return(Result.Succeeded);
            }
            BoundingBoxXYZ bbox        = view3d.GetSectionBox();
            Transform      transform   = bbox.Transform;
            double         bboxOriginZ = transform.Origin.Z;
            double         minZ        = bbox.Min.Z + bboxOriginZ;
            double         maxZ        = bbox.Max.Z + bboxOriginZ;

            PlanViewRange viewRange = viewPlan.GetViewRange();

            viewRange.SetLevelId(PlanViewPlane.TopClipPlane, level.Id);
            viewRange.SetLevelId(PlanViewPlane.CutPlane, level.Id);
            viewRange.SetLevelId(PlanViewPlane.BottomClipPlane, level.Id);
            viewRange.SetLevelId(PlanViewPlane.ViewDepthPlane, level.Id);
            if (viewPlan.ViewType == ViewType.CeilingPlan)
            {
                viewRange.SetOffset(PlanViewPlane.CutPlane, minZ - level.Elevation);
                viewRange.SetOffset(PlanViewPlane.TopClipPlane, maxZ - level.Elevation);
                viewRange.SetOffset(PlanViewPlane.ViewDepthPlane, maxZ - level.Elevation);
                viewRange.SetOffset(PlanViewPlane.BottomClipPlane, minZ - level.Elevation);
            }
            if (viewPlan.ViewType != ViewType.CeilingPlan)
            {
                viewRange.SetOffset(PlanViewPlane.CutPlane, maxZ - level.Elevation);
                viewRange.SetOffset(PlanViewPlane.BottomClipPlane, minZ - level.Elevation);
                viewRange.SetOffset(PlanViewPlane.ViewDepthPlane, minZ - level.Elevation);
                viewRange.SetOffset(PlanViewPlane.TopClipPlane, maxZ - level.Elevation);
            }
            using (Transaction t = new Transaction(doc))
            {
                t.Start("Set View Range");
                viewPlan.SetViewRange(viewRange);
                t.Commit();
            }
            return(Result.Succeeded);
        }