Ejemplo n.º 1
0
        public static void AutoPutSeat(this Document doc, PickedBox box, PositionRequest request, List <SeatBatch> batches)
        {
            Doc         = doc;
            Request     = request;
            PickBox     = box.ToBoundingBoxXYZ();
            PickEdges   = PickBox.GetPlaneEdges();
            FillPattern = doc.GetFirstFillPattern();
            RefSeat     = doc.Get90Seat();

            if (RefSeat == null)
            {
                MessageBox.Show("The document hasn't any 90° seat, please put one!");
                return;
            }

            var floorRooms = GetRoomListOnFloor();
            var sb         = new StringBuilder();

            foreach (var floorRoom in floorRooms)
            {
                sb.AppendLine(floorRoom.Name);
            }

            MessageBox.Show(sb.ToString());

            var seatInfos = GetSeatInfosOnFloor(floorRooms, batches);

            PutSeatList(doc, seatInfos);

            if (!ConformPasswayWidth())
            {
                MessageBox.Show("The passsway width is qualified!");
            }
        }
Ejemplo n.º 2
0
        public PickedBox2(PickedBox picked, bool fixRange)
        {
            double minX = picked.Min.X;
            double minY = picked.Min.Y;
            double minZ = picked.Min.Z;

            double maxX = picked.Max.X;
            double maxY = picked.Max.Y;
            double maxZ = picked.Max.Z;

            if (picked.Min.X > picked.Max.X)
            {
                maxX = picked.Min.X;
                minX = picked.Max.X;
            }

            if (picked.Min.Y > picked.Max.Y)
            {
                maxY = picked.Min.Y;
                minY = picked.Max.Y;
            }

            if (fixRange)
            {
                minZ = Double.MinValue;
                maxZ = Double.MaxValue;
            }

            Min = new XYZ(minX, minY, minZ);
            Max = new XYZ(maxX, maxY, maxZ);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the space edge set.
        /// </summary>
        /// <param name="box"></param>
        /// <returns></returns>
        public static List <Line> GetSpaceEdges(this PickedBox box)
        {
            var vectors = box.GetSpaceVectors();
            var p1      = vectors[0];
            var p2      = vectors[1];
            var p3      = vectors[2];
            var p4      = vectors[3];
            var p5      = vectors[4];
            var p6      = vectors[5];
            var p7      = vectors[6];
            var p8      = vectors[7];
            var p12     = Line.CreateBound(p1, p2);
            var p14     = Line.CreateBound(p1, p4);
            var p15     = Line.CreateBound(p1, p5);
            var p23     = Line.CreateBound(p2, p3);
            var p24     = Line.CreateBound(p2, p4);
            var p34     = Line.CreateBound(p3, p4);
            var p37     = Line.CreateBound(p3, p7);
            var p48     = Line.CreateBound(p4, p8);
            var p56     = Line.CreateBound(p5, p6);
            var p58     = Line.CreateBound(p5, p8);
            var p67     = Line.CreateBound(p6, p7);
            var p78     = Line.CreateBound(p7, p8);

            return(new List <Line> {
                p12, p14, p15, p23, p24, p34, p37, p48, p56, p58, p67, p78
            });
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Converts to bounding box.
        /// </summary>
        /// <param name="box"></param>
        /// <returns></returns>
        public static BoundingBoxXYZ ToBoundingBoxXYZ(this PickedBox box)
        {
            if (box is null)
            {
                throw new ArgumentNullException(nameof(box));
            }

            var minPt = box.Min;

            var maxPt = box.Max;

            var minX = Min(minPt.X, maxPt.X);

            var minY = Min(minPt.Y, maxPt.Y);

            var minZ = Min(minPt.Z, maxPt.Z);

            var maxX = Max(minPt.X, maxPt.X);

            var maxY = Max(minPt.Y, maxPt.Y);

            var maxZ = Max(minPt.Z, maxPt.Z);

            return(new BoundingBoxXYZ
            {
                Min = new XYZ(minX, minY, minZ),

                Max = new XYZ(maxX, maxY, maxZ)
            });
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the point and the plane about space direction relationship.
        /// </summary>
        /// <param name="pt"></param>
        /// <param name="box"></param>
        /// <returns></returns>
        public static GeometryPosition GetSpacePosition(this XYZ pt, PickedBox box)
        {
            GeometryPosition result;
            var pt1      = pt.GetRoundPoint();
            var xs       = new[] { NumberUtil.GetRound(box.Min.X), NumberUtil.GetRound(box.Max.X) };
            var ys       = new[] { NumberUtil.GetRound(box.Min.Y), NumberUtil.GetRound(box.Max.Y) };
            var zs       = new[] { NumberUtil.GetRound(box.Min.Z), NumberUtil.GetRound(box.Max.Z) };
            var minPt    = new XYZ(xs.Min(), ys.Min(), zs.Min());
            var maxPt    = new XYZ(xs.Max(), ys.Max(), zs.Max());
            var position = pt.GetPlanePosition(box);

            switch (position)
            {
            case GeometryPosition.Other when pt1.Z <minPt.Z:
                                                case GeometryPosition.Other when pt1.Z> maxPt.Z:
                result = GeometryPosition.Other;
                break;

            case GeometryPosition.Edge when zs.Contains(pt1.Z):
                result = GeometryPosition.Edge;

                break;

            default:
                result = GeometryPosition.Inner;
                break;
            }

            return(result);
        }
Ejemplo n.º 6
0
        public View Create3DView(Document doc, PickedBox pickedbox)
        {
            var viewfamilytypes = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType))
                                  .Cast <ViewFamilyType>().Where(m => m.ViewFamily == ViewFamily.ThreeDimensional);
            var targetviewfamilytypeId = viewfamilytypes.First().Id;
            var result = View3D.CreateIsometric(doc, targetviewfamilytypeId);

            return(result);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the box's plane 4 vectors.
        /// </summary>
        /// <param name="box"></param>
        /// <returns></returns>
        public static List <XYZ> GetPlaneVectors(this PickedBox box)
        {
            var p1 = box.Min;
            var p2 = new XYZ(box.Max.X, box.Min.Y, p1.Z);
            var p3 = new XYZ(box.Max.X, box.Max.Y, p1.Z);
            var p4 = new XYZ(p1.X, box.Max.Y, p1.Z);

            return(new List <XYZ> {
                p1, p2, p3, p4
            });
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the box's space 8 vectors.
        /// </summary>
        /// <param name="box"></param>
        /// <returns></returns>
        public static List <XYZ> GetSpaceVectors(this PickedBox box)
        {
            var p1 = box.Min;
            var p2 = new XYZ(box.Max.X, box.Min.Y, p1.Z);
            var p3 = new XYZ(box.Max.X, box.Max.Y, p1.Z);
            var p4 = new XYZ(p1.X, box.Max.Y, p1.Z);
            var p5 = new XYZ(p1.X, p1.Y, box.Max.Z);
            var p6 = new XYZ(box.Max.X, p1.Y, box.Max.Z);
            var p7 = new XYZ(p1.X, box.Max.Y, box.Max.Z);
            var p8 = box.Max;

            return(new List <XYZ> {
                p1, p2, p3, p4, p5, p6, p7, p8
            });
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets the plane edge set and z axis value equals no zero.
        /// </summary>
        /// <param name="box"></param>
        /// <returns></returns>
        public static List <Line> GetPlaneEdges(this PickedBox box)
        {
            var vectors = box.GetPlaneVectors();
            var p1      = vectors[0];
            var p2      = vectors[1];
            var p3      = vectors[2];
            var p4      = vectors[3];
            var p12     = Line.CreateBound(p1, p2);
            var p23     = Line.CreateBound(p2, p3);
            var p34     = Line.CreateBound(p3, p4);
            var p41     = Line.CreateBound(p4, p1);

            return(new List <Line> {
                p12, p23, p34, p41
            });
        }
Ejemplo n.º 10
0
        //平面内判断一个点是否在一个矩形框(PickBox)内.
        private bool IsPointInPickbox(PickedBox pickbox, XYZ xyz, View view)
        {
            double x = Math.Round(xyz.X, 3);
            double y = Math.Round(xyz.Y, 3);
            double z = Math.Round(xyz.Z, 3);

            double xmin = Math.Round(pickbox.Min.X, 3);
            double xmax = Math.Round(pickbox.Max.X, 3);
            double ymin = Math.Round(pickbox.Min.Y, 3);
            double ymax = Math.Round(pickbox.Max.Y, 3);
            double zmin = Math.Round(pickbox.Min.Z, 3);
            double zmax = Math.Round(pickbox.Max.Z, 3);

            double tmp = 0;

            if (xmin > xmax)
            {
                tmp = xmin; xmin = xmax; xmax = tmp;
            }
            if (ymin > ymax)
            {
                tmp = ymin; ymin = ymax; ymax = tmp;
            }
            if (zmin > zmax)
            {
                tmp = zmin; zmin = zmax; zmax = tmp;
            }

            bool boolx = (x >= xmin && x <= xmax);
            bool booly = (y >= ymin && y <= ymax);
            bool boolz = (z >= zmin && z <= zmax);

            //平面图特殊情况特殊处理.
            if (view.ViewDirection.X == 0 && view.ViewDirection.Y == 0 && boolx && booly)
            {
                return(true);
            }

            if (boolx && booly && boolz)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private bool IsIntersect(Viewport viewport, PickedBox pickedBox, out double intersectArea)
        {
            var     plane             = CreatePlane(XYZ.BasisZ, XYZ.Zero);
            Outline outline           = viewport.GetBoxOutline();
            var     viewportRectangle = GetRectangle(outline, plane);

            Outline pickedOutline   = new Outline(pickedBox.Min, pickedBox.Max);
            var     pickedRectangle = GetRectangle(pickedOutline, plane);

            var intersectRectangle = System.Drawing.Rectangle.Intersect(viewportRectangle, pickedRectangle);

            if (intersectRectangle.IsEmpty)
            {
                intersectArea = double.NaN;
                return(false);
            }

            intersectArea = intersectRectangle.Width * intersectRectangle.Height;
            return(true);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Gets the point and the plane about plane direction relationship.
        /// </summary>
        /// <param name="pt"></param>
        /// <param name="box"></param>
        /// <returns></returns>
        public static GeometryPosition GetPlanePosition(this XYZ pt, PickedBox box)
        {
            GeometryPosition result;
            var pointl = pt.GetRoundPoint();
            var xs     = new[] { NumberUtil.GetRound(box.Min.X), NumberUtil.GetRound(box.Max.X) };
            var ys     = new[] { NumberUtil.GetRound(box.Min.Y), NumberUtil.GetRound(box.Max.Y) };
            var minPt  = new XYZ(xs.Min(), ys.Min(), 0);
            var maxPt  = new XYZ(xs.Max(), ys.Max(), 0);

            if (pointl.X < minPt.X)
            {
                result = GeometryPosition.Other;
            }
            else if (pointl.Y < minPt.Y)
            {
                result = GeometryPosition.Other;
            }
            else if (pointl.X > maxPt.X)
            {
                result = GeometryPosition.Other;
            }
            else if (pointl.Y > maxPt.Y)
            {
                result = GeometryPosition.Other;
            }
            else if (xs.Contains(pointl.X) && ys.Contains(pointl.Y))
            {
                result = GeometryPosition.Edge;
            }
            else
            {
                result = GeometryPosition.Inner;
            }

            return(result);
        }
Ejemplo n.º 13
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = commandData.Application.ActiveUIDocument.Document;

            //get a PickBox
            PickedBox pickbox = uidoc.Selection.PickBox(PickBoxStyle.Enclosing, "框选要关闭/开启的轴号");

            //get a activeview
            View activeview = uidoc.ActiveView;

            //get Grid by visable
            FilteredElementCollector gridcollector = new FilteredElementCollector(doc);

            gridcollector.OfClass(typeof(Grid)).WhereElementIsNotElementType().WhereElementIsViewIndependent();
            IEnumerable <Grid> gridenumerable = from ele in gridcollector
                                                let grid = ele as Grid
                                                           where grid.CanBeVisibleInView(activeview)
                                                           select grid;
            List <Grid> grids = gridenumerable.ToList();
            //get level by visable
            FilteredElementCollector levelcollector = new FilteredElementCollector(doc);

            levelcollector.OfClass(typeof(Level)).WhereElementIsNotElementType().WhereElementIsViewIndependent();
            IEnumerable <Level> levelenumerable = from ele in levelcollector
                                                  let level = ele as Level
                                                              where level.CanBeVisibleInView(activeview)
                                                              select level;
            List <Level> levels = levelenumerable.ToList();



            //get grid/level.endpoint & start  transaction
            //Determine which point is in the pickbox
            using (Transaction transaction = new Transaction(doc))
            {
                transaction.Start("批量开关轴号");
                foreach (Grid grid in grids)
                {
                    IList <Curve> curves = grid.GetCurvesInView(DatumExtentType.ViewSpecific, activeview);
                    foreach (Curve curve in curves)
                    {
                        XYZ start = curve.GetEndPoint(0);
                        XYZ end   = curve.GetEndPoint(1);
                        if (IsPointInPickbox(pickbox, start, activeview))
                        {
                            ChangeBubbleVisible(grid, DatumEnds.End0, activeview);
                        }

                        if (IsPointInPickbox(pickbox, end, activeview))
                        {
                            ChangeBubbleVisible(grid, DatumEnds.End1, activeview);
                        }
                    }
                }

                foreach (Level level in levels)
                {
                    IList <Curve> curves = level.GetCurvesInView(DatumExtentType.ViewSpecific, activeview);
                    foreach (Curve curve in curves)
                    {
                        XYZ start = curve.GetEndPoint(0);
                        XYZ end   = curve.GetEndPoint(1);
                        if (IsPointInPickbox(pickbox, start, activeview))
                        {
                            ChangeBubbleVisible(level, DatumEnds.End0, activeview);
                        }

                        if (IsPointInPickbox(pickbox, end, activeview))
                        {
                            ChangeBubbleVisible(level, DatumEnds.End1, activeview);
                        }
                    }
                }



                uidoc.RefreshActiveView();
                transaction.Commit();
            }
            return(Result.Succeeded);
        }
Ejemplo n.º 14
0
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            try
            {
                UIApplication uiapp = commandData.Application;
                UIDocument    uidoc = uiapp.ActiveUIDocument;
                Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
                Document  doc       = uidoc.Document;
                Selection selection = uidoc.Selection;
                Autodesk.Revit.DB.View activeView = doc.ActiveView;
                ElementId levelId = null;

                // 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 tx = new Transaction(doc, "Create view"))
                {
                    //set the name of the view
                    String viewNameToCreate = "OAT 3D Section";

                    //start transaction
                    tx.Start();

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

                    // Set the name of the view
                    view.Name = makeViewNameUnique(doc, viewNameToCreate);

                    // Set the name of the transaction
                    tx.SetName("Create view " + view.Name);

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

                    // Determin the height of the bounding box
                    double zOffset = 0;

                    // Get the current level Id
                    Level     _curLevel = null;
                    Parameter level     = activeView.LookupParameter("Associated Level");
                    FilteredElementCollector lvlCollector  = new FilteredElementCollector(doc);
                    ICollection <Element>    lvlCollection = lvlCollector.OfClass(typeof(Level)).ToElements();
                    foreach (Element lev in lvlCollection)
                    {
                        Level lvl = lev as Level;
                        if (lvl.Name == level.AsString())
                        {
                            levelId   = lvl.Id;
                            _curLevel = lvl;
                        }
                    }

                    // Get the selection box
                    PickedBox pickBox = uidoc.Selection.PickBox(PickBoxStyle.Directional, "Click and drag to define the box.");

                    // Get the two user selected points on screen
                    XYZ xyzFirst = pickBox.Min;
                    XYZ xyzThird = pickBox.Max;

                    // Set zOffset to 10'
                    zOffset = _curLevel.Elevation + 10;

                    // Build the box from the selected points
                    XYZ xyxSecond = new XYZ(xyzThird.X, xyzFirst.Y, zOffset);
                    XYZ xyzFourth = new XYZ(xyzFirst.X, xyzThird.Y, zOffset);

                    boundingBoxXYZ.Min = new XYZ(xyzFirst.X, xyzThird.Y, _curLevel.Elevation);
                    boundingBoxXYZ.Max = new XYZ(xyzThird.X, xyzFirst.Y, zOffset);
                    view.SetSectionBox(boundingBoxXYZ);

                    //End transaction
                    tx.Commit();
                    uidoc.ActiveView = view;
                }
            }

            catch (Exception e)
            {
                message = e.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
            return(Result.Succeeded);
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
0
        //private void Application_DialogBoxShowing(object sender, Autodesk.Revit.UI.Events.DialogBoxShowingEventArgs e)
        //{
        //  //  TaskDialog.Show("Information", e.HelpId.ToString());
        //   // Console.WriteLine("Information", e.HelpId.ToString());

        //    TaskDialogShowingEventArgs e2   = e as TaskDialogShowingEventArgs;
        //    string s = string.Empty;

        //    if (null != e2)
        //    {
        //        s = string.Format(
        //          ", dialog id {0}, message '{1}'",
        //          e2.DialogId, e2.Message);

        //        bool isConfirm = e2.DialogId.Equals(
        //          "TaskDialog_Save_File");

        //        if (isConfirm)
        //        {
        //            //e2.OverrideResult(
        //            //  (int)WinForms.DialogResult.Yes);

        //            s += ", auto-confirmed.";
        //        }
        //    }


        //}
        public void PatTry(ExternalCommandData revit)
        {
            Document doc = doc = revit.Application.ActiveUIDocument.Document;

            Selection        s        = revit.Application.ActiveUIDocument.Selection;
            List <Reference> ref_elem = s.PickObjects(ObjectType.Element, "Select Element").Cast <Reference>().ToList();

            PickedBox boundary = s.PickBox(PickBoxStyle.Crossing, "Select boundary");

            if (ref_elem.Count == 0 || boundary == null)
            {
                return;
            }
            double tile_width = Line.CreateBound(boundary.Min, new XYZ(boundary.Max.X, boundary.Min.Y, boundary.Min.Z)).Length;

            double tile_height = Line.CreateBound(boundary.Min, new XYZ(boundary.Min.X, boundary.Max.Y, boundary.Min.Z)).Length;

            ref_elem.ToList().ForEach((Refr) =>
            {
                Element deltail_line = doc.GetElement(Refr);

                if ((deltail_line as DetailCurve) == null)
                {
                    return;
                }

                DetailCurve elem_curve = (deltail_line as DetailCurve);

                XYZ origin = elem_curve.GeometryCurve.GetEndPoint(0);
                XYZ dir    = (elem_curve.GeometryCurve as Line).Direction;
                double ang = dir.AngleTo(new XYZ(1, 0, 0));

                if (ang > 1.5708)           //> 90 deg
                {
                    ang = 3.14159 - 1.5708; //180-90
                }
                List <Curve> curve_list = new List <Curve>();
                CurveArray cr           = new CurveArray();
                for (int x = 1; x <= 100; x++)
                {
                    XYZ base_grid_pt = new XYZ(origin.X + tile_width * x, origin.Y, origin.Z);
                    for (int y = 1; y <= 100; y++)
                    {
                        XYZ grid_pt = new XYZ(origin.X + tile_width * x, origin.Y + tile_height * y, origin.Z);
                        cr.Append(Line.CreateBound(base_grid_pt, grid_pt) as Curve);
                    }
                }
                using (Transaction t = new Transaction(doc, "Draw Grid"))
                {
                    try
                    {
                        t.Start();
                        doc.Create.NewDetailCurveArray(doc.ActiveView, cr);
                        t.Commit();
                    }
                    catch (Exception)
                    {
                        t.RollBack();
                    }
                }
            });
            TaskDialog.Show("Instruction", "Process Complete........#############");
            TaskDialog.Show("Instruction", "Process Complete........#############");
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
0
 public PickedBox2(PickedBox picked) : this(picked, false)
 {
 }
        private static void CropView(View view, PickedBox pickedBox, Document doc, string trName)
        {
            var cropRegionShapeManager = view.GetCropRegionShapeManager();

            var pt1   = pickedBox.Min;
            var pt3   = pickedBox.Max;
            var plane = CreatePlane(view.UpDirection, pt3);
            var pt2   = plane.ProjectOnto(pt1);

            plane = CreatePlane(view.UpDirection, pt1);
            var pt4 = plane.ProjectOnto(pt3);

            var line1 = TryCreateLine(pt1, pt2);
            var line2 = TryCreateLine(pt2, pt3);
            var line3 = TryCreateLine(pt3, pt4);
            var line4 = TryCreateLine(pt4, pt1);

            if (line1 == null || line2 == null || line3 == null || line4 == null)
            {
                // Не удалось получить валидную прямоугольную область. Попробуйте еще раз
                MessageBox.Show(Language.GetItem("h6"));
                return;
            }

            var curveLoop = CurveLoop.Create(new List <Curve>
            {
                line1, line2, line3, line4
            });

            if (curveLoop.IsRectangular(CreatePlane(view.ViewDirection, view.Origin)))
            {
                using (var transactionGroup = new TransactionGroup(doc))
                {
                    transactionGroup.Start();

                    using (var tr = new Transaction(doc, trName))
                    {
                        tr.Start();
                        if (!view.CropBoxActive)
                        {
                            view.CropBoxActive  = true;
                            view.CropBoxVisible = false;
                        }

                        cropRegionShapeManager.SetCropShape(curveLoop);

                        tr.Commit();
                    }

                    // reset crop
                    using (var tr = new Transaction(doc, trName))
                    {
                        tr.Start();

                        cropRegionShapeManager.RemoveCropRegionShape();

                        tr.Commit();
                    }

                    transactionGroup.Assimilate();
                }
            }
            else
            {
                // Не удалось получить валидную прямоугольную область. Попробуйте еще раз
                MessageBox.Show(Language.GetItem("h6"));
            }
        }