Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
0
        private void comboBoxDoc_SelectedIndexChanged(object sender, EventArgs e)
        {
            dataGridViewView.DataSource = null;
            Document  doc    = comboBoxDoc.SelectedValue as Document;
            ArrayList alView = new ArrayList();

            FilteredElementCollector collector;

            collector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Views).OfClass(typeof(View3D));

            var Elems = from eleFilter in collector
                        where ((View3D)eleFilter).IsTemplate == false
                        orderby((View3D)eleFilter).Name
                        select eleFilter;

            foreach (Element ele in Elems) //得到楼层
            {
                View3D v3dView = ele as View3D;

                cView cview = new cView(v3dView.Name, v3dView, v3dView.GetSectionBox());
                alView.Add(cview);
            }

            dataGridViewView.DataSource = alView;
        }
        // https://forums.autodesk.com/t5/revit-api-forum/set-view-cropbox-to-a-section-box/m-p/9600049

        public static void AdjustViewCropToSectionBox(
            /*this*/ View3D view)
        {
            if (!view.IsSectionBoxActive)
            {
                return;
            }
            if (!view.CropBoxActive)
            {
                view.CropBoxActive = true;
            }
            BoundingBoxXYZ CropBox    = view.CropBox;
            BoundingBoxXYZ SectionBox = view.GetSectionBox();
            Transform      T          = CropBox.Transform;
            var            Corners    = BBCorners(SectionBox, T);
            double         MinX       = Corners.Min(j => j.X);
            double         MinY       = Corners.Min(j => j.Y);
            double         MinZ       = Corners.Min(j => j.Z);
            double         MaxX       = Corners.Max(j => j.X);
            double         MaxY       = Corners.Max(j => j.Y);
            double         MaxZ       = Corners.Max(j => j.Z);

            CropBox.Min  = new XYZ(MinX, MinY, MinZ);
            CropBox.Max  = new XYZ(MaxX, MaxY, MaxZ);
            view.CropBox = CropBox;
        }
        /// <summary>
        /// Return relevant 3D view information (from
        /// Revit API documentation help file  sample).
        /// </summary>
        static string GetView3dInfo(View3D view3d)
        {
            string message = "3D View: ";

            // The position of the camera and view direction.

            ViewOrientation3D ori = view3d.GetOrientation();
            XYZ peye     = ori.EyePosition;
            XYZ vforward = ori.ForwardDirection;
            XYZ vup      = ori.UpDirection;

            message += string.Format(
                "\r\nCamera position: {0}"
                + "\r\nView direction: {1}"
                + "\r\nUp direction: {2}",
                Util.PointString(peye),
                Util.PointString(vforward),
                Util.PointString(vup));

            // Identifies whether the view is a perspective view.

            if (view3d.IsPerspective)
            {
                message += "\r\nThe view is a perspective view.";
            }

            // The section box of the 3D view can cut the model.

            if (view3d.IsSectionBoxActive)
            {
                BoundingBoxXYZ sectionBox = view3d.GetSectionBox();

                // Note that the section box can be rotated
                // and transformed. So the min/max corners
                // coordinates relative to the model must be
                // computed via the transform.

                Transform trf = sectionBox.Transform;

                XYZ max = sectionBox.Max; // Maximum coordinates (upper-right-front corner of the box before transform is applied).
                XYZ min = sectionBox.Min; // Minimum coordinates (lower-left-rear corner of the box before transform is applied).

                // Transform the min and max to model coordinates

                XYZ maxInModelCoords = trf.OfPoint(max);
                XYZ minInModelCoords = trf.OfPoint(min);

                message += "\r\nView has an active section box: ";

                message += "\r\n'Maximum' coordinates: "
                           + Util.PointString(maxInModelCoords);

                message += "\r\n'Minimum' coordinates: "
                           + Util.PointString(minInModelCoords);
            }
            return(message);
        }
Ejemplo n.º 5
0
 public BoundingBoxXYZ GetOriginalBox()
 {
     if (uiApp.ActiveUIDocument.Document.ActiveView.ViewType != ViewType.ThreeD)
     {
         return(uiApp.ActiveUIDocument.ActiveView.CropBox);
     }
     else
     {
         View3D view3D = uiApp.ActiveUIDocument.ActiveView as View3D;
         return(view3D.GetSectionBox());
     }
 }
        //get the bounding box for sectionbox of the 3D view
        public static BoundingBoxXYZ GetBounds(View3D view)
        {
            BoundingBoxXYZ bounds = new BoundingBoxXYZ();

            try
            {
                bounds = view.GetSectionBox();
                view.IsSectionBoxActive = false;
            }
            catch
            {
                return(null);
            }
            return(bounds);
        }
