コード例 #1
0
        public static View3D GetMatching3DView(this View view, Document doc)
        {
            ViewFamilyType viewFamilyType = (from v in new FilteredElementCollector(doc).
                                             OfClass(typeof(ViewFamilyType)).
                                             Cast <ViewFamilyType>()
                                             where v.ViewFamily == ViewFamily.ThreeDimensional
                                             select v).First();

            View3D view3d = View3D.CreateIsometric(doc, viewFamilyType.Id);

            view3d.Name = view.Name + " 3D temp view";

            ViewBox myviewbox = GetViewBox(view);

            if (myviewbox.bbox == null)
            {
                BoundingBoxXYZ boundingBoxXYZ = new BoundingBoxXYZ();



                boundingBoxXYZ.Min = myviewbox.P1;
                boundingBoxXYZ.Max = myviewbox.P2;
                view3d.SetSectionBox(boundingBoxXYZ);
            }
            else
            {
                view3d.SetSectionBox(myviewbox.bbox);
            }
            view3d.SetOrientation(new ViewOrientation3D(myviewbox.EyePosition, myviewbox.DirectionUp, myviewbox.DirectionView));



            foreach (Category cat in doc.Settings.Categories)
            {
                try
                {
                    if (cat.CategoryType == CategoryType.Model && cat.get_AllowsVisibilityControl(view3d))
                    {
                        view3d.SetVisibility(cat, view.GetVisibility(cat));
                    }
                }
                catch (System.Exception e) { }
            }


            doc.Regenerate();

            return(view3d);
        }
コード例 #2
0
        /// <summary>
        /// 建立新的3D视图,并将其剖面框设为选择房间的大小
        /// create a new 3D view and change the section box fix the selected room
        /// </summary>
        /// <returns></returns>
        public View3D Create3DView()
        {
            using (Transaction tran = new Transaction(DocSet.doc))
            {
                var collector       = new FilteredElementCollector(DocSet.doc).OfClass(typeof(ViewFamilyType));
                var viewFamilyTypes = from elem in collector
                                      let type = elem as ViewFamilyType
                                                 where type.ViewFamily == ViewFamily.ThreeDimensional
                                                 select type;

                tran.Start("Create A new 3Dview");
                View3D view = View3D.CreateIsometric(DocSet.doc, viewFamilyTypes.First().Id);

                //设定一个新的截面框
                BoundingBoxXYZ boxXyz = new BoundingBoxXYZ();
                XYZ            max    = DocSet.selRoom.get_BoundingBox(view).Max;
                XYZ            min    = DocSet.selRoom.get_BoundingBox(view).Min;
                boxXyz.Max = new XYZ(max.X + 2, max.Y + 2, max.Z);
                boxXyz.Min = new XYZ(min.X - 2, min.Y - 2, min.Z - 0.5);

                view.OrientTo(new XYZ(1, 1, -1));//将3D视角转到左上
                view.SetSectionBox(boxXyz);

                string name = "ISO ";
                name         += _SoANumber;
                view.ViewName = name;
                var par = view.get_Parameter(BuiltInParameter.VIEW_DESCRIPTION).Set(DocSet.selRoom.Name + " - ISOMETRIC");
                tran.Commit();
                //view.SetOrientation(new ViewOrientation3D )

                return(view);
            }
        }
コード例 #3
0
 public static void ApplySectionBoxToView(BoundingBoxXYZ boundingBox, View3D view3D)
 {
     if (boundingBox != null || view3D != null)
     {
         view3D?.SetSectionBox(boundingBox);
     }
 }
コード例 #4
0
        public void Showview(Document doc, ICollection <ElementId> elementIds)
        {
            View3D     view      = Get3Dview(doc);
            List <XYZ> pointsmax = new List <XYZ>();
            List <XYZ> pointsmin = new List <XYZ>();

            foreach (var i in elementIds)
            {
                Element        element = doc.GetElement(i);
                BoundingBoxXYZ boxXYZ  = element.get_BoundingBox(view);
                XYZ            max     = boxXYZ.Max;
                XYZ            min     = boxXYZ.Min;
                pointsmax.Add(max);
                pointsmin.Add(min);
            }
            var            Bpoint         = new Maxpoint(pointsmax);
            var            Vpoint         = new Minpoint(pointsmin);
            XYZ            Maxpoint       = new XYZ(Bpoint.Xmax, Bpoint.Ymax, Bpoint.Zmax);
            XYZ            Minpoint       = new XYZ(Vpoint.Xmin, Vpoint.Ymin, Vpoint.Zmin);
            BoundingBoxXYZ viewSectionBox = new BoundingBoxXYZ();

            viewSectionBox.Max = Maxpoint;
            viewSectionBox.Min = Minpoint;
            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Move And Resize Section Box");
                view.SetSectionBox(viewSectionBox);
                tx.Commit();
            }
            uidoc.ActiveView = view;
            uidoc.Selection.SetElementIds(elementIds);
            uidoc.RefreshActiveView();
            uidoc.ShowElements(elementIds);
        }
コード例 #5
0
 ////[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "1")]
 public static void ApplySectionBoxToView(BoundingBoxXYZ bounds, View3D view)
 {
     if (bounds != null || view != null)
     {
         view.SetSectionBox(bounds);
     }
 }
