示例#1
0
        /// <summary>
        /// Orthogonal View by Perspective Camera.
        /// </summary>
        /// <param name="bcfView"></param>
        /// <param name="camera"></param>
        /// <returns></returns>
        private bool SetOrthogonalView(View3D bcfView, PerspectiveCamera camera)
        {
            var result = false;

            try
            {
                var direction   = RevitUtils.GetRevitXYZ(camera.CameraDirection);
                var upVector    = RevitUtils.GetRevitXYZ(camera.CameraUpVector);
                var viewPoint   = RevitUtils.GetRevitXYZ(camera.CameraViewPoint);
                var orientation = RevitUtils.ConvertBasePoint(ActiveDoc, viewPoint, direction, upVector, true);

                using (var trans = new Transaction(ActiveDoc))
                {
                    trans.Start("Set Orientation");
                    try
                    {
                        bcfView.SetOrientation(orientation);
                        trans.Commit();
                    }
                    catch (Exception)
                    {
                        trans.RollBack();
                    }
                }

                SetViewPointBoundingBox(bcfView);
                result = true;
            }
            catch (Exception)
            {
                // ignored
            }

            return(result);
        }
示例#2
0
        private bool SetPerspectiveView(View3D bcfView, PerspectiveCamera camera)
        {
            var result = false;

            try
            {
                var zoom        = camera.FieldOfView;
                var direction   = RevitUtils.GetRevitXYZ(camera.CameraDirection);
                var upVector    = RevitUtils.GetRevitXYZ(camera.CameraUpVector);
                var viewPoint   = RevitUtils.GetRevitXYZ(camera.CameraViewPoint);
                var orientation = RevitUtils.ConvertBasePoint(ActiveDoc, viewPoint, direction, upVector, true);


                using (var trans = new Transaction(ActiveDoc))
                {
                    trans.Start("Set Orientation");
                    try
                    {
                        if (bcfView.CanResetCameraTarget())
                        {
                            bcfView.ResetCameraTarget();
                        }
                        bcfView.SetOrientation(orientation);
                        if (bcfView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR).HasValue)
                        {
                            var m_farClip = bcfView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR);
                            m_farClip.Set(0);
                        }

                        bcfView.CropBoxActive  = true;
                        bcfView.CropBoxVisible = true;

                        trans.Commit();
                    }
                    catch (Exception)
                    {
                        trans.RollBack();
                    }
                }
                result = true;
            }
            catch (Exception)
            {
                // ignored
            }

            return(result);
        }
示例#3
0
        private bool SetOrthogonalView(View3D bcfView, OrthogonalCamera camera)
        {
            var result = false;

            try
            {
                var zoom        = camera.ViewToWorldScale.ToFeet();
                var direction   = RevitUtils.GetRevitXYZ(camera.CameraDirection);
                var upVector    = RevitUtils.GetRevitXYZ(camera.CameraUpVector);
                var viewPoint   = RevitUtils.GetRevitXYZ(camera.CameraViewPoint);
                var orientation = RevitUtils.ConvertBasePoint(ActiveDoc, viewPoint, direction, upVector, true);

                using (var trans = new Transaction(ActiveDoc))
                {
                    trans.Start("Set Orientation");
                    try
                    {
                        bcfView.SetOrientation(orientation);
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.RollBack();
                        var message = ex.Message;
                    }
                }

                var m_xyzTl = bcfView.Origin.Add(bcfView.UpDirection.Multiply(zoom)).Subtract(bcfView.RightDirection.Multiply(zoom));
                var m_xyzBr = bcfView.Origin.Subtract(bcfView.UpDirection.Multiply(zoom)).Add(bcfView.RightDirection.Multiply(zoom));
                BCFUIView.ZoomAndCenterRectangle(m_xyzTl, m_xyzBr);

                result = true;
            }
            catch (Exception ex)
            {
                var message = ex.Message;
            }
            return(result);
        }