Ejemplo n.º 7
0
        public CameraViewInfo(View3D view3d)
        {
            ViewId   = view3d.Id.IntegerValue;
            ViewName = view3d.Name;

            ViewTemplateId = view3d.ViewTemplateId;

            Orientation    = view3d.GetOrientation();
            IsCropBoxOn    = view3d.CropBoxActive;
            CropBox        = view3d.CropBox;
            IsSectionBoxOn = view3d.IsSectionBoxActive;
            SectionBox     = view3d.GetSectionBox();

            Display = view3d.DisplayStyle;
            GetParameters(view3d.Parameters);
        }
Ejemplo n.º 8
0
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            uiApp = commandData.Application;

            FormSectionBoxList fs = new FormSectionBoxList(commandData.Application, null, null);

            if (fs.ShowDialog() == DialogResult.OK)
            {
                if (uiApp.ActiveUIDocument.Document.ActiveView.ViewType != ViewType.ThreeD)
                {
                    TaskDialog.Show("提示", "只对3维视图有效", TaskDialogCommonButtons.Close);
                    return(Autodesk.Revit.UI.Result.Succeeded);
                }
                View3D         view3dActive = (View3D)uiApp.ActiveUIDocument.Document.ActiveView;
                BoundingBoxXYZ sectionBox   = view3dActive.GetSectionBox();

                using (Transaction trans = new Transaction(uiApp.ActiveUIDocument.Document))
                {
                    // The name of the transaction was given as an argument
                    if (trans.Start("sectionBox Copy") == TransactionStatus.Started)
                    {
                        // apply the requested operation to every door
                        //view3dActive.SetSectionBox();

                        trans.Commit();
                    }
                }
            }
            return(Autodesk.Revit.UI.Result.Succeeded);



            //try
            //{
            //    ClassApplication.thisApp.ShowFormCopy(commandData.Application);

            //    return Result.Succeeded;
            //}
            //catch (Exception ex)
            //{
            //    message = ex.Message;
            //    return Result.Failed;
            //}
        }
Ejemplo n.º 9
0
 //get the bounding box for sectionbox of the 3D view
 public void GetBoundsDetail()
 {
     try
     {
         using (Transaction tran = new Transaction(doc, "Manage View"))
         {
             tran.Start();
             bounds = view3D.GetSectionBox();
             view3D.IsSectionBoxActive = false;
             detail = view3D.get_Parameter(BuiltInParameter.VIEW_DETAIL_LEVEL).AsInteger();
             view3D.get_Parameter(BuiltInParameter.VIEW_DETAIL_LEVEL).Set(2);
             tran.Commit();
         }
     }
     catch
     {
         throw new Exception();
     }
 }
Ejemplo n.º 10
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();
                }
            }
        }