コード例 #6
0
        private void CreateSectionBox(bool execute, Document doc)
        {
            try
            {
                Element element = m_doc.GetElement(new ElementId(currentElement.ElementId));
                if (null != element)
                {
                    using (Transaction trans = new Transaction(doc))
                    {
                        trans.Start("Section Box");
                        try
                        {
                            if (execute)
                            {
                                BoundingBoxXYZ boundingBox = element.get_BoundingBox(null);
                                if (null != boundingBox)
                                {
                                    XYZ            minXYZ            = new XYZ(boundingBox.Min.X - 3, boundingBox.Min.Y - 3, boundingBox.Min.Z - 3);
                                    XYZ            maxXYZ            = new XYZ(boundingBox.Max.X + 3, boundingBox.Max.Y + 3, boundingBox.Max.Z + 3);
                                    BoundingBoxXYZ offsetBoundingBox = new BoundingBoxXYZ();
                                    offsetBoundingBox.Min = minXYZ;
                                    offsetBoundingBox.Max = maxXYZ;
#if RELEASE2013
                                    activeView.SectionBox = offsetBoundingBox;
#else
                                    activeView.SetSectionBox(offsetBoundingBox);
                                    activeView.GetSectionBox().Enabled = true;
#endif
                                }
                            }
                            else
                            {
#if RELEASE2013
                                activeView.SectionBox = null;
#else
                                Parameter parameter = activeView.get_Parameter(BuiltInParameter.VIEWER_MODEL_CLIP_BOX_ACTIVE);
                                if (null != parameter)
                                {
                                    parameter.Set(0);
                                }
                                activeView.GetSectionBox().Enabled = false;
#endif
                            }
                            trans.Commit();
                        }
                        catch (Exception ex)
                        {
                            string message = ex.Message;
                            trans.RollBack();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create a section box around the selected element.\n" + ex.Message, "Create Section Box", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
コード例 #7
0
 public void SetBoundingBox(Document doc, ICollection <ElementId> ids)
 {
     try
     {
         View3D view3D = doc.ActiveView as View3D;
         bool   flag   = view3D == null;
         if (flag)
         {
             TaskDialog.Show("Error", "Please go to 3D view");
         }
         else
         {
             XYZ xyz  = XYZ.Zero;
             XYZ xyz2 = XYZ.Zero;
             foreach (ElementId id in ids)
             {
                 FamilyInstance familyInstance = doc.GetElement(id) as FamilyInstance;
                 bool           flag2          = familyInstance == null;
                 if (!flag2)
                 {
                     BoundingBoxXYZ boundingBoxXYZ = familyInstance.get_BoundingBox(view3D);
                     XYZ            min            = boundingBoxXYZ.Min;
                     XYZ            max            = boundingBoxXYZ.Max;
                     bool           flag3          = xyz.IsAlmostEqualTo(XYZ.Zero);
                     if (flag3)
                     {
                         xyz = min;
                     }
                     else
                     {
                         xyz = new XYZ(Math.Min(xyz.X, min.X), Math.Min(xyz.Y, min.Y), Math.Min(xyz.Z, min.Z));
                     }
                     bool flag4 = xyz2.IsAlmostEqualTo(XYZ.Zero);
                     if (flag4)
                     {
                         xyz2 = max;
                     }
                     else
                     {
                         xyz2 = new XYZ(Math.Max(xyz2.X, max.X), Math.Max(xyz2.Y, max.Y), Math.Max(xyz2.Z, max.Z));
                     }
                 }
             }
             Transaction transaction = new Transaction(doc, "SetBoundingBox");
             transaction.Start();
             BoundingBoxXYZ boundingBoxXYZ2 = new BoundingBoxXYZ();
             boundingBoxXYZ2.Min       = xyz - new XYZ(1.0, 1.0, 1.0);
             boundingBoxXYZ2.Max       = xyz2 + new XYZ(1.0, 1.0, 1.0);
             view3D.IsSectionBoxActive = true;
             view3D.SetSectionBox(boundingBoxXYZ2);
             transaction.Commit();
         }
     }
     catch
     {
     }
 }
コード例 #8
0
 //set the bounding box for the sectionbox of 3D view
 public static bool SetBounds(BoundingBoxXYZ bounds, View3D view)
 {
     try
     {
         view.IsSectionBoxActive = true;
         view.SetSectionBox(bounds);
     }
     catch
     {
         return(false);
     }
     return(true);
 }
コード例 #9
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication  val   = commandData.get_Application();
            Document       val2  = val.get_ActiveUIDocument().get_Document();
            IList <View3D> views = new FilteredElementCollector(val2).WhereElementIsNotElementType().OfClass(typeof(View3D)).ToElements()
                                   .Cast <View3D>()
                                   .ToList();
            ViewsForZonesForm viewsForZonesForm = new ViewsForZonesForm(views, val2.get_ActiveView() as View3D);

            viewsForZonesForm.ShowDialog();
            if (viewsForZonesForm.DialogResult != DialogResult.OK)
            {
                return(1);
            }
            View3D selectedView = viewsForZonesForm.SelectedView;
            XYZ    val3         = new XYZ(0.0 - VIEW_CROP_OFFSETS[5], 0.0 - VIEW_CROP_OFFSETS[3], 0.0 - VIEW_CROP_OFFSETS[1]);
            XYZ    val4         = new XYZ(VIEW_CROP_OFFSETS[4], VIEW_CROP_OFFSETS[2], VIEW_CROP_OFFSETS[0]);
            IList <FamilyInstance> projectZones = ZoneData.GetProjectZones(val2);
            Transaction            val5         = new Transaction(val2, "Create Views for Project Zones");

            try
            {
                val5.Start();
                foreach (FamilyInstance item in projectZones)
                {
                    ElementId      val6 = selectedView.Duplicate(0);
                    View3D         val7 = val2.GetElement(val6) as View3D;
                    BoundingBoxXYZ val8 = item.get_BoundingBox(null);
                    BoundingBoxXYZ val9 = new BoundingBoxXYZ();
                    val9.set_Min(val8.get_Min() + val3);
                    val9.set_Max(val8.get_Max() + val4);
                    val7.set_Name("3D " + item.LookupParameter("Name").AsString());
                    val7.SetSectionBox(val9);
                }
                val5.Commit();
            }
            catch (OperationCanceledException)
            {
                return(1);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(-1);
            }
            return(0);
        }
コード例 #10
0
 //set the bounding box for the sectionbox of 3D view
 public void SetBounds()
 {
     try
     {
         using (Transaction tran = new Transaction(doc, "Manage View"))
         {
             tran.Start();
             view3D.IsSectionBoxActive = true;
             view3D.SetSectionBox(bounds);
             view3D.get_Parameter(BuiltInParameter.VIEW_DETAIL_LEVEL).Set(detail);
             tran.Commit();
         }
     }
     catch
     {
         throw new Exception();
     }
 }
コード例 #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bcfView"></param>
        private void PlaceSectionBox(View3D bcfView)
        {
            var selectedComponent = ViewModel.SelectedComponent;

            if (null == selectedComponent)
            {
                return;
            }

            using (var trans = new Transaction(ActiveDoc))
            {
                trans.Start("Set Section Box");
                try
                {
                    var element = selectedComponent.RvtElement;
                    if (null != element)
                    {
                        var transform   = selectedComponent.TransformValue;
                        var boundingBox = element.get_BoundingBox(null);
                        var minXYZ      = transform.OfPoint(boundingBox.Min);
                        var maxXYZ      = transform.OfPoint(boundingBox.Max);


                        var offsetBox = new BoundingBoxXYZ();
                        offsetBox.Min = new XYZ(minXYZ.X - 3, minXYZ.Y - 3, minXYZ.Z - 3);
                        offsetBox.Max = new XYZ(maxXYZ.X + 3, maxXYZ.Y + 3, maxXYZ.Z + 3);

                        bcfView.SetSectionBox(offsetBox);
                        bcfView.GetSectionBox().Enabled = true;

                        BCFUIView.ZoomAndCenterRectangle(offsetBox.Min, offsetBox.Max);
                        BCFUIView.Zoom(0.8);
                    }
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed to set sectionbox.\n" + ex.Message, "Set Section Box", MessageBoxButton.OK, MessageBoxImage.Warning);
                    trans.RollBack();
                }
            }
        }
コード例 #12
0
        private void ApplyClippingPlanes(UIDocument uiDocument, View3D view)
        {
            using var trans = new Transaction(uiDocument.Document);
            if (trans.Start($"Apply view point clipping planes in '{view.Name}'") != TransactionStatus.Started)
            {
                return;
            }

            Log.Information("Retrieving viewpoint clipping planes " +
                            "and converting them into an axis aligned bounding box ...");
            AxisAlignedBoundingBox boundingBox = GetViewpointClippingBox();

            if (!boundingBox.Equals(AxisAlignedBoundingBox.Infinite))
            {
                Log.Information("Found axis aligned clipping planes. Setting resulting section box ...");
                view.SetSectionBox(ToRevitSectionBox(boundingBox));
                view.IsSectionBoxActive = true;
            }

            trans.Commit();
        }
コード例 #13
0
        public void SetSectionBox(BoundingBoxXYZ box, bool cropOrNot)
        {
            using (Transaction trans = new Transaction(uiApp.ActiveUIDocument.Document))
            {
                trans.Start("Cropping View");

                if (uiApp.ActiveUIDocument.Document.ActiveView.ViewType != ViewType.ThreeD)
                {
                    uiApp.ActiveUIDocument.ActiveView.CropBoxActive = cropOrNot;
                    uiApp.ActiveUIDocument.ActiveView.CropBox       = box;
                }
                else
                {
                    View3D view3D = uiApp.ActiveUIDocument.ActiveView as View3D;

                    view3D.IsSectionBoxActive = cropOrNot;
                    view3D.SetSectionBox(box);
                }
                trans.Commit();
            }
        }
コード例 #14
0
ファイル: Basement.cs プロジェクト: pgrandin/revit
        public Result setup_sections()
        {
            // get a ViewFamilyType for a 3D View
            ViewFamilyType viewFamilyType = (from v in new FilteredElementCollector(doc).
                                             OfClass(typeof(ViewFamilyType)).
                                             Cast <ViewFamilyType>()
                                             where v.ViewFamily == ViewFamily.ThreeDimensional
                                             select v).First();

            using (Transaction t = new Transaction(doc, "Create view"))
            {
                t.Start();

                // Create the 3d view
                View3D view = View3D.CreateIsometric(doc, viewFamilyType.Id);

                // Set the name of the view
                view.Name = "Basement Section Box";

                // Set the name of the transaction
                // A transaction can be renamed after it has been started
                t.SetName("Create view " + view.Name);

                // Create a new BoundingBoxXYZ to define a 3D rectangular space
                BoundingBoxXYZ boundingBoxXYZ = new BoundingBoxXYZ();

                // Set the lower left bottom corner of the box
                // Use the Z of the current level.
                // X & Y values have been hardcoded based on this RVT geometry
                boundingBoxXYZ.Min = new XYZ(-2, 2, level.Elevation - 5);

                boundingBoxXYZ.Max = new XYZ(500 / 12, 500 / 12, 50);

                // Apply this bouding box to the view's section box
                view.SetSectionBox(boundingBoxXYZ);

                t.Commit();
            }
            return(Result.Succeeded);
        }
コード例 #15
0
        public View3D CreateView3D(int scale)
        {
            Document _doc = Level?.Document;

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

            View3D _view3D = View3D.CreateIsometric(_doc, _3DViewFamilyType.Id);

            _view3D.SetSectionBox(Bounds);
            string _viewName = GetViewName("3D");

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

            return(_view3D);
        }
コード例 #16
0
        public static void CreateBox(ClashItems elements)
        {
            View3D activeView = (View3D)RevitTools.Doc.ActiveView;


            BoundingBoxXYZ A    = elements.ElementA.get_BoundingBox(activeView);
            BoundingBoxXYZ B    = elements.ElementB.get_BoundingBox(activeView);
            var            XMax = Math.Max(A.Max.X, B.Max.X);
            var            YMax = Math.Max(A.Max.Y, B.Max.Y);
            var            ZMax = Math.Max(A.Max.Z, B.Max.Z);

            var XMin = Math.Min(A.Min.X, B.Min.X);
            var YMin = Math.Min(A.Min.Y, B.Min.Y);
            var ZMin = Math.Min(A.Min.Z, B.Min.Z);

            BoundingBoxXYZ bbx = new BoundingBoxXYZ()
            {
                Max = new XYZ(XMax, YMax, ZMax), Min = new XYZ(XMin, YMin, ZMin)
            };

            activeView.SetSectionBox(bbx);
        }
コード例 #17
0
        public static List <Revit.Elements.Element> ThreeDViewByRoom(List <Revit.Elements.Room> Rooms, List <String> Names, double Offset = 500)
        {
            var ThreeDViews = new List <Revit.Elements.Element>();
            var doc         = DocumentManager.Instance.CurrentDBDocument;
            var vtype       = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)).Cast <ViewFamilyType>().FirstOrDefault(a => a.ViewFamily == ViewFamily.ThreeDimensional);

            TransactionManager.Instance.EnsureInTransaction(doc);
            foreach (var elem in Rooms.Zip(Names, Tuple.Create))
            {
                BoundingBoxXYZ bbox       = elem.Item1.InternalElement.get_BoundingBox(doc.ActiveView);
                var            newbbox    = Utility.crop_box(bbox, Offset / 304.8);
                View3D         ThreeDView = View3D.CreateIsometric(doc, vtype.Id);
                ThreeDView.Name = elem.Item2;
                ThreeDView.SetSectionBox(newbbox);
                ThreeDView.CropBoxActive  = true;
                ThreeDView.CropBoxVisible = true;
                ThreeDView.Scale          = 50;
                ThreeDViews.Add(ThreeDView.ToDSType(true));
            }
            TransactionManager.Instance.TransactionTaskDone();

            return(ThreeDViews);
        }
コード例 #18
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = commandData.Application.ActiveUIDocument;
            Document      doc   = uidoc.Document;
            Selection     sel   = uidoc.Selection;

            View acView = doc.ActiveView;

            PickedBox pb = sel.PickBox(PickBoxStyle.Directional);

            XYZ min = pb.Min;
            XYZ max = pb.Max;

            double[] xnum = new[] { min.X, max.X };
            double[] ynum = new[] { min.Y, max.Y };

            Level lv1 = acView.GenLevel;
            Level lv2 = new FilteredElementCollector(doc).OfClass(typeof(Level)).Cast <Level>()
                        .Where(m => m.Name == "标高2").First();

            double z = double.NegativeInfinity;

            if (lv2 != null)
            {
                z = lv2.Elevation - lv1.Elevation;
            }
            else
            {
                z = 4000 / 304.8;
            }

            XYZ newMin = new XYZ(xnum.Min(), ynum.Min(), lv1.Elevation);

            XYZ newMax = new XYZ(xnum.Max(), ynum.Max(), z);

            Transform tsf = Transform.Identity;

            tsf.Origin = new XYZ();
            tsf.BasisX = XYZ.BasisX;
            tsf.BasisY = XYZ.BasisY;
            tsf.BasisZ = XYZ.BasisZ;

            BoundingBoxXYZ box = new BoundingBoxXYZ();

            box.Transform = tsf;
            box.Min       = newMin;
            box.Max       = newMax;



            Transaction ts = new Transaction(doc, "******");

            try
            {
                ts.Start();

                //创建三维视图
                View3D v3d = View3D.CreateIsometric(doc,
                                                    new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)).Cast <ViewFamilyType>()
                                                    .Where(m => m.ViewFamily == ViewFamily.ThreeDimensional).First().Id);

                v3d.SetSectionBox(box);

                ts.Commit();

                uidoc.ActiveView = v3d;
            }

            catch (Exception)
            {
                if (ts.GetStatus() == TransactionStatus.Started)
                {
                    ts.RollBack();
                }
            }

            return(Result.Succeeded);
        }