示例#4
0
        /// <summary>
        /// External Event Implementation
        /// </summary>
        /// <param name="app"></param>
        public void Execute(UIApplication app)
        {
            try
            {
                UIDocument uidoc      = app.ActiveUIDocument;
                Document   doc        = uidoc.Document;
                var        uniqueView = UserSettings.GetBool("alwaysNewView");

                // IS ORTHOGONAL
                if (v.OrthogonalCamera != null)
                {
                    if (v.OrthogonalCamera.CameraViewPoint == null || v.OrthogonalCamera.CameraUpVector == null || v.OrthogonalCamera.CameraDirection == null)
                    {
                        return;
                    }
                    //type = "OrthogonalCamera";
                    var zoom            = v.OrthogonalCamera.ViewToWorldScale.ToFeet();
                    var cameraDirection = RevitUtils.GetRevitXYZ(v.OrthogonalCamera.CameraDirection);
                    var cameraUpVector  = RevitUtils.GetRevitXYZ(v.OrthogonalCamera.CameraUpVector);
                    var cameraViewPoint = RevitUtils.GetRevitXYZ(v.OrthogonalCamera.CameraViewPoint);
                    var orient3D        = RevitUtils.ConvertBasePoint(doc, cameraViewPoint, cameraDirection, cameraUpVector, true);

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

                            if (orthoView == null || uniqueView)
                            {
                                orthoView      = View3D.CreateIsometric(doc, getFamilyViews(doc).First().Id);
                                orthoView.Name = (uniqueView) ? "BCFortho" + DateTime.Now.ToString("yyyyMMddTHHmmss") : "BCFortho";
                            }
                            else
                            {
                                //reusing an existing view, I net to reset the visibility
                                //placed this here because if set afterwards it doesn't work
                                orthoView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate);
                            }
                            orthoView.SetOrientation(orient3D);
                            trans.Commit();
                        }
                    }
                    uidoc.ActiveView = orthoView;
                    //adjust view rectangle

                    // **** CUSTOM VALUE FOR TEKLA **** //
                    // double x = zoom / 2.5;
                    // **** CUSTOM VALUE FOR TEKLA **** //

                    double x = zoom;
                    //if(MySettings.Get("optTekla")=="1")
                    //    x = zoom / 2.5;

                    //set UI view position and zoom
                    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);
                }
                //perspective
                else if (v.PerspectiveCamera != null)
                {
                    if (v.PerspectiveCamera.CameraViewPoint == null || v.PerspectiveCamera.CameraUpVector == null || v.PerspectiveCamera.CameraDirection == null)
                    {
                        return;
                    }

                    //not used since the fov cannot be changed in Revit
                    var zoom = v.PerspectiveCamera.FieldOfView;
                    //FOV - not used
                    //double z1 = 18 / Math.Tan(zoom / 2 * Math.PI / 180);
                    //double z = 18 / Math.Tan(25 / 2 * Math.PI / 180);
                    //double factor = z1 - z;

                    var cameraDirection = RevitUtils.GetRevitXYZ(v.PerspectiveCamera.CameraDirection);
                    var cameraUpVector  = RevitUtils.GetRevitXYZ(v.PerspectiveCamera.CameraUpVector);
                    var cameraViewPoint = RevitUtils.GetRevitXYZ(v.PerspectiveCamera.CameraViewPoint);
                    var orient3D        = RevitUtils.ConvertBasePoint(doc, cameraViewPoint, cameraDirection, cameraUpVector, true);



                    View3D perspView = null;
                    //try to use an existing 3D view
                    IEnumerable <View3D> viewcollector3D = get3DViews(doc);
                    if (viewcollector3D.Any(o => o.Name == "BCFpersp"))
                    {
                        perspView = viewcollector3D.First(o => o.Name == "BCFpersp");
                    }

                    using (var trans = new Transaction(uidoc.Document))
                    {
                        if (trans.Start("Open perspective view") == TransactionStatus.Started)
                        {
                            if (null == perspView || uniqueView)
                            {
                                perspView      = View3D.CreatePerspective(doc, getFamilyViews(doc).First().Id);
                                perspView.Name = (uniqueView) ? "BCFpersp" + DateTime.Now.ToString("yyyyMMddTHHmmss") : "BCFpersp";
                            }
                            else
                            {
                                //reusing an existing view, I net to reset the visibility
                                //placed this here because if set afterwards it doesn't work
                                perspView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate);
                            }

                            perspView.SetOrientation(orient3D);

                            // turn off the far clip plane
                            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;
                }
                //sheet
                else if (v.SheetCamera != null)
                {
                    IEnumerable <View> viewcollectorSheet = getSheets(doc, v.SheetCamera.SheetID);
                    if (!viewcollectorSheet.Any())
                    {
                        MessageBox.Show("View " + v.SheetCamera.SheetName + " with Id=" + v.SheetCamera.SheetID + " not found.");
                        return;
                    }
                    uidoc.ActiveView = viewcollectorSheet.First();
                    uidoc.RefreshActiveView();

                    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);
                }
                //no view included
                else
                {
                    return;
                }

                if (v.Components == null)
                {
                    return;
                }


                var elementsToSelect = new List <ElementId>();
                var elementsToHide   = new List <ElementId>();
                var elementsToShow   = new List <ElementId>();

                var visibleElems = new FilteredElementCollector(doc, doc.ActiveView.Id)
                                   .WhereElementIsNotElementType()
                                   .WhereElementIsViewIndependent()
                                   .ToElementIds()
                                   .Where(e => doc.GetElement(e).CanBeHidden(doc.ActiveView)); //might affect performance, but it's necessary


                bool canSetVisibility = (v.Components.Visibility != null &&
                                         v.Components.Visibility.DefaultVisibilitySpecified &&
                                         v.Components.Visibility.Exceptions.Any())
                ;
                bool canSetSelection = (v.Components.Selection != null && v.Components.Selection.Any());



                //loop elements
                foreach (var e in visibleElems)
                {
                    var guid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, e));

                    if (canSetVisibility)
                    {
                        if (v.Components.Visibility.DefaultVisibility)
                        {
                            if (v.Components.Visibility.Exceptions.Any(x => x.IfcGuid == guid))
                            {
                                elementsToHide.Add(e);
                            }
                        }
                        else
                        {
                            if (v.Components.Visibility.Exceptions.Any(x => x.IfcGuid == guid))
                            {
                                elementsToShow.Add(e);
                            }
                        }
                    }

                    if (canSetSelection)
                    {
                        if (v.Components.Selection.Any(x => x.IfcGuid == guid))
                        {
                            elementsToSelect.Add(e);
                        }
                    }
                }



                using (var trans = new Transaction(uidoc.Document))
                {
                    if (trans.Start("Apply BCF visibility and selection") == TransactionStatus.Started)
                    {
                        if (elementsToHide.Any())
                        {
                            doc.ActiveView.HideElementsTemporary(elementsToHide);
                        }
                        //there are no items to hide, therefore hide everything and just show the visible ones
                        else if (elementsToShow.Any())
                        {
                            doc.ActiveView.IsolateElementsTemporary(elementsToShow);
                        }

                        if (elementsToSelect.Any())
                        {
                            uidoc.Selection.SetElementIds(elementsToSelect);
                        }
                    }
                    trans.Commit();
                }


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