Ejemplo n.º 11
0
        public static bool belongsToView(View3D view3D, BoundingBoxXYZ bb)
        {
            var SectionBox = view3D.GetSectionBox();
            var vMax       = SectionBox.Max + SectionBox.Transform.Origin;
            var vMin       = SectionBox.Min + SectionBox.Transform.Origin;
            var bbMax      = bb.Max;
            var bbMin      = bb.Min;

            if (bbMin.X < vMax.X && bbMax.X > vMin.X)
            {
                if (bbMin.Y < vMax.Y && bbMax.Y > vMin.Y)
                {
                    if (bbMin.Z < vMax.Z && bbMax.Z > vMin.Z)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 12
0
        private void SetElementTransparency(View3D view3d, Dictionary <int, Element> elementDictionary)
        {
            try
            {
                this.toolStripProgressBar1.Visible = true;
                this.toolStripStatusLabel1.Text    = "Setting Transparency of Elements...";
                Application.DoEvents();
                System.Threading.Thread.Sleep(1000);

                OverrideGraphicSettings settings = new OverrideGraphicSettings();
                settings.SetSurfaceTransparency(70);
                settings.SetHalftone(true);

                BoundingBoxXYZ boundingBox                      = view3d.GetSectionBox();
                Outline        outline                          = new Outline(boundingBox.Min, boundingBox.Max);
                BoundingBoxIntersectsFilter filter              = new BoundingBoxIntersectsFilter(outline);
                FilteredElementCollector    collector           = new FilteredElementCollector(m_doc);
                IList <Element>             boundingBoxElements = collector.WherePasses(filter).ToElements();

                this.toolStripProgressBar1.Maximum = boundingBoxElements.Count;
                this.toolStripProgressBar1.Value   = 0;
                this.toolStripProgressBar1.ProgressBar.Refresh();

                foreach (Element element in boundingBoxElements)
                {
                    if (elementDictionary.ContainsKey(element.Id.IntegerValue))
                    {
                        continue;
                    }
                    view3d.SetElementOverrides(element.Id, settings);
                    this.toolStripProgressBar1.PerformStep();
                }
                this.toolStripProgressBar1.Visible = false;
                this.toolStripStatusLabel1.Text    = "Ready";
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create a 3DView named " + selectedView + "\n" + ex.Message, "CommandForm:Create3DView", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bcfView"></param>
        /// <param name="removeHighlight"></param>
        /// <param name="removeIsolate"></param>
        /// <param name="removeSectionBox"></param>
        private void CleanViewSettings(View3D bcfView, bool removeHighlight, bool removeIsolate, bool removeSectionBox)
        {
            using (var trans = new Transaction(ActiveDoc))
            {
                trans.Start("Clean Views");
                try
                {
                    var uidoc = new UIDocument(ActiveDoc);
                    if (removeHighlight)
                    {
                        //remove selection
                        uidoc.Selection.SetElementIds(new List <ElementId>());
                    }

                    if (removeIsolate)
                    {
                        //remove isolation
                        if (bcfView.IsInTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate))
                        {
                            bcfView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate);
                        }
                    }

                    if (removeSectionBox)
                    {
                        //remove sectionbox
                        bcfView.GetSectionBox().Enabled = false;
                    }

                    trans.Commit();
                }
                catch (Exception)
                {
                    trans.RollBack();
                }
            }
        }
Ejemplo n.º 14
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();
                }
            }
        }
Ejemplo n.º 15
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

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

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

            PlanViewRange viewRange = viewPlan.GetViewRange();

            viewRange.SetLevelId(PlanViewPlane.TopClipPlane, level.Id);
            viewRange.SetLevelId(PlanViewPlane.CutPlane, level.Id);
            viewRange.SetLevelId(PlanViewPlane.BottomClipPlane, level.Id);
            viewRange.SetLevelId(PlanViewPlane.ViewDepthPlane, level.Id);
            if (viewPlan.ViewType == ViewType.CeilingPlan)
            {
                viewRange.SetOffset(PlanViewPlane.CutPlane, minZ - level.Elevation);
                viewRange.SetOffset(PlanViewPlane.TopClipPlane, maxZ - level.Elevation);
                viewRange.SetOffset(PlanViewPlane.ViewDepthPlane, maxZ - level.Elevation);
                viewRange.SetOffset(PlanViewPlane.BottomClipPlane, minZ - level.Elevation);
            }
            if (viewPlan.ViewType != ViewType.CeilingPlan)
            {
                viewRange.SetOffset(PlanViewPlane.CutPlane, maxZ - level.Elevation);
                viewRange.SetOffset(PlanViewPlane.BottomClipPlane, minZ - level.Elevation);
                viewRange.SetOffset(PlanViewPlane.ViewDepthPlane, minZ - level.Elevation);
                viewRange.SetOffset(PlanViewPlane.TopClipPlane, maxZ - level.Elevation);
            }
            using (Transaction t = new Transaction(doc))
            {
                t.Start("Set View Range");
                viewPlan.SetViewRange(viewRange);
                t.Commit();
            }
            return(Result.Succeeded);
        }