コード例 #19
0
        public void SetSectionBox(UIApplication app, int offset)
        {
            var     doc         = app.ActiveUIDocument.Document;
            Element currentView = app.ActiveUIDocument.ActiveView;
            View3D  view3D      = null;
            var     userName    = Environment.UserName;

            var list3D = new FilteredElementCollector(doc).OfClass(typeof(View3D)).ToList();

            if (currentView is View3D)
            {
                view3D = currentView as View3D;
            }
            else
            {
                if (list3D.Any())
                {
                    var my3D = list3D.Where(x => x.Name.ToUpper().Contains(userName.ToUpper())).ToList();
                    if (my3D.Count != 0)
                    {
                        view3D = my3D[0] as View3D;
                    }
                }
            }

            if (view3D == null)
            {
                using (var tr = new Transaction(doc, "Create 3D view"))
                {
                    tr.Start();
                    if (list3D.Any() && list3D[0].GetTypeId().IntegerValue == -1)
                    {
                        var threeD =
                            new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType))
                            .Cast <ViewFamilyType>()
                            .FirstOrDefault(x => x.ViewFamily == ViewFamily.ThreeDimensional);
                        view3D = View3D.CreateIsometric(doc, threeD?.Id);
                    }
                    else
                    {
                        if (list3D.Any())
                        {
                            view3D = View3D.CreateIsometric(doc, list3D[0].GetTypeId());
                        }
                        else
                        {
                            var threeD =
                                new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType))
                                .Cast <ViewFamilyType>()
                                .FirstOrDefault(x => x.ViewFamily == ViewFamily.ThreeDimensional);
                            view3D = View3D.CreateIsometric(doc, threeD?.Id);
                        }
                    }
#if R2017 || R2018
                    view3D.ViewName = "3D - " + userName;
#else
                    view3D.Name = "3D - " + userName;
#endif
                    tr.Commit();
                }
            }

            app.ActiveUIDocument.ActiveView = view3D;
            var elements = app.ActiveUIDocument.Selection.GetElementIds()
                           .Select(id => doc.GetElement(id)).Where(el => el.Category.Id.IntegerValue != (int)BuiltInCategory.OST_SectionBox).ToList();

            var points = GetBoundingBoxXYZ(elements, doc);
            var box    = new BoundingBoxXYZ();
            box.Max = new XYZ(points[0].X + offset, points[0].Y + offset, points[0].Z + offset);
            box.Min = new XYZ(points[1].X - offset, points[1].Y - offset, points[1].Z - offset);
            using (var tr = new Transaction(doc, "Create 3D section"))
            {
                tr.Start();
                try
                {
                    view3D.SetSectionBox(box);
                    if (ExternalCommands.ScrollerWin.IsSectionView)
                    {
                        app.ActiveUIDocument.ShowElements(app.ActiveUIDocument.Selection.GetElementIds());
                    }
                }
                catch
                {
                    // ignored
                }

                tr.Commit();
            }
        }
コード例 #20
0
ファイル: ThisApplication.cs プロジェクト: tsao100/AppHookup
        public void create3DViewsWithSectionBox()
        {
            UIDocument uidoc = ActiveUIDocument;
            Document   doc   = uidoc.Document;
            // get list of all levels
            IList <Level> levels = new FilteredElementCollector(doc).OfClass(typeof(Level)).Cast <Level>().OrderBy(l => l.Elevation).ToList();

            // get a ViewFamilyType for a 3D View
            ViewFamilyType viewFamilyType = (from v in new FilteredElementCollector(doc).
                                             OfClass(typeof(ViewFamilyType)).
                                             Cast <ViewFamilyType>()
                                             where v.ViewFamily == ViewFamily.ThreeDimensional
                                             select v).First();

            using (Transaction t = new Transaction(doc, "Create view"))
            {
                int ctr = 0;
                // loop through all levels
                foreach (Level level in levels)
                {
                    t.Start();

                    // Create the 3d view
                    View3D view = View3D.CreateIsometric(doc, viewFamilyType.Id);

                    // Set the name of the view
                    view.Name = level.Name + " Section Box";

                    // Set the name of the transaction
                    // A transaction can be renamed after it has been started
                    t.SetName("Create view " + view.Name);

                    // Create a new BoundingBoxXYZ to define a 3D rectangular space
                    BoundingBoxXYZ boundingBoxXYZ = new BoundingBoxXYZ();

                    // Set the lower left bottom corner of the box
                    // Use the Z of the current level.
                    // X & Y values have been hardcoded based on this RVT geometry
                    boundingBoxXYZ.Min = new XYZ(-50, -100, level.Elevation);

                    // Determine the height of the bounding box
                    double zOffset = 0;
                    // If there is another level above this one, use the elevation of that level
                    if (levels.Count > ctr + 1)
                    {
                        zOffset = levels.ElementAt(ctr + 1).Elevation;
                    }
                    // If this is the top level, use an offset of 10 feet
                    else
                    {
                        zOffset = level.Elevation + 10;
                    }
                    boundingBoxXYZ.Max = new XYZ(200, 125, zOffset);

                    // Apply this bouding box to the view's section box
                    //view.SectionBox = boundingBoxXYZ;
                    view.SetSectionBox(boundingBoxXYZ);

                    t.Commit();

                    // Open the just-created view
                    // There cannot be an open transaction when the active view is set
                    uidoc.ActiveView = view;

                    ctr++;
                }
            }
        }
コード例 #21
0
        private bool Create3DView()
        {
            bool result = false;

            try
            {
                BoundingBoxXYZ            boundingBox       = null;
                Dictionary <int, Element> elementDictionary = new Dictionary <int, Element>();
                foreach (ListViewItem item in listViewComponents.Items)
                {
                    if (null != item.Tag)
                    {
                        Element element = item.Tag as Element;
                        if (null != element.get_BoundingBox(null) && !elementDictionary.ContainsKey(element.Id.IntegerValue))
                        {
                            elementDictionary.Add(element.Id.IntegerValue, element);
                        }
                    }
                }

                boundingBox = elementDictionary[elementDictionary.Keys.First()].get_BoundingBox(null);

                double maxX = boundingBox.Max.X;
                double maxY = boundingBox.Max.Y;
                double maxZ = boundingBox.Max.Z;
                double minX = boundingBox.Min.X;
                double minY = boundingBox.Min.Y;
                double minZ = boundingBox.Min.Z;

                foreach (int eId in elementDictionary.Keys)
                {
                    Element element = elementDictionary[eId];
                    boundingBox = element.get_BoundingBox(null);
                    if (null != boundingBox)
                    {
                        if (boundingBox.Max.X > maxX)
                        {
                            maxX = boundingBox.Max.X;
                        }
                        if (boundingBox.Max.Y > maxY)
                        {
                            maxY = boundingBox.Max.Y;
                        }
                        if (boundingBox.Max.Z > maxZ)
                        {
                            maxZ = boundingBox.Max.Z;
                        }
                        if (boundingBox.Min.X < minX)
                        {
                            minX = boundingBox.Min.X;
                        }
                        if (boundingBox.Min.Y < minY)
                        {
                            minY = boundingBox.Min.Y;
                        }
                        if (boundingBox.Min.Z < minZ)
                        {
                            minZ = boundingBox.Min.Z;
                        }
                    }
                }

                XYZ xyzMax = new XYZ(maxX, maxY, maxZ);
                XYZ xyzMin = new XYZ(minX, minY, minZ);

                boundingBox.Max = xyzMax;
                boundingBox.Min = xyzMin;
                View3D view3d = null;
                using (Transaction trans = new Transaction(m_doc))
                {
                    trans.Start("Create a 3DView");
                    view3d = View3D.CreateIsometric(m_doc, view3dFamilyType.Id);
#if RELEASE2013
                    view3d.SectionBox = boundingBox;
#else
                    view3d.SetSectionBox(boundingBox);
                    view3d.GetSectionBox().Enabled = true;
#endif
                    view3d.Name = selectedView;

#if RELEASE2014 || RELEASE2015
                    SetElementTransparency(view3d, elementDictionary);
#endif
                    if (!view3dDictionary.ContainsKey(view3d.Name))
                    {
                        view3dDictionary.Add(view3d.Name, view3d);
                    }
                    trans.Commit();
                }
                if (null != view3d)
                {
                    m_app.ActiveUIDocument.ActiveView = view3d;
                }

                result = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create a 3DView named " + selectedView + "\n" + ex.Message, "CommandForm:Create3DView", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                result = false;
            }
            return(result);
        }
