コード例 #1
0
        /// <summary>
        /// Sets a callback that applies a zoom to the current view.
        /// </summary>
        /// <param name="app">The current UI application.</param>
        /// <param name="viewId">The view ID for the view to be zoomed.</param>
        /// <param name="zoom">The zoom in decimal precision.</param>
        public static void SetPendingZoomChangedCallback(UIApplication app, ElementId viewId, decimal zoom)
        {
            void Callback(object sender, IdlingEventArgs args)
            {
                StatusBarService.SetStatusText("Zooming to scale '" + zoom + "' ...");
                UIView currentView = app.ActiveUIDocument.GetOpenUIViews().First();

                if (currentView.ViewId != viewId)
                {
                    return;
                }

                UIDocument uiDoc      = app.ActiveUIDocument;
                View       activeView = uiDoc.ActiveView;

                var zoomCorners = currentView.GetZoomCorners();
                XYZ bottomLeft  = zoomCorners[0];
                XYZ topRight    = zoomCorners[1];

                var(currentHeight, currentWidth) =
                    RevitUtils.ConvertToViewBoxValues(topRight, bottomLeft, activeView.RightDirection);

                var zoomedViewBoxHeight = Convert.ToDouble(zoom).ToInternalRevitUnit();
                var zoomedViewBoxWidth  = zoomedViewBoxHeight * currentWidth / currentHeight;

                XYZ newTopRight = activeView.Origin
                                  .Add(activeView.UpDirection.Multiply(zoomedViewBoxHeight / 2))
                                  .Add(activeView.RightDirection.Multiply(zoomedViewBoxWidth / 2));
                XYZ newBottomLeft = activeView.Origin
                                    .Subtract(activeView.UpDirection.Multiply(zoomedViewBoxHeight / 2))
                                    .Subtract(activeView.RightDirection.Multiply(zoomedViewBoxWidth / 2));

                Log.Information("Zoom to {topRight} | {bottomLeft} ...", newTopRight.ToString(), newBottomLeft.ToString());
                currentView.ZoomAndCenterRectangle(newTopRight, newBottomLeft);

                StatusBarService.ResetStatusBarText();
                Log.Information("Finished applying zoom for orthogonal view.");
                app.Idling -= Callback;
            }

            Log.Information("Append zoom callback for orthogonal view to idle state of Revit application ...");
            app.Idling += Callback;
        }
コード例 #2
0
        private void ShowBCfViewpointInternal(UIApplication app)
        {
            UIDocument uiDocument = app.ActiveUIDocument;
            var        hasCamera  = _bcfViewpoint.GetCamera().Match(
                camera =>
            {
                Log.Information("Found camera type {t}, opening related OpenProject view ...", camera.Type.ToString());
                View3D openProjectView = uiDocument.Document.GetOpenProjectView(camera.Type);

                ResetView(uiDocument, openProjectView);
                Log.Information("Reset view '{v}'.", openProjectView.Name);
                ApplyViewOrientationAndVisibility(uiDocument, openProjectView, camera);
                Log.Information("Applied view orientation and visibility in '{v}'.", openProjectView.Name);
                ApplyClippingPlanes(uiDocument, openProjectView);
                Log.Information("Applied view point clipping planes in '{v}'.", openProjectView.Name);

                if (!uiDocument.ActiveView.Id.Equals(openProjectView.Id))
                {
                    Log.Information("Setting view '{t}' as active view ...", openProjectView.Name);
                    uiDocument.ActiveView = openProjectView;
                }

                uiDocument.RefreshActiveView();
                Log.Information("Refreshed active view.");
                StatusBarService.ResetStatusBarText();

                ZoomIfNeeded(app, camera, uiDocument.ActiveView.Id);
                Log.Information("Finished loading BCF viewpoint.");

                return(true);
            },
                () => false);

            if (!hasCamera)
            {
                Log.Error("BCF viewpoint has no camera information. Aborting ...");
            }
        }