Ejemplo n.º 16
0
        private OrthogonalCamera GetOrthogonalCamera(Dictionary <int, ElementProperties> elementDictionary, string imagePath)
        {
            OrthogonalCamera orthoCamera = new OrthogonalCamera();

            try
            {
                BoundingBoxXYZ boundingBox = new BoundingBoxXYZ();
                boundingBox.Enabled = true;
                for (int i = 0; i < 3; i++)
                {
                    boundingBox.set_MinEnabled(i, true);
                    boundingBox.set_MaxEnabled(i, true);
                    boundingBox.set_BoundEnabled(0, i, true);
                    boundingBox.set_BoundEnabled(1, i, true);
                }

                BoundingBoxXYZ tempBoundingBox = elementDictionary.First().Value.RevitElement.get_BoundingBox(null);
                tempBoundingBox.Enabled = true;

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

                List <ElementId>           elementIds = new List <ElementId>();
                Dictionary <int, Category> categories = new Dictionary <int, Category>();
                foreach (ElementProperties ep in elementDictionary.Values)
                {
                    Element element = ep.RevitElement;
                    if (null != element)
                    {
                        try
                        {
                            if (!categories.ContainsKey(element.Category.Id.IntegerValue))
                            {
                                categories.Add(element.Category.Id.IntegerValue, element.Category);
                            }
                            BoundingBoxXYZ bbBox = element.get_BoundingBox(null);
                            bbBox.Enabled = true;
                            elementIds.Add(element.Id);
                            if (null != boundingBox)
                            {
                                if (bbBox.Max.X > maxX)
                                {
                                    maxX = bbBox.Max.X;
                                }
                                if (bbBox.Max.Y > maxY)
                                {
                                    maxY = bbBox.Max.Y;
                                }
                                if (bbBox.Max.Z > maxZ)
                                {
                                    maxZ = bbBox.Max.Z;
                                }
                                if (bbBox.Min.X < minX)
                                {
                                    minX = bbBox.Min.X;
                                }
                                if (bbBox.Min.Y < minY)
                                {
                                    minY = bbBox.Min.Y;
                                }
                                if (bbBox.Min.Z < minZ)
                                {
                                    minZ = bbBox.Min.Z;
                                }
                            }
                        }
                        catch
                        {
                            continue;
                        }
                    }
                }

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

                boundingBox.set_Bounds(0, xyzMin);
                boundingBox.set_Bounds(1, xyzMax);


                ViewFamilyType           view3dFamilyType = null;
                FilteredElementCollector collector        = new FilteredElementCollector(m_doc);
                List <Element>           elements         = collector.OfClass(typeof(ViewFamilyType)).ToElements().ToList();
                foreach (Element element in elements)
                {
                    ViewFamilyType viewfamilytype = element as ViewFamilyType;
                    if (viewfamilytype.ViewFamily == ViewFamily.ThreeDimensional)
                    {
                        view3dFamilyType = viewfamilytype; break;
                    }
                }

                if (null != view3dFamilyType)
                {
                    using (TransactionGroup transGroup = new TransactionGroup(m_doc))
                    {
                        transGroup.Start("Start Creating View 3D");
                        using (Transaction trans = new Transaction(m_doc))
                        {
                            trans.Start("Create View");

                            View3D view3d = View3D.CreateIsometric(m_doc, view3dFamilyType.Id);
                            view3d.SetSectionBox(boundingBox);
                            view3d.GetSectionBox().Enabled = true;
                            view3d.DetailLevel = ViewDetailLevel.Fine;

                            foreach (Category category in categories.Values)
                            {
                                if (category.get_AllowsVisibilityControl(view3d))
                                {
#if RELEASE2017 || RELEASE2018
                                    view3d.SetCategoryHidden(category.Id, false);
#else
                                    view3d.SetVisibility(category, true);
#endif
                                }
                            }

                            view3d.get_Parameter(BuiltInParameter.MODEL_GRAPHICS_STYLE).Set(4);

                            //m_app.ActiveUIDocument.ActiveView = view3d;
                            //m_app.ActiveUIDocument.RefreshActiveView();

                            XYZ   eyePostion = view3d.GetOrientation().EyePosition;
                            Point viewPoint  = new Point();
                            viewPoint.X = eyePostion.X; viewPoint.Y = eyePostion.Y; viewPoint.Z = eyePostion.Z;
                            orthoCamera.CameraViewPoint = viewPoint;

                            XYZ       forwardDirection = view3d.GetOrientation().ForwardDirection;
                            Direction fDirection       = new Direction();
                            fDirection.X = forwardDirection.X; fDirection.Y = forwardDirection.Y; fDirection.Z = forwardDirection.Z;
                            orthoCamera.CameraDirection = fDirection;

                            XYZ       upDirection = view3d.GetOrientation().UpDirection;
                            Direction uDirection  = new Direction();
                            uDirection.X = upDirection.X; uDirection.Y = upDirection.Y; uDirection.Z = upDirection.Z;
                            orthoCamera.CameraUpVector = uDirection;

                            orthoCamera.ViewToWorldScale = view3d.Scale;
                            m_app.ActiveUIDocument.RefreshActiveView();
                            trans.Commit();

                            trans.Start("Export Image");
                            //create snapshot.png
                            ImageExportOptions option = new ImageExportOptions();
                            option.HLRandWFViewsFileType = ImageFileType.PNG;
                            option.ImageResolution       = ImageResolution.DPI_300;
                            option.ShouldCreateWebSite   = false;
                            option.ExportRange           = ExportRange.SetOfViews;
                            option.FilePath = imagePath;
                            List <ElementId> viewIds = new List <ElementId>();
                            viewIds.Add(view3d.Id);
                            option.SetViewsAndSheets(viewIds);

                            if (ImageExportOptions.IsValidFileName(option.FilePath))
                            {
                                m_doc.ExportImage(option);
                            }
                            trans.Commit();
                        }
                        transGroup.RollBack();
                    }

                    if (File.Exists(imagePath))
                    {
                        File.Delete(imagePath);
                    }
                    string[] fileNames = Directory.GetFiles(Path.GetDirectoryName(imagePath), "snapshot*");
                    foreach (string fName in fileNames)
                    {
                        if (Path.GetExtension(fName) == ".png" || Path.GetExtension(fName) == ".jpg")
                        {
                            File.Move(fName, imagePath);
                            if (File.Exists(fName))
                            {
                                File.Delete(fName);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to get the orthogonal camera.\n" + ex.Message, "Get Orthogonal Camera", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(orthoCamera);
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Generate Viewpoint
        /// </summary>
        /// <param name="elemCheck"></param>
        /// <returns></returns>
        public VisualizationInfo generateViewpoint(int elemCheck)
        {
            try
            {
                UIDocument uidoc = uiapp.ActiveUIDocument;
                Document   doc   = uidoc.Document;

                VisualizationInfo v = new VisualizationInfo();

                XYZ    centerIMP = new XYZ();
                string type      = "";
                double zoomValue = 1;

                if (uidoc.ActiveView.ViewType != ViewType.ThreeD) //is a 2D view
                {
                    XYZ TL = uidoc.GetOpenUIViews()[0].GetZoomCorners()[0];
                    XYZ BR = uidoc.GetOpenUIViews()[0].GetZoomCorners()[1];
                    v.SheetCamera             = new SheetCamera();
                    v.SheetCamera.SheetID     = uidoc.ActiveView.Id.IntegerValue;
                    v.SheetCamera.TopLeft     = new IssueTracker.Classes.BCF2.Point(TL.X, TL.Y, TL.Z);
                    v.SheetCamera.BottomRight = new IssueTracker.Classes.BCF2.Point(BR.X, BR.Y, BR.Z);
                }
                else
                {
                    View3D view3D = (View3D)uidoc.ActiveView;
                    if (!view3D.IsPerspective) //IS ORTHO
                    {
                        XYZ TL = uidoc.GetOpenUIViews()[0].GetZoomCorners()[0];
                        XYZ BR = uidoc.GetOpenUIViews()[0].GetZoomCorners()[1];

                        double xO = (TL.X + BR.X) / 2;
                        double yO = (TL.Y + BR.Y) / 2;
                        double zO = (TL.Z + BR.Z) / 2;
                        //converto to METERS
                        centerIMP = new XYZ(xO, yO, zO);
                        double dist       = TL.DistanceTo(BR) / 2; //custom sectet value to get solibri zoom value from Corners of Revit UiView
                        XYZ    diagVector = TL.Subtract(BR);
                        // **** CUSTOM VALUE FOR TEKLA **** //
                        //zoomValue = UnitUtils.ConvertFromInternalUnits(dist * Math.Sin(diagVector.AngleTo(view3D.RightDirection)), DisplayUnitType.DUT_METERS);
                        // **** CUSTOM VALUE FOR TEKLA **** //
                        double customZoomValue = (MyProjectSettings.Get("useDefaultZoom", doc.PathName) == "1") ? 1 : 2.5;

                        zoomValue = UnitUtils.ConvertFromInternalUnits(dist * Math.Sin(diagVector.AngleTo(view3D.RightDirection)), DisplayUnitType.DUT_METERS) * customZoomValue;
                        type      = "OrthogonalCamera";
                    }
                    else // it is a perspective view
                    {
                        centerIMP = uidoc.ActiveView.Origin;
                        type      = "PerspectiveCamera";
                        zoomValue = 45;
                    }
                    ViewOrientation3D t = ConvertBasePoint(centerIMP, uidoc.ActiveView.ViewDirection, uidoc.ActiveView.UpDirection, false);
                    //ViewOrientation3D t = new ViewOrientation3D(centerIMP, uidoc.ActiveView.UpDirection, uidoc.ActiveView.ViewDirection);
                    XYZ c  = t.EyePosition;
                    XYZ vi = t.ForwardDirection;
                    XYZ up = t.UpDirection;

                    if (type == "OrthogonalCamera")
                    {
                        v.OrthogonalCamera = new OrthogonalCamera();
                        v.OrthogonalCamera.CameraViewPoint.X = UnitUtils.ConvertFromInternalUnits(c.X, DisplayUnitType.DUT_METERS);
                        v.OrthogonalCamera.CameraViewPoint.Y = UnitUtils.ConvertFromInternalUnits(c.Y, DisplayUnitType.DUT_METERS);
                        v.OrthogonalCamera.CameraViewPoint.Z = UnitUtils.ConvertFromInternalUnits(c.Z, DisplayUnitType.DUT_METERS);
                        v.OrthogonalCamera.CameraUpVector.X  = UnitUtils.ConvertFromInternalUnits(up.X, DisplayUnitType.DUT_METERS);
                        v.OrthogonalCamera.CameraUpVector.Y  = UnitUtils.ConvertFromInternalUnits(up.Y, DisplayUnitType.DUT_METERS);
                        v.OrthogonalCamera.CameraUpVector.Z  = UnitUtils.ConvertFromInternalUnits(up.Z, DisplayUnitType.DUT_METERS);
                        v.OrthogonalCamera.CameraDirection.X = UnitUtils.ConvertFromInternalUnits(vi.X, DisplayUnitType.DUT_METERS) * -1;
                        v.OrthogonalCamera.CameraDirection.Y = UnitUtils.ConvertFromInternalUnits(vi.Y, DisplayUnitType.DUT_METERS) * -1;
                        v.OrthogonalCamera.CameraDirection.Z = UnitUtils.ConvertFromInternalUnits(vi.Z, DisplayUnitType.DUT_METERS) * -1;
                        v.OrthogonalCamera.ViewToWorldScale  = zoomValue;
                    }
                    else
                    {
                        v.PerspectiveCamera = new PerspectiveCamera();
                        v.PerspectiveCamera.CameraViewPoint.X = UnitUtils.ConvertFromInternalUnits(c.X, DisplayUnitType.DUT_METERS);
                        v.PerspectiveCamera.CameraViewPoint.Y = UnitUtils.ConvertFromInternalUnits(c.Y, DisplayUnitType.DUT_METERS);
                        v.PerspectiveCamera.CameraViewPoint.Z = UnitUtils.ConvertFromInternalUnits(c.Z, DisplayUnitType.DUT_METERS);
                        v.PerspectiveCamera.CameraUpVector.X  = UnitUtils.ConvertFromInternalUnits(up.X, DisplayUnitType.DUT_METERS);
                        v.PerspectiveCamera.CameraUpVector.Y  = UnitUtils.ConvertFromInternalUnits(up.Y, DisplayUnitType.DUT_METERS);
                        v.PerspectiveCamera.CameraUpVector.Z  = UnitUtils.ConvertFromInternalUnits(up.Z, DisplayUnitType.DUT_METERS);
                        v.PerspectiveCamera.CameraDirection.X = UnitUtils.ConvertFromInternalUnits(vi.X, DisplayUnitType.DUT_METERS) * -1;
                        v.PerspectiveCamera.CameraDirection.Y = UnitUtils.ConvertFromInternalUnits(vi.Y, DisplayUnitType.DUT_METERS) * -1;
                        v.PerspectiveCamera.CameraDirection.Z = UnitUtils.ConvertFromInternalUnits(vi.Z, DisplayUnitType.DUT_METERS) * -1;
                        v.PerspectiveCamera.FieldOfView       = zoomValue;
                    }


                    // handle section box if enabled
                    if (view3D.IsSectionBoxActive)
                    {
                        BoundingBoxXYZ sectionBox = view3D.GetSectionBox();

                        // Note that the section box can be rotated and transformed.
                        // So the min/max corners coordinates relative to the model must be computed via the transform.
                        Transform trf = sectionBox.Transform;

                        XYZ max = sectionBox.Max; //Maximum coordinates (upper-right-front corner of the box before transform is applied).
                        XYZ min = sectionBox.Min; //Minimum coordinates (lower-left-rear corner of the box before transform is applied).

                        // Transform the min and max to model coordinates
                        XYZ maxInModelCoords = trf.OfPoint(max);
                        XYZ minInModelCoords = trf.OfPoint(min);

                        // Convert to project unit
                        DisplayUnitType lengthUnitType = doc.GetUnits().GetFormatOptions(UnitType.UT_Length).DisplayUnits;
                        maxInModelCoords = new XYZ(UnitUtils.ConvertFromInternalUnits(maxInModelCoords.X, lengthUnitType),
                                                   UnitUtils.ConvertFromInternalUnits(maxInModelCoords.Y, lengthUnitType),
                                                   UnitUtils.ConvertFromInternalUnits(maxInModelCoords.Z, lengthUnitType));
                        minInModelCoords = new XYZ(UnitUtils.ConvertFromInternalUnits(minInModelCoords.X, lengthUnitType),
                                                   UnitUtils.ConvertFromInternalUnits(minInModelCoords.Y, lengthUnitType),
                                                   UnitUtils.ConvertFromInternalUnits(minInModelCoords.Z, lengthUnitType));

                        // Convert to shared coordinates
                        maxInModelCoords = ARUP.IssueTracker.Revit.Classes.Utils.ConvertToFromSharedCoordinate(doc, maxInModelCoords, false);
                        minInModelCoords = ARUP.IssueTracker.Revit.Classes.Utils.ConvertToFromSharedCoordinate(doc, minInModelCoords, false);

                        // Add to BCF clipping planes
                        v.ClippingPlanes = BcfAdapter.GetClippingPlanesFromBoundingBox
                                           (
                            maxInModelCoords.X, maxInModelCoords.Y, maxInModelCoords.Z,
                            minInModelCoords.X, minInModelCoords.Y, minInModelCoords.Z
                                           );
                    }
                }


                //COMPONENTS PART
                FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id).WhereElementIsNotElementType();
                System.Collections.Generic.ICollection <ElementId> collection = null;

                if (elemCheck == 0)
                {
                    collection = collector.ToElementIds();
                }
                else if (elemCheck == 1)
                {
                    collection = uidoc.Selection.GetElementIds();
                }

                if (null != collection && collection.Any())
                {
                    v.Components = new List <IssueTracker.Classes.BCF2.Component>();
                    foreach (var eId in collection)
                    {
                        Guid   guid    = ExportUtils.GetExportId(doc, eId);
                        string ifcguid = IfcGuid.ToIfcGuid(guid).ToString();
                        v.Components.Add(new ARUP.IssueTracker.Classes.BCF2.Component(doc.Application.VersionName, eId.ToString(), ifcguid));
                    }
                }

                return(v);
            }
            catch (System.Exception ex1)
            {
                TaskDialog.Show("Error!", "exception: " + ex1);
            }
            return(null);
        }
Ejemplo n.º 19
0
        public void Execute(UIApplication uiapp)
        {
            bool   bFirst = true;
            double xTempMax = 0, yTempMax = 0, zTempMax = 0;
            double xTempMin = 0, yTempMin = 0, zTempMin = 0;

            try
            {
                cSectionbox cS = Request.Take();
                //必须为3d View
                if (uiapp.ActiveUIDocument.Document.ActiveView.ViewType != ViewType.ThreeD)
                {
                    TaskDialog.Show("提示", "只对3维视图有效", TaskDialogCommonButtons.Close);
                    return;
                }
                View3D         view3dActive = (View3D)uiapp.ActiveUIDocument.Document.ActiveView;
                BoundingBoxXYZ sectionBox   = view3dActive.GetSectionBox();
                XYZ            xyzT;

                if (cS.bSelect) //选择集决定
                {
                    //ICollection<ElementId> selElements = uiapp.ActiveUIDocument.Selection.GetElementIds();

                    //if (uiapp.ActiveUIDocument.Selection.Elements.Size > 0)
                    if (uiapp.ActiveUIDocument.Selection.GetElementIds().Count > 0)
                    {
                        bFirst = true;
                        foreach (ElementId eId in uiapp.ActiveUIDocument.Selection.GetElementIds())
                        {
                            Element        el   = uiapp.ActiveUIDocument.Document.GetElement(eId);
                            BoundingBoxXYZ bXYZ = el.get_BoundingBox(uiapp.ActiveUIDocument.ActiveView);


                            if (bXYZ == null)
                            {
                                continue;
                            }

                            if (bFirst) //第一次
                            {
                                xTempMax = bXYZ.Max.X; yTempMax = bXYZ.Max.Y; zTempMax = bXYZ.Max.Z;
                                xTempMin = bXYZ.Min.X; yTempMin = bXYZ.Min.Y; zTempMin = bXYZ.Min.Z;

                                bFirst = false;
                            }
                            else
                            {
                                xTempMax = Math.Max(xTempMax, bXYZ.Max.X);
                                yTempMax = Math.Max(yTempMax, bXYZ.Max.Y);
                                zTempMax = Math.Max(zTempMax, bXYZ.Max.Z);

                                xTempMin = Math.Min(xTempMin, bXYZ.Min.X);
                                yTempMin = Math.Min(yTempMin, bXYZ.Min.Y);
                                zTempMin = Math.Min(zTempMin, bXYZ.Min.Z);

                                //TaskDialog.Show("提示", "xTemp=" + xTemp.ToString() + " yTemp=" + yTemp.ToString() + " zTemp" + zTemp.ToString(), TaskDialogCommonButtons.Close);
                            }
                        }
                        if (!bFirst)
                        {
                            if (cS.bZ)
                            {
                                XYZ XYZMaxNew = sectionBox.Transform.Inverse.OfPoint(new XYZ(xTempMax + UnitUtils.ConvertToInternalUnits(cS.dWY, DisplayUnitType.DUT_MILLIMETERS), yTempMax + UnitUtils.ConvertToInternalUnits(cS.dWY, DisplayUnitType.DUT_MILLIMETERS), zTempMax + UnitUtils.ConvertToInternalUnits(cS.dWY, DisplayUnitType.DUT_MILLIMETERS)));
                                XYZ XYZMinNew = sectionBox.Transform.Inverse.OfPoint(new XYZ(xTempMin - UnitUtils.ConvertToInternalUnits(cS.dWY, DisplayUnitType.DUT_MILLIMETERS), yTempMin - UnitUtils.ConvertToInternalUnits(cS.dWY, DisplayUnitType.DUT_MILLIMETERS), zTempMin - UnitUtils.ConvertToInternalUnits(cS.dWY, DisplayUnitType.DUT_MILLIMETERS)));

                                sectionBox.Max = XYZMaxNew;
                                sectionBox.Min = XYZMinNew;
                            }
                            else
                            {
                                XYZ XYZMaxNew = sectionBox.Transform.Inverse.OfPoint(new XYZ(xTempMax + UnitUtils.ConvertToInternalUnits(cS.dWY, DisplayUnitType.DUT_MILLIMETERS), yTempMax + UnitUtils.ConvertToInternalUnits(cS.dWY, DisplayUnitType.DUT_MILLIMETERS), zTempMax));
                                XYZ XYZMinNew = sectionBox.Transform.Inverse.OfPoint(new XYZ(xTempMin - UnitUtils.ConvertToInternalUnits(cS.dWY, DisplayUnitType.DUT_MILLIMETERS), yTempMin - UnitUtils.ConvertToInternalUnits(cS.dWY, DisplayUnitType.DUT_MILLIMETERS), zTempMin));

                                sectionBox.Max = XYZMaxNew;
                                sectionBox.Min = XYZMinNew;
                            }

                            //sectionBox
                        }
                    }
                    else
                    {
                        TaskDialog.Show("提示", "请进行选择", TaskDialogCommonButtons.Close);
                        return;
                    }
                }
                else
                {
                    sectionBox = changeSectionBox(sectionBox, cS.dCeil, cS.dFloor);
                    bFirst     = false;
                }

                //TaskDialog.Show(cS.dCeil.ToString(), cS.dFloor.ToString());
                if (!bFirst)
                {
                    using (Transaction trans = new Transaction(uiapp.ActiveUIDocument.Document))
                    {
                        // The name of the transaction was given as an argument
                        if (trans.Start("sectionBox Level") == TransactionStatus.Started)
                        {
                            // apply the requested operation to every door
                            view3dActive.SetSectionBox(sectionBox);

                            trans.Commit();
                        }
                    }
                }



                //TaskDialog.Show("提示", "sectionBox.Max.z" + sectionBox.Max.Z.ToString()+" sectionBox.Min.z" + sectionBox.Min.Z.ToString(), TaskDialogCommonButtons.Close);

                //Transaction trans = new Transaction(uiapp.ActiveUIDocument.Document, "sectionBox Level");
                //view3dActive.SetSectionBox(sectionBox);
                //view3dActive.SectionBox = sectionBox;

                //287091
            }
            finally
            {
                ClassApplication.thisApp.WakeFormUp();
            }

            return;
        }