コード例 #22
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bcfView"></param>
        private void SetViewPointBoundingBox(View3D bcfView)
        {
            if (ViewModel.RvtComponents.Count == 0)
            {
                return;
            }

            var offsetBoundingBox = new BoundingBoxXYZ();

            using (var trans = new Transaction(ActiveDoc))
            {
                trans.Start("Set BoundingBox");
                try
                {
                    double minX      = 0;
                    double minY      = 0;
                    double minZ      = 0;
                    double maxX      = 0;
                    double maxY      = 0;
                    double maxZ      = 0;
                    var    firstLoop = true;

                    foreach (var rvtComp in ViewModel.RvtComponents)
                    {
                        var element = rvtComp.RvtElement;
                        if (null != element)
                        {
                            var bb = element.get_BoundingBox(null);
                            if (null != bb)
                            {
                                var transform = rvtComp.TransformValue;

                                var minXYZ = transform.OfPoint(bb.Min);
                                var maxXYZ = transform.OfPoint(bb.Max);

                                if (firstLoop)
                                {
                                    minX      = minXYZ.X;
                                    minY      = minXYZ.Y;
                                    minZ      = minXYZ.Z;
                                    maxX      = maxXYZ.X;
                                    maxY      = maxXYZ.Y;
                                    maxZ      = maxXYZ.Z;
                                    firstLoop = false;
                                }
                                else
                                {
                                    if (minX > minXYZ.X)
                                    {
                                        minX = minXYZ.X;
                                    }
                                    if (minY > minXYZ.Y)
                                    {
                                        minY = minXYZ.Y;
                                    }
                                    if (minZ > minXYZ.Z)
                                    {
                                        minZ = minXYZ.Z;
                                    }
                                    if (maxX < maxXYZ.X)
                                    {
                                        maxX = maxXYZ.X;
                                    }
                                    if (maxY < maxXYZ.Y)
                                    {
                                        maxY = maxXYZ.Y;
                                    }
                                    if (maxZ < maxXYZ.Z)
                                    {
                                        maxZ = maxXYZ.Z;
                                    }
                                }
                            }
                        }
                    }
                    offsetBoundingBox.Min = new XYZ(minX - 3, minY - 3, minZ - 3);
                    offsetBoundingBox.Max = new XYZ(maxX + 3, maxY + 3, maxZ + 3);

                    bcfView.SetSectionBox(offsetBoundingBox);
                    bcfView.GetSectionBox().Enabled = true;

                    BCFUIView.ZoomAndCenterRectangle(offsetBoundingBox.Min, offsetBoundingBox.Max);
                    BCFUIView.Zoom(0.8);

                    trans.Commit();
                }
                catch (Exception)
                {
                    trans.RollBack();
                }
            }
        }
コード例 #23
0
        public static View3D CreateWorkset3DView(Document doc, ItemInfo itemInfo, ViewFamilyType view3dFamilyType, bool overwrite)
        {
            View3D view3D = null;

            try
            {
                string viewName = "WS - 3D - " + itemInfo.ItemName;
                using (TransactionGroup tg = new TransactionGroup(doc))
                {
                    tg.Start("Create 3D View");
                    try
                    {
                        FilteredElementCollector collector = new FilteredElementCollector(doc);
                        List <View3D>            view3ds   = collector.OfClass(typeof(View3D)).ToElements().Cast <View3D>().ToList();
                        var views = from view in view3ds where view.Name == viewName select view;
                        if (views.Count() > 0)
                        {
                            if (overwrite)
                            {
                                view3D = views.First();
                            }
                            else
                            {
                                return(view3D);
                            }
                        }
                        if (null == view3D)
                        {
                            using (Transaction trans = new Transaction(doc))
                            {
                                trans.Start("Create Isometric");
                                try
                                {
                                    view3D      = View3D.CreateIsometric(doc, view3dFamilyType.Id);
                                    view3D.Name = viewName;
                                    if (view3D.CanModifyViewDiscipline())
                                    {
                                        view3D.Discipline = ViewDiscipline.Coordination;
                                    }
                                    trans.Commit();
                                }
                                catch (Exception ex)
                                {
                                    trans.RollBack();
                                    MessageBox.Show("Failed to create Isometric.\n" + ex.Message, "Create Isometric", 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)
                                        {
                                            view3D.SetWorksetVisibility(ws.Id, WorksetVisibility.Visible);
                                        }
                                        else
                                        {
                                            view3D.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);
                            }
                        }

                        using (Transaction trans = new Transaction(doc))
                        {
                            trans.Start("Set SectionBox");
                            try
                            {
                                collector = new FilteredElementCollector(doc, view3D.Id);
                                List <Element> elements = collector.ToElements().ToList();
                                if (elements.Count > 0)
                                {
                                    BoundingBoxXYZ boundingBox = GetBoundingBox(elements);
                                    if (null != boundingBox)
                                    {
                                        view3D.SetSectionBox(boundingBox);
                                    }
                                }
                                trans.Commit();
                            }
                            catch (Exception ex)
                            {
                                trans.RollBack();
                                MessageBox.Show("Failed to set sectionbox.\n" + ex.Message, "Set Sectionbox", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Failed to create 3d views by worksets.\n" + ex.Message, "Create 3D Views by Worksets", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        tg.RollBack();
                    }
                    tg.Assimilate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create workset views.\n" + ex.Message, "Create Workset 3D View", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(view3D);
        }
コード例 #24
0
        void Focus(UIApplication uiapp, Document doc, Element_Change item)
        {
            try
            {
                BoundingBoxXYZ boundingBoxXYZ = new BoundingBoxXYZ();
                ResetView(uiapp, doc);
                double a = 2;
                if (item.element != null && item.element_link != null)
                {
                    BoundingBoxXYZ boundingbox_1 = item.element.get_BoundingBox(null);
                    BoundingBoxXYZ boundingbox_2 = item.element_link.get_BoundingBox(null);

                    var x_1_min = boundingbox_1.Min.X;
                    var y_1_min = boundingbox_1.Min.Y;
                    var z_1_min = boundingbox_1.Min.Z;

                    var x_2_min = boundingbox_2.Min.X;
                    var y_2_min = boundingbox_2.Min.Y;
                    var z_2_min = boundingbox_2.Min.Z;

                    XYZ min = new XYZ(Math.Max(x_1_min, x_2_min) - a, Math.Max(y_1_min, y_2_min) - a, Math.Max(z_1_min, z_2_min) - a);

                    var x_1_max = boundingbox_1.Max.X;
                    var y_1_max = boundingbox_1.Max.Y;
                    var z_1_max = boundingbox_1.Max.Z;

                    var x_2_max = boundingbox_2.Max.X;
                    var y_2_max = boundingbox_2.Max.Y;
                    var z_2_max = boundingbox_2.Max.Z;

                    XYZ max = new XYZ(Math.Min(x_1_max, x_2_max) + a, Math.Min(y_1_max, y_2_max) + a, Math.Min(z_1_max, z_2_max) + a);

                    boundingBoxXYZ.Min = min;
                    boundingBoxXYZ.Max = max;
                }
                else if (item.element != null && item.element_link == null)
                {
                    BoundingBoxXYZ boundingbox_1 = item.element.get_BoundingBox(null);

                    XYZ min = new XYZ(boundingbox_1.Min.X - a, boundingbox_1.Min.Y - a, boundingbox_1.Min.Z - a);
                    XYZ max = new XYZ(boundingbox_1.Max.X + a, boundingbox_1.Max.Y + a, boundingbox_1.Max.Z + a);

                    boundingBoxXYZ.Min = min;
                    boundingBoxXYZ.Max = max;
                }
                else if (item.element == null && item.element_link != null)
                {
                    BoundingBoxXYZ boundingbox_1 = item.element_link.get_BoundingBox(null);

                    XYZ min = new XYZ(boundingbox_1.Min.X - a, boundingbox_1.Min.Y - a, boundingbox_1.Min.Z - a);
                    XYZ max = new XYZ(boundingbox_1.Max.X + a, boundingbox_1.Max.Y + a, boundingbox_1.Max.Z + a);

                    boundingBoxXYZ.Min = min;
                    boundingBoxXYZ.Max = max;
                }

                View3D view = doc.ActiveView as View3D;
                view.SetSectionBox(boundingBoxXYZ);

                var UIView = uiapp.ActiveUIDocument.GetOpenUIViews();
                foreach (var view1 in UIView)
                {
                    if (view1.ViewId == view.Id)
                    {
                        view1.ZoomAndCenterRectangle(boundingBoxXYZ.Min, boundingBoxXYZ.Max);
                    }
                }

                Selection select = uiapp.ActiveUIDocument.Selection;
                if (item.element != null)
                {
                    select.SetElementIds(new List <ElementId>()
                    {
                        item.element.Id
                    });
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #25
0
        public static View3D CreateLink3DView(Document doc, ItemInfo itemInfo, ViewFamilyType view3dFamilyType, bool overwrite)
        {
            View3D view3D = null;

            try
            {
                string viewName = "LINKRVT - 3D - " + itemInfo.ItemName;
                using (TransactionGroup tg = new TransactionGroup(doc))
                {
                    tg.Start("Create 3D View");
                    try
                    {
                        FilteredElementCollector collector = new FilteredElementCollector(doc);
                        List <View3D>            view3ds   = collector.OfClass(typeof(View3D)).ToElements().Cast <View3D>().ToList();
                        var views = from view in view3ds where view.Name == viewName select view;
                        if (views.Count() > 0)
                        {
                            if (overwrite)
                            {
                                view3D = views.First();
                            }
                            else
                            {
                                return(view3D);
                            }
                        }
                        if (null == view3D)
                        {
                            using (Transaction trans = new Transaction(doc))
                            {
                                trans.Start("Create Isometric");
                                try
                                {
                                    view3D      = View3D.CreateIsometric(doc, view3dFamilyType.Id);
                                    view3D.Name = viewName;
                                    if (view3D.CanModifyViewDiscipline())
                                    {
                                        view3D.Discipline = ViewDiscipline.Coordination;
                                    }
                                    trans.Commit();
                                }
                                catch (Exception ex)
                                {
                                    trans.RollBack();
                                    MessageBox.Show("Failed to create Isometric.\n" + ex.Message, "Create Isometric", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                }
                            }
                        }


                        using (Transaction trans = new Transaction(doc))
                        {
                            trans.Start("Set SectionBox");
                            try
                            {
                                collector = new FilteredElementCollector(doc);
                                List <Element> linkInstances = collector.OfCategory(BuiltInCategory.OST_RvtLinks).WhereElementIsNotElementType().ToElements().ToList();
                                var            selectedLinks = from link in linkInstances where link.Name.Contains(itemInfo.ItemName) && null != link.Location select link;
                                if (selectedLinks.Count() > 0)
                                {
                                    BoundingBoxXYZ boundingBox = GetBoundingBox(selectedLinks.ToList());
                                    if (null != boundingBox)
                                    {
                                        view3D.SetSectionBox(boundingBox);
                                    }
                                }
                                trans.Commit();
                            }
                            catch (Exception ex)
                            {
                                trans.RollBack();
                                MessageBox.Show("Failed to set sectionbox.\n" + ex.Message, "Set Sectionbox", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Failed to create 3d views by worksets.\n" + ex.Message, "Create 3D Views by Worksets", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        tg.RollBack();
                    }
                    tg.Assimilate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create workset views.\n" + ex.Message, "Create Workset 3D View", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(view3D);
        }
コード例 #26
0
ファイル: ExtOpenView.cs プロジェクト: tinydot/issue-tracker
        /// <summary>
        /// External Event Implementation
        /// </summary>
        /// <param name="app"></param>
        public void Execute(UIApplication app)
        {
            try
            {
                UIDocument uidoc = app.ActiveUIDocument;
                Document   doc   = uidoc.Document;
                //Selection m_elementsToHide = uidoc.Selection; //SelElementSet.Create();

                BlockingCollection <ElementId> elementsToBeIsolated = new BlockingCollection <ElementId>();
                BlockingCollection <ElementId> elementsToBeHidden   = new BlockingCollection <ElementId>();
                BlockingCollection <ElementId> elementsToBeSelected = new BlockingCollection <ElementId>();

                // IS ORTHOGONAL
                if (v.OrthogonalCamera != null)
                {
                    if (v.OrthogonalCamera.ViewToWorldScale == null || v.OrthogonalCamera.CameraViewPoint == null || v.OrthogonalCamera.CameraUpVector == null || v.OrthogonalCamera.CameraDirection == null)
                    {
                        return;
                    }
                    //type = "OrthogonalCamera";
                    var zoom            = UnitUtils.ConvertToInternalUnits(v.OrthogonalCamera.ViewToWorldScale, DisplayUnitType.DUT_METERS);
                    var CameraDirection = ARUP.IssueTracker.Revit.Classes.Utils.GetInternalXYZ(v.OrthogonalCamera.CameraDirection.X, v.OrthogonalCamera.CameraDirection.Y, v.OrthogonalCamera.CameraDirection.Z);
                    var CameraUpVector  = ARUP.IssueTracker.Revit.Classes.Utils.GetInternalXYZ(v.OrthogonalCamera.CameraUpVector.X, v.OrthogonalCamera.CameraUpVector.Y, v.OrthogonalCamera.CameraUpVector.Z);
                    var CameraViewPoint = ARUP.IssueTracker.Revit.Classes.Utils.GetInternalXYZ(v.OrthogonalCamera.CameraViewPoint.X, v.OrthogonalCamera.CameraViewPoint.Y, v.OrthogonalCamera.CameraViewPoint.Z);
                    var orient3d        = ARUP.IssueTracker.Revit.Classes.Utils.ConvertBasePoint(doc, CameraViewPoint, CameraDirection, CameraUpVector, true);


                    View3D orthoView = null;
                    //if active view is 3d ortho use it
                    if (doc.ActiveView.ViewType == ViewType.ThreeD)
                    {
                        View3D ActiveView3D = doc.ActiveView as View3D;
                        if (!ActiveView3D.IsPerspective)
                        {
                            orthoView = ActiveView3D;
                        }
                    }
                    string userDefault3dViewName = "{3D - " + app.Application.Username + "}";
                    string default3dViewName     = "{3D}";
                    string userBCForthoViewName  = string.Format("BCFortho_{0}", app.Application.Username);
                    if (orthoView == null)
                    {
                        IEnumerable <View3D> viewcollector3D = get3DViews(doc);
                        //find a orthographic 3D view
                        if (viewcollector3D.Any())
                        {
                            if (viewcollector3D.Where(o => o.Name == userDefault3dViewName).Any()) // 1) try to find user specific 3D view in workshared environment
                            {
                                orthoView = viewcollector3D.Where(o => o.Name == userDefault3dViewName).First();
                            }
                            else if (viewcollector3D.Where(o => o.Name == default3dViewName).Any()) // 2) try to find the default 3D view if 1) not found
                            {
                                orthoView = viewcollector3D.Where(o => o.Name == default3dViewName).First();
                            }
                            else if (viewcollector3D.Where(o => o.Name == userBCForthoViewName).Any()) // 3) try to find BCFortho 3D view generated by AIT previously if 2) is not found
                            {
                                orthoView = viewcollector3D.Where(o => o.Name == userBCForthoViewName).First();
                            }
                        }
                    }
                    using (Transaction trans = new Transaction(uidoc.Document))
                    {
                        if (trans.Start("Open orthogonal view") == TransactionStatus.Started)
                        {
                            //create a new user-specific 3d ortho view
                            if (orthoView == null)
                            {
                                orthoView      = View3D.CreateIsometric(doc, getFamilyViews(doc).First().Id);
                                orthoView.Name = userBCForthoViewName;
                            }

                            orthoView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate);
                            orthoView.SetOrientation(orient3d);
                            trans.Commit();
                        }
                    }
                    uidoc.ActiveView = orthoView;
                    //adjust view rectangle

                    // **** CUSTOM VALUE FOR TEKLA **** //
                    // double x = touple.Item2
                    // **** CUSTOM VALUE FOR TEKLA **** //
                    double customZoomValue = (MyProjectSettings.Get("useDefaultZoom", doc.PathName) == "1") ? 1 : 2.5;
                    double x       = zoom / customZoomValue;
                    XYZ    m_xyzTl = uidoc.ActiveView.Origin.Add(uidoc.ActiveView.UpDirection.Multiply(x)).Subtract(uidoc.ActiveView.RightDirection.Multiply(x));
                    XYZ    m_xyzBr = uidoc.ActiveView.Origin.Subtract(uidoc.ActiveView.UpDirection.Multiply(x)).Add(uidoc.ActiveView.RightDirection.Multiply(x));
                    uidoc.GetOpenUIViews().First().ZoomAndCenterRectangle(m_xyzTl, m_xyzBr);
                }

                else if (v.PerspectiveCamera != null)
                {
                    if (v.PerspectiveCamera.FieldOfView == null || v.PerspectiveCamera.CameraViewPoint == null || v.PerspectiveCamera.CameraUpVector == null || v.PerspectiveCamera.CameraDirection == null)
                    {
                        return;
                    }

                    var    zoom   = v.PerspectiveCamera.FieldOfView;
                    double z1     = 18 / Math.Tan(zoom / 2 * Math.PI / 180); //focale 1
                    double z      = 18 / Math.Tan(25 / 2 * Math.PI / 180);   //focale, da controllare il 18, vedi PDF
                    double factor = z1 - z;

                    var CameraDirection = ARUP.IssueTracker.Revit.Classes.Utils.GetInternalXYZ(v.PerspectiveCamera.CameraDirection.X, v.PerspectiveCamera.CameraDirection.Y, v.PerspectiveCamera.CameraDirection.Z);
                    var CameraUpVector  = ARUP.IssueTracker.Revit.Classes.Utils.GetInternalXYZ(v.PerspectiveCamera.CameraUpVector.X, v.PerspectiveCamera.CameraUpVector.Y, v.PerspectiveCamera.CameraUpVector.Z);
                    XYZ oldO            = ARUP.IssueTracker.Revit.Classes.Utils.GetInternalXYZ(v.PerspectiveCamera.CameraViewPoint.X, v.PerspectiveCamera.CameraViewPoint.Y, v.PerspectiveCamera.CameraViewPoint.Z);
                    var CameraViewPoint = (oldO.Subtract(CameraDirection.Divide(factor)));
                    var orient3d        = ARUP.IssueTracker.Revit.Classes.Utils.ConvertBasePoint(doc, CameraViewPoint, CameraDirection, CameraUpVector, true);

                    View3D perspView = null;

                    IEnumerable <View3D> viewcollector3D = get3DViews(doc);
                    string userPersp3dViewName           = string.Format("BCFperps_{0}", app.Application.Username);
                    // find a perspective view
                    if (viewcollector3D.Any() && viewcollector3D.Where(o => o.Name == userPersp3dViewName).Any())
                    {
                        perspView = viewcollector3D.Where(o => o.Name == userPersp3dViewName).First();
                    }
                    using (Transaction trans = new Transaction(uidoc.Document))
                    {
                        if (trans.Start("Open perspective view") == TransactionStatus.Started)
                        {
                            if (null == perspView)
                            {
                                perspView      = View3D.CreatePerspective(doc, getFamilyViews(doc).First().Id);
                                perspView.Name = userPersp3dViewName;
                            }

                            perspView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate);
                            perspView.SetOrientation(orient3d);

                            // turn on the far clip plane with standard parameter API
                            if (perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR).HasValue)
                            {
                                Parameter m_farClip = perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR);
                                m_farClip.Set(1);
                            }
                            // reset far clip offset
                            if (perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR).HasValue)
                            {
                                Parameter m_farClipOffset = perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR);
                                m_farClipOffset.SetValueString("35");
                            }
                            // turn off the far clip plane with standard parameter API
                            if (perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR).HasValue)
                            {
                                Parameter m_farClip = perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR);
                                m_farClip.Set(0);
                            }
                            perspView.CropBoxActive  = true;
                            perspView.CropBoxVisible = true;

                            trans.Commit();
                        }
                    }
                    uidoc.ActiveView = perspView;
                }
                else if (v.SheetCamera != null)//sheet
                {
                    //using (Transaction trans = new Transaction(uidoc.Document))
                    //{
                    //    if (trans.Start("Open sheet view") == TransactionStatus.Started)
                    //    {
                    IEnumerable <View> viewcollectorSheet = getSheets(doc, v.SheetCamera.SheetID);
                    if (!viewcollectorSheet.Any())
                    {
                        MessageBox.Show("No Sheet with Id=" + v.SheetCamera.SheetID + " found.");
                        return;
                    }
                    uidoc.ActiveView = viewcollectorSheet.First();
                    uidoc.ActiveView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate);
                    uidoc.RefreshActiveView();

                    //        trans.Commit();
                    //    }
                    //}
                    XYZ m_xyzTl = new XYZ(v.SheetCamera.TopLeft.X, v.SheetCamera.TopLeft.Y,
                                          v.SheetCamera.TopLeft.Z);
                    XYZ m_xyzBr = new XYZ(v.SheetCamera.BottomRight.X, v.SheetCamera.BottomRight.Y,
                                          v.SheetCamera.BottomRight.Z);
                    uidoc.GetOpenUIViews().First().ZoomAndCenterRectangle(m_xyzTl, m_xyzBr);
                }
                else
                {
                    return;
                }

                //apply BCF clipping planes to Revit section box
                View3D view3D = doc.ActiveView as View3D;
                if (view3D != null)
                {
                    // resume section box state
                    using (Transaction trans = new Transaction(uidoc.Document))
                    {
                        if (trans.Start("Resume Section Box") == TransactionStatus.Started)
                        {
                            view3D.IsSectionBoxActive = false;
                        }
                        trans.Commit();
                    }

                    if (v.ClippingPlanes != null)
                    {
                        if (v.ClippingPlanes.Count() > 0)
                        {
                            var result = getBoundingBoxFromClippingPlanes(doc, v.ClippingPlanes);

                            if (result != null)
                            {
                                BoundingBoxXYZ computedBox = result.Item1;
                                Transform      rotate      = result.Item2;

                                using (Transaction trans = new Transaction(uidoc.Document))
                                {
                                    if (trans.Start("Apply Section Box") == TransactionStatus.Started)
                                    {
                                        view3D.IsSectionBoxActive = true;
                                        view3D.SetSectionBox(computedBox);

                                        if (rotate != null)
                                        {
                                            // Transform the View3D's section box with the rotation transform
                                            computedBox.Transform = computedBox.Transform.Multiply(rotate);

                                            // Set the section box back to the view (requires an open transaction)
                                            view3D.SetSectionBox(computedBox);
                                        }
                                    }
                                    trans.Commit();
                                }
                            }
                        }
                    }
                }

                // resume visibility and selection
                using (Transaction trans = new Transaction(uidoc.Document))
                {
                    if (trans.Start("Resume Visibility/Selection") == TransactionStatus.Started)
                    {
#if REVIT2014
                        uidoc.ActiveView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate);
                        uidoc.Selection.Elements.Clear();
#elif REVIT2015
                        uidoc.ActiveView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate);
                        uidoc.Selection.SetElementIds(new List <ElementId>());
#else
                        uidoc.ActiveView.TemporaryViewModes.DeactivateAllModes();
                        uidoc.Selection.SetElementIds(new List <ElementId>());
#endif
                    }
                    trans.Commit();
                }

                //select/hide elements
                if (v.Components != null && v.Components.Any())
                {
                    //if (v.Components.Count > 100)
                    //{
                    //    var result = MessageBox.Show("Too many elements attached. It may take for a while to isolate/select them. Do you want to continue?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                    //    if (result == MessageBoxResult.No)
                    //    {
                    //        uidoc.RefreshActiveView();
                    //        return;
                    //    }
                    //}

                    revitWindow.initializeProgressWin(v.Components.Count);

                    FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id);
                    var allElementIds = collector.ToElementIds();
                    Dictionary <Guid, ElementId> exportIdElementIdDic = new Dictionary <Guid, ElementId>();
                    Dictionary <int, ElementId>  uniqueIdElementIdDic = new Dictionary <int, ElementId>();
                    foreach (ElementId eId in allElementIds)
                    {
                        Guid guid             = ExportUtils.GetExportId(doc, eId);
                        int  elementIdInteger = Convert.ToInt32(doc.GetElement(eId).UniqueId.Substring(37), 16);
                        if (!exportIdElementIdDic.ContainsKey(guid))
                        {
                            exportIdElementIdDic.Add(guid, eId);
                        }
                        if (!uniqueIdElementIdDic.ContainsKey(elementIdInteger))
                        {
                            uniqueIdElementIdDic.Add(elementIdInteger, eId);
                        }
                    }
                    //System.Threading.Tasks.Parallel.For(0, v.Components.Count, i => {
                    for (int i = 0; i < v.Components.Count; i++)
                    {
                        double percentage = ((double)i / (double)v.Components.Count) * 100;
                        revitWindow.updateProgressWin((int)percentage, i, v.Components.Count);

                        ARUP.IssueTracker.Classes.BCF2.Component e = v.Components[i];
                        ElementId currentElementId = null;

                        // find by ElementId first if OriginatingSystem is Revit
                        if (e.OriginatingSystem != null)
                        {
                            if (e.OriginatingSystem.Contains("Revit") && !string.IsNullOrEmpty(e.AuthoringToolId))
                            {
                                int elementId = -1;
                                int.TryParse(e.AuthoringToolId, out elementId);
                                if (elementId != -1)
                                {
                                    Element ele = doc.GetElement(new ElementId(elementId));
                                    if (ele != null)
                                    {
                                        currentElementId = ele.Id;
                                    }
                                }
                            }
                        }

                        // find by IfcGuid if ElementId not found
                        if (currentElementId == null)
                        {
                            var bcfguid = IfcGuid.FromIfcGUID(e.IfcGuid);
                            if (exportIdElementIdDic.ContainsKey(bcfguid))
                            {
                                currentElementId = exportIdElementIdDic[bcfguid];
                            }
                        }

                        // find by UniqueId if IfcGuid not found
                        if (currentElementId == null)
                        {
                            int authoringToolId = -1;
                            int.TryParse(e.AuthoringToolId, out authoringToolId);
                            if (uniqueIdElementIdDic.ContainsKey(authoringToolId))
                            {
                                currentElementId = uniqueIdElementIdDic[authoringToolId];
                            }
                        }

                        if (currentElementId != null)
                        {
                            // handle visibility
                            if (e.Visible)
                            {
                                elementsToBeIsolated.Add(currentElementId);
                            }
                            else
                            {
                                elementsToBeHidden.Add(currentElementId);
                            }

                            // handle selection
                            if (e.Selected)
                            {
                                elementsToBeSelected.Add(currentElementId);
                            }
                        }
                    }
                    ;

                    if (elementsToBeHidden.Count > 0)
                    {
                        using (Transaction trans = new Transaction(uidoc.Document))
                        {
                            if (trans.Start("Hide Elements") == TransactionStatus.Started)
                            {
                                uidoc.ActiveView.HideElementsTemporary(elementsToBeHidden.ToList());
                            }
                            trans.Commit();
                        }
                    }
                    else if (elementsToBeIsolated.Count > 0)
                    {
                        using (Transaction trans = new Transaction(uidoc.Document))
                        {
                            if (trans.Start("Isolate Elements") == TransactionStatus.Started)
                            {
                                uidoc.ActiveView.IsolateElementsTemporary(elementsToBeIsolated.ToList());
                            }
                            trans.Commit();
                        }
                    }

                    if (elementsToBeSelected.Count > 0)
                    {
                        using (Transaction trans = new Transaction(uidoc.Document))
                        {
                            if (trans.Start("Select Elements") == TransactionStatus.Started)
                            {
#if REVIT2014
                                SelElementSet selectedElements = SelElementSet.Create();
                                elementsToBeSelected.ToList().ForEach(id =>
                                {
                                    selectedElements.Add(doc.GetElement(id));
                                });

                                uidoc.Selection.Elements = selectedElements;
#else
                                uidoc.Selection.SetElementIds(elementsToBeSelected.ToList());
#endif
                            }
                            trans.Commit();
                        }
                    }

                    revitWindow.disposeProgressWin();
                }

                uidoc.RefreshActiveView();
            }
            catch (Exception ex)
            {
                TaskDialog.Show("Error!", "exception: " + ex);
            }
        }
コード例 #27
0
        private View Create3DViewFromArea()
        {
            View           currentView = CurrentDocument.ActiveView;
            View3D         finalView   = null;
            PickedBox      area        = null;
            BoundingBoxXYZ viewBox     = null;

            // Check that the user is in a plan (for now, allow changes to use Section space later)
            if (currentView.ViewType != ViewType.CeilingPlan && currentView.ViewType != ViewType.FloorPlan)
            {
                TaskDialog.Show("Error", "This command can only be used in plan view at the moment");
                throw new CancellableException();
            }

            //// Prompt the user to select a bounding box
            //using (Selection userBox = UiDocument.Selection)
            //{
            //    area = userBox.PickBox(PickBoxStyle.Crossing, "Please draw the area you'd like to see in 3D");
            //}

            // Create a new 3D Area from this bound box as well as the Plan's section box
            var view3Ds = new FilteredElementCollector(CurrentDocument).OfClass(typeof(ViewFamilyType));

            var view3DId = view3Ds
                           .Cast <ViewFamilyType>()
                           .FirstOrDefault(v => v.ViewFamily == ViewFamily.ThreeDimensional).Id;

            using (var sub = new Transaction(CurrentDocument, "Creating 3D view"))
            {
                if (!sub.HasStarted())
                {
                    sub.Start();
                }

                // Create new 3D View
                finalView = View3D.CreateIsometric(CurrentDocument, view3DId);
                finalView.IsSectionBoxActive = true;

                try
                {
                    var box = new BoundingBoxXYZ
                    {
                        Enabled = true,
                        Min     = new XYZ(-100.0, -100.0, -100.0),
                        Max     = new XYZ(100.0, 100.0, 100.0)
                    };

                    finalView.SetSectionBox(box);
                }

                catch (ArgumentException args)
                {
                    Console.WriteLine($"Something happened: \n{args}");
                    sub.RollBack();
                    throw new CancellableException();
                }

                sub.Commit();
            }

            // change to the newly created view
            //UiDocument.RequestViewChange(finalView);

            return(finalView);
        }
コード例 #28
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            IEnumerable <ElementId> selElSet = uidoc.Selection.GetElementIds();
            IList <double>          XX = new List <double>(), YY = new List <double>(), ZZ = new List <double>();

            XX.Clear(); YY.Clear(); ZZ.Clear();
            if (selElSet.Count().Equals(0))
            {
                return(Result.Failed);
            }
            foreach (ElementId elll in selElSet)
            {
                double n = doc.GetElement(elll).get_BoundingBox(doc.ActiveView).Min.X;
                XX.Add(n);
                n = doc.GetElement(elll).get_BoundingBox(doc.ActiveView).Max.X;
                XX.Add(n);

                n = doc.GetElement(elll).get_BoundingBox(doc.ActiveView).Min.Y;
                YY.Add(n);
                n = doc.GetElement(elll).get_BoundingBox(doc.ActiveView).Max.Y;
                YY.Add(n);

                n = doc.GetElement(elll).get_BoundingBox(doc.ActiveView).Min.Z;
                ZZ.Add(n);
                n = doc.GetElement(elll).get_BoundingBox(doc.ActiveView).Max.Z;
                ZZ.Add(n);
            }

            FilteredElementCollector lvlcol = new FilteredElementCollector(doc).
                                              OfCategory(BuiltInCategory.OST_Levels).WhereElementIsNotElementType();
            double minElevation = 0, maxElevation = 0;

            foreach (Level lvl in lvlcol)
            {
                if (lvl.Elevation > maxElevation)
                {
                    maxElevation = lvl.Elevation;
                }
                if (lvl.Elevation < minElevation)
                {
                    minElevation = lvl.Elevation;
                }
            }


            XYZ min = new XYZ(XX.Min(), YY.Min(), minElevation - 5);
            XYZ max = new XYZ(XX.Max(), YY.Max(), maxElevation + 5);

            if (max.Subtract(min).GetLength() < 5)
            {
                min.Add(min.Multiply(1.5));
                max.Add(max.Multiply(1.5));
            }

            Transform t = Transform.Identity;

            t.BasisX = XYZ.BasisX;
            t.BasisY = XYZ.BasisY;
            t.BasisZ = XYZ.BasisZ;

            BoundingBoxXYZ sectionBox = new BoundingBoxXYZ();

            sectionBox.Transform = t;
            sectionBox.Min       = min;
            sectionBox.Max       = max;



            ViewFamilyType vft
                = new FilteredElementCollector(doc)
                  .OfClass(typeof(ViewFamilyType))
                  .Cast <ViewFamilyType>()
                  .FirstOrDefault <ViewFamilyType>(x =>
                                                   ViewFamily.Section == x.ViewFamily);

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Create Section View");

                View Myview = ViewSection.CreateSection(doc, vft.Id, sectionBox);
                #region Test/////////////////3D

                ViewFamilyType vft3d
                    = new FilteredElementCollector(doc)
                      .OfClass(typeof(ViewFamilyType))
                      .Cast <ViewFamilyType>()
                      .FirstOrDefault <ViewFamilyType>(x =>
                                                       ViewFamily.ThreeDimensional == x.ViewFamily);

                View3D view3dEX = View3D.CreateIsometric(doc, vft3d.Id);

                view3dEX.SetSectionBox(sectionBox);
                #endregion


                tx.Commit();
                uidoc.ActiveView = view3dEX;
            }
            return(Result.Succeeded);
        }
コード例 #29
0
ファイル: E_Focus.cs プロジェクト: karthi1015/RevitTool
        //----------------------------------------------------------
        void SectionBox(UIApplication uiapp, Document doc, child item)
        {
            try
            {
                ResetView(uiapp, doc);
                var       document1 = item.doc1_child;
                var       document2 = item.doc2_child;
                ElementId ele1      = new ElementId(Convert.ToInt32(item.id1_child));
                ElementId ele2      = new ElementId(Convert.ToInt32(item.id2_child));


                BoundingBoxXYZ boundingbox_1 = document1.GetElement(ele1).get_BoundingBox(null);
                BoundingBoxXYZ boundingbox_2 = document2.GetElement(ele2).get_BoundingBox(null);
                double         a             = 10;
                if (boundingbox_1 != null && boundingbox_2 != null)
                {
                    var x_1_min = boundingbox_1.Min.X;
                    var y_1_min = boundingbox_1.Min.Y;
                    var z_1_min = boundingbox_1.Min.Z;

                    var x_2_min = boundingbox_2.Min.X;
                    var y_2_min = boundingbox_2.Min.Y;
                    var z_2_min = boundingbox_2.Min.Z;

                    XYZ min = new XYZ(Math.Max(x_1_min, x_2_min) - a, Math.Max(y_1_min, y_2_min) - a, Math.Max(z_1_min, z_2_min) - a);

                    var x_1_max = boundingbox_1.Max.X;
                    var y_1_max = boundingbox_1.Max.Y;
                    var z_1_max = boundingbox_1.Max.Z;

                    var x_2_max = boundingbox_2.Max.X;
                    var y_2_max = boundingbox_2.Max.Y;
                    var z_2_max = boundingbox_2.Max.Z;

                    XYZ max = new XYZ(Math.Min(x_1_max, x_2_max) + a, Math.Min(y_1_max, y_2_max) + a, Math.Min(z_1_max, z_2_max) + a);

                    BoundingBoxXYZ boundingBoxXYZ = new BoundingBoxXYZ();
                    boundingBoxXYZ.Min = min;
                    boundingBoxXYZ.Max = max;

                    View3D view = doc.ActiveView as View3D;
                    view.SetSectionBox(boundingBoxXYZ);

                    var UIView = uiapp.ActiveUIDocument.GetOpenUIViews();
                    foreach (var view1 in UIView)
                    {
                        if (view1.ViewId == view.Id)
                        {
                            view1.ZoomAndCenterRectangle(min, max);
                        }
                    }

                    Selection select = uiapp.ActiveUIDocument.Selection;
                    if (doc.Title == document1.Title)
                    {
                        select.SetElementIds(new List <ElementId>()
                        {
                            ele1
                        });
                    }
                    else if (doc.Title == document2.Title)
                    {
                        select.SetElementIds(new List <ElementId>()
                        {
                            ele2
                        });
                    }
                }
            }
            catch (Exception)
            {
            }
        }
コード例 #30
0
        /// <summary>
        /// External Event Implementation
        /// </summary>
        /// <param name="app"></param>
        public void Execute(UIApplication app)
        {
            try
            {
                UIDocument    uidoc            = app.ActiveUIDocument;
                Document      doc              = uidoc.Document;
                SelElementSet m_elementsToHide = SelElementSet.Create();

                List <ElementId> elementsToBeIsolated = new List <ElementId>();
                List <ElementId> elementsToBeHidden   = new List <ElementId>();
                List <ElementId> elementsToBeSelected = new List <ElementId>();


                // IS ORTHOGONAL
                if (v.OrthogonalCamera != null)
                {
                    if (v.OrthogonalCamera.ViewToWorldScale == null || v.OrthogonalCamera.CameraViewPoint == null || v.OrthogonalCamera.CameraUpVector == null || v.OrthogonalCamera.CameraDirection == null)
                    {
                        return;
                    }
                    //type = "OrthogonalCamera";
                    var zoom            = UnitUtils.ConvertToInternalUnits(v.OrthogonalCamera.ViewToWorldScale, DisplayUnitType.DUT_METERS);
                    var CameraDirection = ARUP.IssueTracker.Revit.Classes.Utils.GetXYZ(v.OrthogonalCamera.CameraDirection.X, v.OrthogonalCamera.CameraDirection.Y, v.OrthogonalCamera.CameraDirection.Z);
                    var CameraUpVector  = ARUP.IssueTracker.Revit.Classes.Utils.GetXYZ(v.OrthogonalCamera.CameraUpVector.X, v.OrthogonalCamera.CameraUpVector.Y, v.OrthogonalCamera.CameraUpVector.Z);
                    var CameraViewPoint = ARUP.IssueTracker.Revit.Classes.Utils.GetXYZ(v.OrthogonalCamera.CameraViewPoint.X, v.OrthogonalCamera.CameraViewPoint.Y, v.OrthogonalCamera.CameraViewPoint.Z);
                    var orient3d        = ARUP.IssueTracker.Revit.Classes.Utils.ConvertBasePoint(doc, CameraViewPoint, CameraDirection, CameraUpVector, true);


                    View3D orthoView = null;
                    //if active view is 3d ortho use it
                    if (doc.ActiveView.ViewType == ViewType.ThreeD)
                    {
                        View3D ActiveView3D = doc.ActiveView as View3D;
                        if (!ActiveView3D.IsPerspective)
                        {
                            orthoView = ActiveView3D;
                        }
                    }
                    if (orthoView == null)
                    {
                        IEnumerable <View3D> viewcollector3D = get3DViews(doc);
                        //try to use default 3D view
                        if (viewcollector3D.Any() && viewcollector3D.Where(o => o.Name == "{3D}" || o.Name == "BCFortho").Any())
                        {
                            orthoView = viewcollector3D.Where(o => o.Name == "{3D}" || o.Name == "BCFortho").First();
                        }
                    }
                    using (Transaction trans = new Transaction(uidoc.Document))
                    {
                        if (trans.Start("Open orthogonal view") == TransactionStatus.Started)
                        {
                            //create a new 3d ortho view
                            if (orthoView == null)
                            {
                                orthoView      = View3D.CreateIsometric(doc, getFamilyViews(doc).First().Id);
                                orthoView.Name = "BCFortho";
                            }

                            orthoView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate);
                            orthoView.SetOrientation(orient3d);
                            trans.Commit();
                        }
                    }
                    uidoc.ActiveView = orthoView;
                    //adjust view rectangle

                    // **** CUSTOM VALUE FOR TEKLA **** //
                    // double x = touple.Item2
                    // **** CUSTOM VALUE FOR TEKLA **** //
                    double customZoomValue = (MyProjectSettings.Get("useDefaultZoom", doc.PathName) == "1") ? 1 : 2.5;
                    double x       = zoom / customZoomValue;
                    XYZ    m_xyzTl = uidoc.ActiveView.Origin.Add(uidoc.ActiveView.UpDirection.Multiply(x)).Subtract(uidoc.ActiveView.RightDirection.Multiply(x));
                    XYZ    m_xyzBr = uidoc.ActiveView.Origin.Subtract(uidoc.ActiveView.UpDirection.Multiply(x)).Add(uidoc.ActiveView.RightDirection.Multiply(x));
                    uidoc.GetOpenUIViews().First().ZoomAndCenterRectangle(m_xyzTl, m_xyzBr);
                }

                else if (v.PerspectiveCamera != null)
                {
                    if (v.PerspectiveCamera.FieldOfView == null || v.PerspectiveCamera.CameraViewPoint == null || v.PerspectiveCamera.CameraUpVector == null || v.PerspectiveCamera.CameraDirection == null)
                    {
                        return;
                    }

                    var    zoom   = v.PerspectiveCamera.FieldOfView;
                    double z1     = 18 / Math.Tan(zoom / 2 * Math.PI / 180); //focale 1
                    double z      = 18 / Math.Tan(25 / 2 * Math.PI / 180);   //focale, da controllare il 18, vedi PDF
                    double factor = z1 - z;

                    var CameraDirection = ARUP.IssueTracker.Revit.Classes.Utils.GetXYZ(v.PerspectiveCamera.CameraDirection.X, v.PerspectiveCamera.CameraDirection.Y, v.PerspectiveCamera.CameraDirection.Z);
                    var CameraUpVector  = ARUP.IssueTracker.Revit.Classes.Utils.GetXYZ(v.PerspectiveCamera.CameraUpVector.X, v.PerspectiveCamera.CameraUpVector.Y, v.PerspectiveCamera.CameraUpVector.Z);
                    XYZ oldO            = ARUP.IssueTracker.Revit.Classes.Utils.GetXYZ(v.PerspectiveCamera.CameraViewPoint.X, v.PerspectiveCamera.CameraViewPoint.Y, v.PerspectiveCamera.CameraViewPoint.Z);
                    var CameraViewPoint = (oldO.Subtract(CameraDirection.Divide(factor)));
                    var orient3d        = ARUP.IssueTracker.Revit.Classes.Utils.ConvertBasePoint(doc, CameraViewPoint, CameraDirection, CameraUpVector, true);



                    View3D perspView = null;

                    IEnumerable <View3D> viewcollector3D = get3DViews(doc);
                    if (viewcollector3D.Any() && viewcollector3D.Where(o => o.Name == "BCFpersp").Any())
                    {
                        perspView = viewcollector3D.Where(o => o.Name == "BCFpersp").First();
                    }
                    using (Transaction trans = new Transaction(uidoc.Document))
                    {
                        if (trans.Start("Open perspective view") == TransactionStatus.Started)
                        {
                            if (null == perspView)
                            {
                                perspView      = View3D.CreatePerspective(doc, getFamilyViews(doc).First().Id);
                                perspView.Name = "BCFpersp";
                            }

                            perspView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate);
                            perspView.SetOrientation(orient3d);

                            // turn on the far clip plane with standard parameter API
                            if (perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR).HasValue)
                            {
                                Parameter m_farClip = perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR);
                                m_farClip.Set(1);
                            }
                            // reset far clip offset
                            if (perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR).HasValue)
                            {
                                Parameter m_farClipOffset = perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR);
                                m_farClipOffset.SetValueString("35");
                            }
                            // turn off the far clip plane with standard parameter API
                            if (perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR).HasValue)
                            {
                                Parameter m_farClip = perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR);
                                m_farClip.Set(0);
                            }
                            perspView.CropBoxActive  = true;
                            perspView.CropBoxVisible = true;

                            trans.Commit();
                        }
                    }
                    uidoc.ActiveView = perspView;
                }
                else if (v.SheetCamera != null)//sheet
                {
                    //using (Transaction trans = new Transaction(uidoc.Document))
                    //{
                    //    if (trans.Start("Open sheet view") == TransactionStatus.Started)
                    //    {
                    IEnumerable <View> viewcollectorSheet = getSheets(doc, v.SheetCamera.SheetID);
                    if (!viewcollectorSheet.Any())
                    {
                        MessageBox.Show("No Sheet with Id=" + v.SheetCamera.SheetID + " found.");
                        return;
                    }
                    uidoc.ActiveView = viewcollectorSheet.First();
                    uidoc.ActiveView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate);
                    uidoc.RefreshActiveView();

                    //        trans.Commit();
                    //    }
                    //}
                    XYZ m_xyzTl = new XYZ(v.SheetCamera.TopLeft.X, v.SheetCamera.TopLeft.Y,
                                          v.SheetCamera.TopLeft.Z);
                    XYZ m_xyzBr = new XYZ(v.SheetCamera.BottomRight.X, v.SheetCamera.BottomRight.Y,
                                          v.SheetCamera.BottomRight.Z);
                    uidoc.GetOpenUIViews().First().ZoomAndCenterRectangle(m_xyzTl, m_xyzBr);
                }
                else
                {
                    return;
                }

                //apply BCF clipping planes to Revit section box
                View3D view3D = doc.ActiveView as View3D;
                if (view3D != null)
                {
                    if (v.ClippingPlanes != null)
                    {
                        if (v.ClippingPlanes.Count() > 0)
                        {
                            var result = getBoundingBoxFromClippingPlanes(doc, v.ClippingPlanes);

                            if (result != null)
                            {
                                BoundingBoxXYZ computedBox = result.Item1;
                                Transform      rotate      = result.Item2;

                                using (Transaction trans = new Transaction(uidoc.Document))
                                {
                                    if (trans.Start("Apply Section Box") == TransactionStatus.Started)
                                    {
                                        view3D.IsSectionBoxActive = true;
                                        view3D.SetSectionBox(computedBox);

                                        if (rotate != null)
                                        {
                                            // Transform the View3D's section box with the rotation transform
                                            computedBox.Transform = computedBox.Transform.Multiply(rotate);

                                            // Set the section box back to the view (requires an open transaction)
                                            view3D.SetSectionBox(computedBox);
                                        }
                                    }
                                    trans.Commit();
                                }
                            }
                        }
                    }
                }

                //select/hide elements
                if (v.Components != null && v.Components.Any())
                {
                    if (v.Components.Count > 100)
                    {
                        var result = MessageBox.Show("Too many elements attached. It may take for a while to isolate/select them. Do you want to continue?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                        if (result == MessageBoxResult.No)
                        {
                            uidoc.RefreshActiveView();
                            return;
                        }
                    }

                    FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id).WhereElementIsNotElementType();
                    System.Collections.Generic.ICollection <ElementId> collection = collector.ToElementIds();
                    foreach (var e in v.Components)
                    {
                        var bcfguid         = IfcGuid.FromIfcGUID(e.IfcGuid);
                        int authoringToolId = string.IsNullOrWhiteSpace(e.AuthoringToolId) ? -1 : int.Parse(e.AuthoringToolId);
                        var ids             = collection.Where(o => bcfguid == ExportUtils.GetExportId(doc, o) | authoringToolId == Convert.ToInt32(doc.GetElement(o).UniqueId.Substring(37), 16));
                        if (ids.Any())
                        {
                            // handle visibility
                            if (e.Visible)
                            {
                                elementsToBeIsolated.Add(ids.First());
                            }
                            else
                            {
                                elementsToBeHidden.Add(ids.First());
                            }

                            // handle selection
                            if (e.Selected)
                            {
                                elementsToBeSelected.Add(ids.First());
                            }
                        }
                    }

                    if (elementsToBeHidden.Count > 0)
                    {
                        using (Transaction trans = new Transaction(uidoc.Document))
                        {
                            if (trans.Start("Hide Elements") == TransactionStatus.Started)
                            {
                                uidoc.ActiveView.HideElementsTemporary(elementsToBeHidden);
                            }
                            trans.Commit();
                        }
                    }
                    else if (elementsToBeIsolated.Count > 0)
                    {
                        using (Transaction trans = new Transaction(uidoc.Document))
                        {
                            if (trans.Start("Isolate Elements") == TransactionStatus.Started)
                            {
                                uidoc.ActiveView.IsolateElementsTemporary(elementsToBeIsolated);
                            }
                            trans.Commit();
                        }
                    }

                    if (elementsToBeSelected.Count > 0)
                    {
                        using (Transaction trans = new Transaction(uidoc.Document))
                        {
                            if (trans.Start("Select Elements") == TransactionStatus.Started)
                            {
                                SelElementSet selectedElements = SelElementSet.Create();
                                elementsToBeSelected.ForEach(id => {
                                    selectedElements.Add(doc.GetElement(id));
                                });

                                uidoc.Selection.Elements = selectedElements;
                            }
                            trans.Commit();
                        }
                    }
                }

                uidoc.RefreshActiveView();
            }
            catch (Exception ex)
            {
                TaskDialog.Show("Error!", "exception: " + ex);
            }
        }