public Boolean BoundingBox_Checker(BoundingBoxXYZ item, BoundingBoxXYZ View)
        {
            try
            {
                //check whether item MIN x,y,z values are bigger then view X,y,z values
                Boolean MIN = false;
                if (item.Min.X>View.Min.X && item.Min.Y>View.Min.Y &&item.Min.Z>View.Min.Z)
                {
                    MIN = true;
                }
                //check whether item max x,y,z values are smaller then view x,y,z values
                Boolean Max = false;
                if (item.Max.X<View.Max.X&&item.Max.Y<View.Max.Y&&item.Max.Z<View.Max.Z)
                {
                    Max = true;
                }

                if (MIN==true && Max ==true)
                {
                    return true;
                }
                else
                {
                    return false;
                }

            }
            catch (Exception)
            {
                return false;
                throw;
            }
        }
示例#2
0
文件: BoundingBox.cs 项目: AMEE/revit
        /// <summary>
        /// The default constructor
        /// </summary>
        /// <param name="boundBoxXYZ">The reference of the application in revit</param>
        public BoundingBox(BoundingBoxXYZ boundBoxXYZ)
        {
            this.Min = boundBoxXYZ.Min;
            this.Max = boundBoxXYZ.Max;

            GetCorners();
        }
示例#3
0
        /// <summary>
        /// Return a string for a 3D bounding box
        /// formatted to two decimal places.
        /// </summary>
        public static string BoundingBoxString(
            BoundingBoxXYZ b)
        {
            //XYZ d = b.Max - b.Min;

              return string.Format( "({0},{1})",
            PointString( b.Min ),
            PointString( b.Max ) );
        }
 public JtBoundingBoxXyz( BoundingBoxXYZ bb )
 {
   xmin = bb.Min.X;
   ymin = bb.Min.Y;
   zmin = bb.Min.Z;
   xmax = bb.Max.X;
   ymax = bb.Max.Y;
   zmax = bb.Max.Z;
 }
示例#5
0
        /// <summary>
        /// construct function.
        /// </summary>
        /// <param name="door">of which geometry data is wanted.</param>
        public DoorGeometry(Autodesk.Revit.DB.Element door)
        {
            m_options                              = new Options();
             m_options.View                         = GetPlanform2DView(door);
             m_options.ComputeReferences            = false;
             Autodesk.Revit.DB.GeometryElement geoEle = door.get_Geometry(m_options);
             AddGeometryElement(geoEle);

             m_bbox = door.get_BoundingBox(m_options.View);
        }
示例#6
0
        /// <summary>
        /// Private constructor
        /// </summary>
        private SectionView( BoundingBoxXYZ bbox )
        {
            TransactionManager.Instance.EnsureInTransaction(Document);

            ViewSection vd = CreateSectionView(bbox);

            InternalSetSectionView(vd);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.CleanupAndSetElementForTrace(Document, this.InternalElement);
        }
示例#7
0
        /// <summary>
        /// create 3D and 2D data of given GeometryElement
        /// </summary>
        /// <param name="elem"></param>
        /// <param name="detail"></param>
        /// <param name="currentView"></param>
        public GeometryData(Element elem, DetailLevels detail, View currentView)
        {
            Options opt = Command.CommandData.Application.Application.Create.NewGeometryOptions();
            opt.DetailLevel = detail;
            opt.ComputeReferences = false;
            GeometryElement geoElement = elem.get_Geometry(opt);

            Autodesk.Revit.DB.XYZ xyz = new Autodesk.Revit.DB.XYZ (0, 0, 0);
            Transform transform = Transform.get_Translation(xyz);
            AddGeoElement(geoElement, transform);

            m_bbox = elem.get_BoundingBox(currentView);
        }
示例#8
0
        /// <summary>
        /// Convert a Revit BoundingBox to a ProtoGeometry BoundingBox
        /// </summary>
        /// <returns></returns>
        public static Autodesk.Revit.DB.BoundingBoxXYZ ToRevitType(this Autodesk.DesignScript.Geometry.BoundingBox bb)
        {
            var rbb = new BoundingBoxXYZ();
            rbb.Enabled = true;

            // placeholder until we can get coordinate system from bounding box
            rbb.Transform = Transform.Identity;

            rbb.Max = bb.MaxPoint.ToXyz();
            rbb.Min = bb.MinPoint.ToXyz();

            return rbb;
        }
示例#9
0
        public override Value Evaluate(FSharpList<Value> args)
        {
            BoundingBoxXYZ bbox = new BoundingBoxXYZ();

            Transform t = (Transform)((Value.Container)args[0]).Item;
            double x = (double)((Value.Number)args[1]).Item;
            double y = (double)((Value.Number)args[2]).Item;
            double z = (double)((Value.Number)args[3]).Item;

            bbox.Transform = t;
            bbox.Min = new XYZ(0, 0, 0);
            bbox.Max = new XYZ(x, y, z);
            return Value.NewContainer(bbox);
        }
        //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);
        }
示例#11
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem != null || listBox1.SelectedItem.ToString() != "You have not selected any Elements")
            {
                Document  linkDoc = findID.linkedDocument;
                ElementId id      = listBox1.SelectedItem as ElementId;
                var       list    = new List <ElementId>();
                list.Add(id);

                Element element = new FilteredElementCollector(linkDoc, list).WhereElementIsNotElementType().ElementAt(0);

                BoundingBoxXYZ boundingBoxXYZ = element.get_BoundingBox(null);
                SetSectionBox(boundingBoxXYZ, true);
            }
        }
示例#12
0
文件: View.cs 项目: l2obin/Dynamo
        private static ViewSection CreateSectionView(BoundingBoxXYZ bbox)
        {
            //http://adndevblog.typepad.com/aec/2012/05/viewplancreate-method.html

            IEnumerable <ViewFamilyType> viewFamilyTypes = from elem in new
                                                           FilteredElementCollector(dynRevitSettings.Doc.Document).OfClass(typeof(ViewFamilyType))
                                                           let type = elem as ViewFamilyType
                                                                      where type.ViewFamily == ViewFamily.Section
                                                                      select type;

            //create a new view
            ViewSection view = ViewSection.CreateSection(dynRevitSettings.Doc.Document, viewFamilyTypes.First().Id, bbox);

            return(view);
        }
示例#13
0
        /// <summary>
        /// Gets the box's space 8 vectors.
        /// </summary>
        /// <param name="box"></param>
        /// <returns></returns>
        public static List <XYZ> GetSpaceVectors(this BoundingBoxXYZ 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
            });
        }
        public static Autodesk.Revit.DB.BoundingBoxXYZ ToRevitBoundingBox(
            Autodesk.DesignScript.Geometry.CoordinateSystem cs,
            Autodesk.DesignScript.Geometry.Point minPoint,
            Autodesk.DesignScript.Geometry.Point maxPoint, bool convertUnits = true)
        {
            var rbb = new BoundingBoxXYZ();
            rbb.Enabled = true;

            rbb.Transform = cs.ToTransform(convertUnits);

            rbb.Max = maxPoint.ToXyz(convertUnits);
            rbb.Min = minPoint.ToXyz(convertUnits);

            return rbb;
        }
示例#15
0
        public static Polygon ConvertStringToPolygon(string bbString)
        {
            BoundingBoxXYZ bb = new BoundingBoxXYZ();

            string[] ss = bbString.Split(';');
            ss[0]             = ss[0].Substring(1, ss[0].Length - 1);
            ss[ss.Length - 1] = ss[ss.Length - 1].Substring(0, ss[ss.Length - 1].Length - 1);
            List <XYZ> points = new List <XYZ>();

            foreach (string s in ss)
            {
                points.Add(ConvertStringToXYZ(s));
            }
            return(new Polygon(points));
        }
示例#16
0
        /// <summary>
        /// Constructor, Construct a new object with an element's geometry Solid,
        /// and its corresponding bounding box.
        /// </summary>
        /// <param name="solid">Element's geometry Solid</param>
        /// <param name="box">Element's geometry bounding box</param>
        public ElementGeometry(Solid solid, BoundingBoxXYZ box)
        {
            m_solid   = solid;
            m_bBoxMin = box.Min;
            m_bBoxMax = box.Max;
            m_isDirty = true;

            // Initialize edge binding
            m_edgeBindinDic = new Dictionary <Edge, EdgeBinding>();
            foreach (Edge edge in m_solid.Edges)
            {
                EdgeBinding edgeBingding = new EdgeBinding(edge);
                m_edgeBindinDic.Add(edge, edgeBingding);
            }
        }
示例#17
0
        /// <summary>
        /// create 3D and 2D data of given GeometryElement
        /// </summary>
        /// <param name="elem">of which geometry data be gotten</param>
        /// <param name="currentView">current view of Revit</param>
        public GeometryData(Element elem, View currentView)
        {
            Options opt = Command.CommandData.Application.Application.Create.NewGeometryOptions();

            opt.View = currentView;
            opt.ComputeReferences = false;
            GeometryElement geoElement = elem.get_Geometry(opt);

            Autodesk.Revit.DB.XYZ xyz       = new Autodesk.Revit.DB.XYZ(0, 0, 0);
            Transform             transform = Transform.CreateTranslation(xyz);

            AddGeoElement(geoElement, transform);

            m_bbox = elem.get_BoundingBox(currentView);
        }
示例#18
0
        bool ContainsRoom(Element scopeBox, SpatialElement room)
        {
            BoundingBoxXYZ boundingBox = scopeBox.get_BoundingBox(room.Document.ActiveView);
            XYZ            min         = boundingBox.Min;
            XYZ            max         = boundingBox.Max;
            XYZ            rmPnt       = ((LocationPoint)room.Location).Point;

            if (rmPnt.X >= min.X && rmPnt.X <= max.X &&
                rmPnt.Y >= min.Y && rmPnt.Y <= max.Y &&
                rmPnt.Z >= min.Z && rmPnt.Z <= max.Z)
            {
                return(true);
            }
            return(false);
        }
示例#19
0
        /// <summary>
        /// Create a sheet to show the schedule.
        /// </summary>
        /// <param name="document">DBDocument of revit file.</param>
        /// <param name="schedule">View schedule which will be shown on sheet.</param>
        private void AddScheduleToNewSheet(Document document, ViewSchedule schedule)
        {
            //Create a filter to get all the title block types.
            FilteredElementCollector collector = new FilteredElementCollector(document);

            collector.OfCategory(BuiltInCategory.OST_TitleBlocks);
            collector.WhereElementIsElementType();

            Transaction t = new Transaction(document, "Create and populate sheet");

            t.Start();

            //Get ElementId of first title block type.
            ElementId titleBlockId = collector.FirstElementId();

            //Create sheet by gotten title block type.
            ViewSheet newSheet = ViewSheet.Create(document, titleBlockId);

            newSheet.Name = "Sheet for " + schedule.Name;

            document.Regenerate();

            //Declare a XYZ to be used as the upperLeft point of schedule sheet instance to be created.
            XYZ upperLeft = new XYZ();

            //If there is an existing title block.
            if (titleBlockId != ElementId.InvalidElementId)
            {
                //Find titleblock of the newly created sheet.
                collector = new FilteredElementCollector(document);
                collector.OfCategory(BuiltInCategory.OST_TitleBlocks);
                collector.OwnedByView(newSheet.Id);
                Element titleBlock = collector.FirstElement();

                //Get bounding box of the title block.
                BoundingBoxXYZ bbox = titleBlock.get_BoundingBox(newSheet);

                //Get upperLeft point of the bounding box.
                upperLeft = new XYZ(bbox.Min.X, bbox.Max.Y, bbox.Min.Z);
                //Move the point to the postion that is 2 inches right and 2 inches down from the original upperLeft point.
                upperLeft = upperLeft + new XYZ(2.0 / 12.0, -2.0 / 12.0, 0);
            }

            //Create a new schedule sheet instance that makes the sheet to show the data of wall view schedule at upperLeft point.
            ScheduleSheetInstance placedInstance = ScheduleSheetInstance.Create(document, newSheet.Id, schedule.Id, upperLeft);

            t.Commit();
        }
示例#20
0
        /// <summary>
        /// Create an element based Tag
        /// </summary>
        /// <param name="element">Element to tag</param>
        /// <param name="horizontal">Horizontal alignment</param>
        /// <param name="addLeader">Add a leader</param>
        /// <returns></returns>
        public static Tag ByElement(Element element, bool horizontal, bool addLeader)
        {
            Autodesk.Revit.DB.Document       document    = DocumentManager.Instance.CurrentDBDocument;
            Autodesk.Revit.DB.XYZ            point       = null;
            Autodesk.Revit.DB.TagMode        tagMode     = TagMode.TM_ADDBY_CATEGORY;
            Autodesk.Revit.DB.TagOrientation orientation = (horizontal)? TagOrientation.Horizontal : TagOrientation.Vertical;

            if (document.ActiveView.ViewType != ViewType.FloorPlan &&
                document.ActiveView.ViewType != ViewType.EngineeringPlan &&
                document.ActiveView.ViewType != ViewType.Detail &&
                document.ActiveView.ViewType != ViewType.Section &&
                document.ActiveView.ViewType != ViewType.Elevation &&
                document.ActiveView.ViewType != ViewType.CeilingPlan)
            {
                throw new ArgumentException("Cannot place a Tag on active View");
            }


            if (element.InternalElement.Location.GetType() == typeof(LocationPoint))
            {
                LocationPoint locationPoint = (LocationPoint)element.InternalElement.Location;
                point = locationPoint.Point;
            }
            else if (element.InternalElement.Location.GetType() == typeof(LocationCurve))
            {
                LocationCurve locationCurve = (LocationCurve)element.InternalElement.Location;
                point = locationCurve.Curve.GetEndPoint(0);
            }
            else
            {
                BoundingBoxXYZ box = element.InternalElement.get_BoundingBox(document.ActiveView);
                if (box == null)
                {
                    box = element.InternalElement.get_BoundingBox(null);
                }
                if (box != null)
                {
                    point = box.Min + ((box.Max - box.Min) / 2);
                }
                else
                {
                    throw new ArgumentNullException("Cannot determine location");
                }
            }


            return(new Tag(element.InternalElement, orientation, tagMode, addLeader, point));
        }
示例#21
0
        private static List <Face3D> Profiles_RoofBase(this RoofBase roofBase)
        {
            List <Face3D> face3Ds = TopProfiles(roofBase);

            IEnumerable <ElementId> elementIds = roofBase.GetDependentElements(new ElementCategoryFilter(BuiltInCategory.OST_Windows));

            if (elementIds == null || elementIds.Count() == 0)
            {
                return(face3Ds);
            }

            foreach (ElementId elementId in elementIds)
            {
                Element element = roofBase.Document.GetElement(elementId);
                if (element == null)
                {
                    continue;
                }

                BoundingBoxXYZ boundingBoxXYZ = element.get_BoundingBox(null);
                Point3D        point3D        = ((boundingBoxXYZ.Max + boundingBoxXYZ.Min) / 2).ToSAM();
                foreach (Face3D face3D in face3Ds)
                {
                    List <Planar.IClosed2D> internalEdges = face3D.InternalEdge2Ds;
                    if (internalEdges == null || internalEdges.Count == 0)
                    {
                        continue;
                    }

                    Spatial.Plane plane = face3D.GetPlane();

                    Point3D        point3D_Projected = plane.Project(point3D);
                    Planar.Point2D point2D           = plane.Convert(point3D_Projected);

                    for (int i = 0; i < internalEdges.Count; i++)
                    {
                        Planar.IClosed2D internalEdge = internalEdges[i];
                        if (internalEdge.Inside(point2D))
                        {
                            face3D.RemoveInternalEdge(i);
                            break;
                        }
                    }
                }
            }

            return(face3Ds);
        }
示例#22
0
        public static void Newbox(this Document doc, BoundingBoxXYZ box)
        {
            var trans = box.Transform;
            var min   = box.Min;
            var max   = box.Max;
            var x     = max.X - min.X;
            var y     = max.Y - min.Y;
            var z     = max.Z - min.Z;

            //1、
            var endx  = min + x * trans.BasisX;
            var linex = Line.CreateBound(min, endx);

            var linex_1 = Line.CreateBound(endx, endx + y * trans.BasisY);
            var linex_2 = Line.CreateBound(endx, endx + z * trans.BasisZ);

            var endy  = min + y * trans.BasisY;
            var liney = Line.CreateBound(min, endy);

            var liney_1 = Line.CreateBound(endy, endy + x * trans.BasisX);
            var liney_2 = Line.CreateBound(endy, endy + z * trans.BasisZ);

            var endz  = min + z * trans.BasisZ;
            var linez = Line.CreateBound(min, endz);

            var linez_1 = Line.CreateBound(endz, endz + x * trans.BasisX);
            var linez_2 = Line.CreateBound(endz, endz + y * trans.BasisY);

            var _linex = Line.CreateBound(max, max - x * trans.BasisX);
            var _liney = Line.CreateBound(max, max - y * trans.BasisY);
            var _linez = Line.CreateBound(max, max - z * trans.BasisZ);

            doc.Invoke(m =>
            {
                doc.NewLine_withoutTransaction(linex);
                doc.NewLine_withoutTransaction(linex_1);
                doc.NewLine_withoutTransaction(linex_2);
                doc.NewLine_withoutTransaction(liney);
                doc.NewLine_withoutTransaction(liney_1);
                doc.NewLine_withoutTransaction(liney_2);
                doc.NewLine_withoutTransaction(linez);
                doc.NewLine_withoutTransaction(linez_1);
                doc.NewLine_withoutTransaction(linez_2);
                doc.NewLine_withoutTransaction(_linex);
                doc.NewLine_withoutTransaction(_liney);
                doc.NewLine_withoutTransaction(_linez);
            }, "创建包围框");
        }
示例#23
0
        /// <summary>
        /// Construct a Revit Linear Dimension from at least two Edges.
        /// </summary>
        /// <param name="view">View to place dimension in</param>
        /// <param name="referenceCurves">Edges to dimension</param>
        /// <param name="line">location of the dimension</param>
        /// <param name="suffix">Suffix</param>
        /// <param name="prefix">Prefix</param>
        /// <returns></returns>
        public static Dimension ByEdges(Revit.Elements.Views.View view, IEnumerable <Autodesk.DesignScript.Geometry.Curve> referenceCurves, [DefaultArgument("null")] Autodesk.DesignScript.Geometry.Line line, string suffix = "", string prefix = "")
        {
            var curves = referenceCurves.ToList();

            if (curves.Count < 2)
            {
                throw new Exception(string.Format(Properties.Resources.NotEnoughDataError, "Curves"));
            }

            Autodesk.Revit.DB.View revitView = (Autodesk.Revit.DB.View)view.InternalElement;
            Line revitLine = null;

            if (!view.IsAnnotationView())
            {
                throw new Exception(Properties.Resources.ViewDoesNotSupportAnnotations);
            }

            if (line == null)
            {
                BoundingBoxXYZ boundingBoxFirstElement = curves[0].BoundingBox.ToRevitType();
                if ((boundingBoxFirstElement) == null)
                {
                    throw new Exception(Properties.Resources.ElementCannotBeAnnotatedError);
                }

                BoundingBoxXYZ boundingBoxLastElement = curves[curves.Count - 1].BoundingBox.ToRevitType();
                if ((boundingBoxLastElement) == null)
                {
                    throw new Exception(Properties.Resources.ElementCannotBeAnnotatedError);
                }

                revitLine = Line.CreateBound(GetMidpoint(boundingBoxFirstElement), GetMidpoint(boundingBoxLastElement));
            }
            else
            {
                revitLine = (Line)line.ToRevitType(true);
            }

            ReferenceArray array = new ReferenceArray();

            foreach (var curve in curves)
            {
                var reference = Revit.GeometryReferences.ElementCurveReference.TryGetCurveReference(curve);
                array.Append(reference.InternalReference);
            }

            return(new Dimension(revitView, revitLine, array, suffix, prefix));
        }
示例#24
0
        internal override void Execute()
        {
            #region 与revit文档交互入口
            UIDocument uidoc    = this.uiapp.ActiveUIDocument;
            Document   doc      = uidoc.Document;
            Selection  sel      = uidoc.Selection;
            View       actiView = doc.ActiveView;
            #endregion

            IList <Element> textNoteTypes = (new FilteredElementCollector(doc)).OfClass(typeof(TextNoteType)).ToElements();
            string          tntfield      = "仿宋_3.5mm";//目标文字注释类型
            ElementId       tntId         = null;
            foreach (Element tnt in textNoteTypes)
            {
                if (tnt.Name == tntfield)//需要确认是否存在门窗标记类型的文字注释
                {
                    tntId = tnt.Id;
                }
            }
            TextNoteOptions opts = new TextNoteOptions(tntId);
            opts.Rotation = 0;


            IList <Element> selElements1 = sel.PickElementsByRectangle("请框选元素");
            using (Transaction trans = new Transaction(doc, "SetSurfaceTransparencyr"))
            {
                trans.Start();
                foreach (Element element in selElements1)
                {
                    if (!element.IsValidObject)
                    {
                        continue;                        //判断物体是否为有效物体
                    }
                    //if (element.Pinned) continue;
                    BoundingBoxXYZ boundingBoxXYZ = element.get_BoundingBox(actiView);
                    if (boundingBoxXYZ == null)
                    {
                        continue;
                    }

                    XYZ      textLoc  = boundingBoxXYZ.Min - new XYZ(20, 0, 0);
                    TextNote textNote = TextNote.Create(doc, actiView.Id, textLoc, element.Id.ToString(), opts);
                }
                trans.Commit();
            }

            //throw new NotImplementedException();
        }
示例#25
0
        // Reports a bounding box of the geometry that this server submits for drawing.
        public Outline GetBoundingBox(Autodesk.Revit.DB.View view)
        {
            try
            {
                BoundingBoxXYZ boundingBox = m_element.get_BoundingBox(null);

                Outline outline = new Outline(boundingBox.Min + m_offset, boundingBox.Max + m_offset);

                return(outline);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
                throw;
            }
        }
示例#26
0
        public static BoundingBoxXYZ crop_box(BoundingBoxXYZ bbox, double offset)
        {
            var minx = bbox.Min.X - offset;
            var miny = bbox.Min.Y - offset;
            var minz = bbox.Min.Z - offset;
            var maxx = bbox.Max.X + offset;
            var maxy = bbox.Max.Y + offset;
            var maxz = bbox.Max.Z + offset;

            var newbox = new BoundingBoxXYZ();

            newbox.Min = new XYZ(minx, miny, minz);
            newbox.Max = new XYZ(maxx, maxy, maxz);

            return(newbox);
        }
示例#27
0
        //擴大BoundingBox
        public Outline ExtendBoundingBox(BoundingBoxXYZ boundingBox)
        {
            Transform trans             = boundingBox.Transform;
            XYZ       boundingBoxMin    = boundingBox.Min;
            XYZ       boundingBoxMax    = boundingBox.Max;
            XYZ       victorBoundingBox = boundingBoxMax - boundingBoxMin;

            victorBoundingBox = victorBoundingBox.Normalize();

            boundingBoxMin -= victorBoundingBox;
            boundingBoxMax += victorBoundingBox;
            //定界框
            Outline outLine = new Outline(trans.OfPoint(boundingBoxMin), trans.OfPoint(boundingBoxMax));

            return(outLine);
        }
示例#28
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 BoundingBoxXYZ 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
            });
        }
        public static Autodesk.Revit.DB.BoundingBoxXYZ ToRevitBoundingBox(
            Autodesk.DesignScript.Geometry.CoordinateSystem cs,
            Autodesk.DesignScript.Geometry.Point minPoint,
            Autodesk.DesignScript.Geometry.Point maxPoint, bool convertUnits = true)
        {
            var rbb = new BoundingBoxXYZ();

            rbb.Enabled = true;

            rbb.Transform = cs.ToTransform(convertUnits);

            rbb.Max = maxPoint.ToXyz(convertUnits);
            rbb.Min = minPoint.ToXyz(convertUnits);

            return(rbb);
        }
示例#30
0
        public static Spatial.BoundingBox3D BoundingBox3D(this Element element)
        {
            if (element == null)
            {
                return(null);
            }

            BoundingBoxXYZ boundingBoxXYZ = element.get_BoundingBox(null);

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

            return(new Spatial.BoundingBox3D(boundingBoxXYZ.Min.ToSAM(), boundingBoxXYZ.Max.ToSAM()));
        }
示例#31
0
        static private BoundingBoxXYZ ProcessBoundingBox(IFCAnyHandle boundingBoxHnd)
        {
            IFCAnyHandle lowerLeftHnd = IFCAnyHandleUtil.GetInstanceAttribute(boundingBoxHnd, "Corner");
            XYZ          minXYZ       = IFCPoint.ProcessScaledLengthIFCCartesianPoint(lowerLeftHnd);

            double xDim = IFCAnyHandleUtil.GetDoubleAttribute(boundingBoxHnd, "XDim").Value;
            double yDim = IFCAnyHandleUtil.GetDoubleAttribute(boundingBoxHnd, "YDim").Value;
            double zDim = IFCAnyHandleUtil.GetDoubleAttribute(boundingBoxHnd, "ZDim").Value;

            XYZ            maxXYZ      = new XYZ(minXYZ.X + xDim, minXYZ.Y + yDim, minXYZ.Z + zDim);
            BoundingBoxXYZ boundingBox = new BoundingBoxXYZ();

            boundingBox.set_Bounds(0, minXYZ);
            boundingBox.set_Bounds(1, maxXYZ);
            return(boundingBox);
        }
示例#32
0
        /// <summary>
        /// Gets the box's plane 4 vectors.
        /// </summary>
        /// <param name="box"></param>
        /// <returns></returns>
        public static List <XYZ> GetPlaneVectorList(this BoundingBoxXYZ box)
        {
            if (box == null)
            {
                throw new ArgumentNullException(nameof(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
            });
        }
示例#33
0
        private bool FillSets(View view)
        {
            Transform identity = Transform.Identity;

            identity.set_Basis(0, view.RightDirection);
            identity.set_Basis(1, view.UpDirection);
            identity.set_Basis(2, view.ViewDirection);
            identity.Origin = view.Origin;

            Transform inverse = identity.Inverse;

            double farPoint          = view.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR).AsDouble();
            var    clippingParameter = view.get_Parameter(BuiltInParameter.VIEWER_BOUND_FAR_CLIPPING);

            if (clippingParameter == null)
            {
                return(false);
            }

            if (clippingParameter.AsInteger() == 0)
            {
                farPoint = 1E+19;
            }
            var segments = farPoint / SetCount;

            foreach (Element element in
                     from Element q in
                     (new FilteredElementCollector(_activeUIDocument.Document)).WhereElementIsNotElementType()
                     .WhereElementIsViewIndependent()
                     where (q.Category != null && q.HasPhases())
                     select q)
            {
                BoundingBoxXYZ boundingBox     = element.get_Geometry(new Options()).GetBoundingBox();
                XYZ            max             = (boundingBox.Max + boundingBox.Min) / 2;
                var            elementDistance = Math.Abs(inverse.OfPoint(max).Z);

                for (int x = 1; x <= SetCount; x++)
                {
                    if (elementDistance < segments * x && elementDistance >= segments * (x - 1))
                    {
                        _elementsSet[x - 1].Add(element.Id);
                        break;
                    }
                }
            }
            return(true);
        }
示例#34
0
    /// <summary>
    /// return section box for a view parallel to given wall
    /// </summary>
    /// <param name="wall"></param>
    /// <returns></returns>
    BoundingBoxXYZ getSectionVewParallelToWall(Wall wall)
    {
        LocationCurve lc    = wall.Location as LocationCurve;
        Curve         curve = lc.Curve;

        //view direction sectionBox.Transform.BasisZ
        //up direction sectionBox.Transform.BasisY
        //right hand is computed so that (right,up viewdirection) form a left handed coordinate system
        //crop region projections of BoundingBoxXYZ.Min and BoundingBoxXYZ.Max onto the view cut plane
        //far clip distance difference of the z-coordinates of BoundingBoxXYZ.Min and BoundingBoxXYZ.Max

        XYZ p = curve.GetEndPoint(0);
        XYZ q = curve.GetEndPoint(1);
        XYZ v = q - p;

        BoundingBoxXYZ bb   = wall.get_BoundingBox(null);
        double         minZ = bb.Min.Z;
        double         maxZ = bb.Max.Z;

        double w      = v.GetLength();
        double h      = maxZ - minZ;
        double d      = wall.WallType.Width;
        double offset = 0.1 * w;

        XYZ min = new XYZ(-w, minZ - offset, -offset);
        XYZ max = new XYZ(w, maxZ + offset, offset);

        XYZ midpoint = p + 0.5 * v;
        XYZ walldir  = v.Normalize();
        XYZ up       = XYZ.BasisZ;
        XYZ viewDir  = walldir.CrossProduct(up);

        Transform t = Transform.Identity;

        t.Origin = midpoint;
        t.BasisX = walldir;
        t.BasisY = up;
        t.BasisZ = viewDir;

        BoundingBoxXYZ sectionBox = new BoundingBoxXYZ();

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

        return(sectionBox);
    }
示例#35
0
            public static bool Recognization(Wall wall)
            {
                _wall         = wall;
                _thickness    = wall.Width;
                _length       = wall.get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH).AsDouble();
                _level_bottom =
                    _doc.GetElement(wall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId()) as Level;
                _level_top =
                    _doc.GetElement(wall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).AsElementId()) as Level;
                _offset_bottom = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET).AsDouble();
                _offset_top    = wall.get_Parameter(BuiltInParameter.WALL_TOP_OFFSET).AsDouble();
                _noConsHeight  = wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).AsDouble();

                _direction = GetWallDirection(wall);

                if (_direction == Direction.Undefined)
                {
                    _abandonWriter.WriteAbandonment(wall, AbandonmentTable.SkewWall);
                    return(false);
                }

                bool isFound;

                _floor_bottom =
                    _myLevel.GetFloor(out isFound, _level_bottom, _offset_bottom);
                _floor_top =
                    _myLevel.GetWallTopFloor(out isFound, _level_bottom, _offset_bottom, _noConsHeight);
                if (!isFound)
                {
                    --_floor_top;
                }

                if (!(MyLevel.isLegalFloorIndex(_floor_bottom) && MyLevel.isLegalFloorIndex(_floor_top)))
                {
                    _abandonWriter.WriteAbandonment(_wall as Element, AbandonmentTable.LevelNotFound);
                    return(false);
                }

                if (_floor_top <= _floor_bottom)
                {
                    _abandonWriter.WriteAbandonment(_wall as Element, AbandonmentTable.Wall_WallTooShort);
                    return(false);
                }

                _boundingBox = wall.get_BoundingBox(_doc.ActiveView);
                return(true);
            }
示例#36
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public virtual Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData
                                                        , ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Autodesk.Revit.DB.Document doc = commandData.Application.ActiveUIDocument.Document;

            // get one sheet view to place panel schedule.
            ViewSheet sheet = doc.ActiveView as ViewSheet;

            if (null == sheet)
            {
                message = "please go to a sheet view.";
                return(Result.Failed);
            }

            // get all PanelScheduleView instances in the Revit document.
            FilteredElementCollector fec = new FilteredElementCollector(doc);
            ElementClassFilter       PanelScheduleViewsAreWanted = new ElementClassFilter(typeof(PanelScheduleView));

            fec.WherePasses(PanelScheduleViewsAreWanted);
            List <Element> psViews = fec.ToElements() as List <Element>;

            Transaction placePanelScheduleOnSheet = new Transaction(doc, "placePanelScheduleOnSheet");

            placePanelScheduleOnSheet.Start();

            XYZ nextOrigin = new XYZ(0.0, 0.0, 0.0);

            foreach (Element element in psViews)
            {
                PanelScheduleView psView = element as PanelScheduleView;
                if (psView.IsPanelScheduleTemplate())
                {
                    // ignore the PanelScheduleView instance which is a template.
                    continue;
                }

                PanelScheduleSheetInstance onSheet = PanelScheduleSheetInstance.Create(doc, psView.Id, sheet);
                onSheet.Origin = nextOrigin;
                BoundingBoxXYZ bbox  = onSheet.get_BoundingBox(doc.ActiveView);
                double         width = bbox.Max.X - bbox.Min.X;
                nextOrigin = new XYZ(onSheet.Origin.X + width, onSheet.Origin.Y, onSheet.Origin.Z);
            }

            placePanelScheduleOnSheet.Commit();

            return(Result.Succeeded);
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication  val   = commandData.get_Application();
            Document       val2  = val.get_ActiveUIDocument().get_Document();
            IList <View3D> views = new FilteredElementCollector(val2).WhereElementIsNotElementType().OfClass(typeof(View3D)).ToElements()
                                   .Cast <View3D>()
                                   .ToList();
            ViewsForZonesForm viewsForZonesForm = new ViewsForZonesForm(views, val2.get_ActiveView() as View3D);

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

            try
            {
                val5.Start();
                foreach (FamilyInstance item in projectZones)
                {
                    ElementId      val6 = selectedView.Duplicate(0);
                    View3D         val7 = val2.GetElement(val6) as View3D;
                    BoundingBoxXYZ val8 = item.get_BoundingBox(null);
                    BoundingBoxXYZ val9 = new BoundingBoxXYZ();
                    val9.set_Min(val8.get_Min() + val3);
                    val9.set_Max(val8.get_Max() + val4);
                    val7.set_Name("3D " + item.LookupParameter("Name").AsString());
                    val7.SetSectionBox(val9);
                }
                val5.Commit();
            }
            catch (OperationCanceledException)
            {
                return(1);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(-1);
            }
            return(0);
        }
示例#38
0
        private bool isTopFace(Face myFace, Element myBeam)

        {
            UIDocument uiDoc = this.ActiveUIDocument;
            Document   doc   = uiDoc.Document;

            BoundingBoxXYZ myBoundBeam = myBeam.get_BoundingBox(null);

            double zMaxValue = myBoundBeam.Max.Z;

            if (Math.Abs(zMaxValue - getElevetionOfFace(myFace)) < 0.001)
            {
                return(true);
            }

            return(false);
        }
        public static IEnumerable <ElementId> CastBoundingBox(
            ModelInfo info, BoundingBoxXYZ bb, BuiltInCategory bic = BuiltInCategory.INVALID, View view = null)
        {
            Outline outline = new Outline(bb.Min, bb.Max);

            BoundingBoxIntersectsFilter filter = new BoundingBoxIntersectsFilter(outline);

            FilteredElementCollector coll;

            coll = view != null ? new FilteredElementCollector(info.DOC, view.Id) : new FilteredElementCollector(info.DOC);

            var intersection = bic == BuiltInCategory.INVALID ?
                               coll.WherePasses(filter).ToElementIds() :
                               coll.WherePasses(filter).OfCategory(bic).ToElementIds();

            return(intersection);
        }
        private void ApplyParameterToDevice(Room room, Document doc)
        {
            List <FamilyInstance> devicesList = new List <FamilyInstance>();
            BoundingBoxXYZ        box         = room.get_BoundingBox(null);

            if (box != null)
            {
                //TODO Create group categories
                devicesList.AddRange(GetCategoryDevices(doc, room, BuiltInCategory.OST_ElectricalEquipment));
                devicesList.AddRange(GetCategoryDevices(doc, room, BuiltInCategory.OST_ElectricalFixtures));
                devicesList.AddRange(GetCategoryDevices(doc, room, BuiltInCategory.OST_LightingDevices));
                devicesList.AddRange(GetCategoryDevices(doc, room, BuiltInCategory.OST_LightingFixtures));
                devicesList.AddRange(GetCategoryDevices(doc, room, BuiltInCategory.OST_FireAlarmDevices));
                devicesList.AddRange(GetCategoryDevices(doc, room, BuiltInCategory.OST_CommunicationDevices));
                devicesList.AddRange(GetCategoryDevices(doc, room, BuiltInCategory.OST_TelephoneDevices));
                devicesList.AddRange(GetCategoryDevices(doc, room, BuiltInCategory.OST_DataDevices));

                devicesList.AddRange(GetCategoryDevices(doc, room, BuiltInCategory.OST_SecurityDevices));
                devicesList.AddRange(GetCategoryDevices(doc, room, BuiltInCategory.OST_CableTray));
                devicesList.AddRange(GetCategoryDevices(doc, room, BuiltInCategory.OST_CableTrayFitting));
                devicesList.AddRange(GetCategoryDevices(doc, room, BuiltInCategory.OST_GenericModel));

                {
                    //TODO Create parameter from user menu
                    using (Transaction trans = new Transaction(doc, "Paramaters Adding"))
                    {
                        trans.Start();
                        foreach (FamilyInstance instance in devicesList)
                        {
                            try
                            {
                                Parameter param1 = instance.LookupParameter("RaumNummer");
                                Parameter param2 = instance.LookupParameter("RaumName");

                                param1.Set(room.get_Parameter(BuiltInParameter.ROOM_NUMBER).AsString());
                                param2.Set(room.get_Parameter(BuiltInParameter.ROOM_NAME).AsString());
                            }
                            catch (Exception e)
                            {
                            }
                        }
                        trans.Commit();
                    }
                }
            }
        }
示例#41
0
        public static View3D GetMatching3DView(this View view, Document doc)
        {
            ViewFamilyType viewFamilyType = (from v in new FilteredElementCollector(doc).
                 OfClass(typeof(ViewFamilyType)).
                 Cast<ViewFamilyType>()
                 where v.ViewFamily == ViewFamily.ThreeDimensional
                 select v).First();

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

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

            ViewBox myviewbox = GetViewBox(view);

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

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

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

            }

            doc.Regenerate();

            return view3d;
        }
示例#42
0
        /// <summary>
        /// Private constructor
        /// </summary>
        private PerspectiveView(XYZ eye, XYZ target, BoundingBoxXYZ bbox, string name, bool isolate)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldEle =
                ElementBinder.GetElementFromTrace<Autodesk.Revit.DB.View3D>(Document);

            // Rebind to Element
            if (oldEle != null)
            {
                InternalSetView3D(oldEle);
                InternalSetOrientation(BuildOrientation3D(eye, target));
                if (isolate)
                {
                    InternalIsolateInView(bbox);
                }
                else
                {
                    InternalRemoveIsolation();
                }
                InternalSetName(name);
                return;
            }

            //Phase 2 - There was no existing Element, create new one
            TransactionManager.Instance.EnsureInTransaction(Document);

            var vd = Create3DView(BuildOrientation3D(eye, target), name, true);
            InternalSetView3D(vd);
            if (isolate)
            {
                InternalIsolateInView(bbox);
            }
            else
            {
                InternalRemoveIsolation();
            }
            InternalSetName(name);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(this.InternalElement);
        }
示例#43
0
文件: ModelData.cs 项目: AMEE/revit
        /// <summary>
        /// Generate appropriate graphics data object from exact analytical model type.
        /// </summary>
        /// <param name="element">The selected element maybe has analytical model lines</param>
        /// <returns>A graphics data object appropriate for GDI.</returns>
        public ModelData(Element element)
        {
            try
            {
                AnalyticalModel analyticalMode = GetAnalyticalModel(element);
                View currentView = Command.CommandData.Application.ActiveUIDocument.Document.ActiveView;
                m_bbox = element.get_BoundingBox(currentView);

                if (null == analyticalMode)
                {
                    return;
                }

                GetModelData(analyticalMode);

            }
            catch (Exception)
            {
            }
        }
示例#44
0
        static private BoundingBoxXYZ ProcessBoundingBox(IFCAnyHandle boundingBoxHnd)
        {
            IFCAnyHandle lowerLeftHnd = IFCAnyHandleUtil.GetInstanceAttribute(boundingBoxHnd, "Corner");
            XYZ minXYZ = IFCPoint.ProcessScaledLengthIFCCartesianPoint(lowerLeftHnd);

            double xDim = IFCAnyHandleUtil.GetDoubleAttribute(boundingBoxHnd, "XDim").Value;
            double yDim = IFCAnyHandleUtil.GetDoubleAttribute(boundingBoxHnd, "YDim").Value;
            double zDim = IFCAnyHandleUtil.GetDoubleAttribute(boundingBoxHnd, "ZDim").Value;

            XYZ maxXYZ = new XYZ(minXYZ.X + xDim, minXYZ.Y + yDim, minXYZ.Z + zDim);
            BoundingBoxXYZ boundingBox = new BoundingBoxXYZ();
            boundingBox.set_Bounds(0, minXYZ);
            boundingBox.set_Bounds(1, maxXYZ);
            return boundingBox;
        }
示例#45
0
        // Handles Solid, Mesh, and Face.
        private static BoundingBoxXYZ ComputeApproximateBoundingBox(IList<Solid> solids, IList<Mesh> polymeshes, IList<Face> independentFaces, Transform trf)
        {
            XYZ minBound = new XYZ(1000000000, 1000000000, 1000000000);
            XYZ maxBound = new XYZ(-1000000000, -1000000000, -1000000000);

            IList<Face> planarFaces = new List<Face>();
            IList<Face> nonPlanarFaces = new List<Face>();
            ICollection<Edge> edgesToTesselate = new HashSet<Edge>();

            foreach (Face face in independentFaces)
            {
                if (face is PlanarFace)
                    planarFaces.Add(face);
                else
                    nonPlanarFaces.Add(face);
            }

            foreach (Solid solid in solids)
            {
                FaceArray faces = solid.Faces;
                IList<Face> solidPlanarFaces = new List<Face>();
                foreach (Face face in faces)
                {
                    if (face is PlanarFace)
                        solidPlanarFaces.Add(face);
                    else
                        nonPlanarFaces.Add(face);
                }

                if (solidPlanarFaces.Count() == faces.Size)
                {
                    foreach (Edge edge in solid.Edges)
                        edgesToTesselate.Add(edge);
                }
                else
                {
                    foreach (Face planarFace in solidPlanarFaces)
                        planarFaces.Add(planarFace);
                }
            }

            foreach (Face planarFace in planarFaces)
            {
                EdgeArrayArray edgeLoops = planarFace.EdgeLoops;
                foreach (EdgeArray edgeLoop in edgeLoops)
                {
                    foreach (Edge edge in edgeLoop)
                        edgesToTesselate.Add(edge);
                }
            }

            foreach (Edge edge in edgesToTesselate)
            {
                IList<XYZ> edgeVertices = edge.Tessellate();
                IList<XYZ> transformedEdgeVertices = TransformVertexList(edgeVertices, trf);
                minBound = NewMinBound(minBound, transformedEdgeVertices);
                maxBound = NewMaxBound(maxBound, transformedEdgeVertices);
            }

            foreach (Face nonPlanarFace in nonPlanarFaces)
            {
                Mesh faceMesh = nonPlanarFace.Triangulate();
                polymeshes.Add(faceMesh);
            }

            foreach (Mesh mesh in polymeshes)
            {
                IList<XYZ> vertices = mesh.Vertices;
                IList<XYZ> transformedVertices = TransformVertexList(vertices, trf);
                minBound = NewMinBound(minBound, transformedVertices);
                maxBound = NewMaxBound(maxBound, transformedVertices);
            }

            BoundingBoxXYZ boundingBox = new BoundingBoxXYZ();
            boundingBox.set_Bounds(0, minBound);
            boundingBox.set_Bounds(1, maxBound);
            return boundingBox;
        }
示例#46
0
        /// <summary>
        /// Creates or updates the IfcLocalPlacement associated with the current origin offset.
        /// </summary>
        /// <param name="exporterIFC">The exporter.</param>
        /// <param name="bbox">The bounding box.</param>
        /// <param name="ecData">The extrusion creation data which contains the local placement.</param>
        /// <param name="lpOrig">The local placement origin.</param>
        /// <param name="unscaledTrfOrig">The unscaled local placement origin.</param>
        public void CreateLocalPlacementFromOffset(ExporterIFC exporterIFC, BoundingBoxXYZ bbox, IFCExtrusionCreationData ecData, XYZ lpOrig, XYZ unscaledTrfOrig)
        {
            if (ecData == null)
                return;

            IFCAnyHandle localPlacement = ecData.GetLocalPlacement();
            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(localPlacement))
            {
                IFCFile file = exporterIFC.GetFile();

                // If the BBox passes through (0,0, 0), or no bbox, do nothing.
                if (bbox == null ||
                    ((bbox.Min.X < MathUtil.Eps() && bbox.Max.X > -MathUtil.Eps()) &&
                     (bbox.Min.Y < MathUtil.Eps() && bbox.Max.Y > -MathUtil.Eps()) &&
                     (bbox.Min.Z < MathUtil.Eps() && bbox.Max.Z > -MathUtil.Eps())))
                {
                    if (!ecData.ReuseLocalPlacement)
                        ecData.SetLocalPlacement(ExporterUtil.CopyLocalPlacement(file, localPlacement));
                    return;
                }

                if (!MathUtil.IsAlmostZero(unscaledTrfOrig.DotProduct(unscaledTrfOrig)))
                {
                    if (!ecData.ReuseLocalPlacement)
                        ecData.SetLocalPlacement(ExporterUtil.CreateLocalPlacement(file, localPlacement, lpOrig, null, null));
                    else
                    {
                        IFCAnyHandle relativePlacement = GeometryUtil.GetRelativePlacementFromLocalPlacement(localPlacement);
                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(relativePlacement))
                        {
                            IFCAnyHandle newRelativePlacement = ExporterUtil.CreateAxis(file, lpOrig, null, null);
                            GeometryUtil.SetRelativePlacement(localPlacement, newRelativePlacement);
                        }
                        else
                        {
                            IFCAnyHandle newOriginHnd = ExporterUtil.CreateCartesianPoint(file, lpOrig);
                            IFCAnyHandleUtil.SetAttribute(relativePlacement, "Location", newOriginHnd);
                        }
                    }
                }
                else if (ecData.ForceOffset)
                    ecData.SetLocalPlacement(ExporterUtil.CreateLocalPlacement(file, localPlacement, null));
                else if (!ecData.ReuseLocalPlacement)
                    ecData.SetLocalPlacement(ExporterUtil.CopyLocalPlacement(file, localPlacement));
            }
        }
示例#47
0
    ViewSection GetFrontView( Element e )
    {
      // Retrieve element bounding box

      BoundingBoxXYZ bb = e.get_BoundingBox( null );

      // Determine box size

      XYZ size = bb.Max - bb.Min;

      // Set up view from front with small gap 
      // between section and element

      //XYZ pMax = new XYZ( -0.5 * size.X, 0.5 * size.Z,  0.5 * size.Y );
      //XYZ pMin = new XYZ(  0.5 * size.X, -0.5 * size.Z, -0.5 * size.Y - 0.2 );

      // Set up view from front in element midpoint

      XYZ pMax = new XYZ( -0.5 * size.X, 0.5 * size.Z,  0.5 * size.Y );
      XYZ pMin = new XYZ( 0.5 * size.X, -0.5 * size.Z, -0.5 * size.Y - 0.2 );

      BoundingBoxXYZ bbView = new BoundingBoxXYZ();
      bbView.Enabled = true;
      bbView.Max = pMax;
      bbView.Min = pMin;

      // Set the transform

      Transform tx = Transform.Identity;

      // Determine element midpoint

      XYZ pMid = 0.5 * ( bb.Max + bb.Min );

      // Set it as origin

      tx.Origin = pMid;

      // Set view direction

      tx.BasisX = -XYZ.BasisX;
      tx.BasisY = XYZ.BasisZ;
      tx.BasisZ = XYZ.BasisY;

      bbView.Transform = tx;

      // Create and return section view

      Document doc = e.Document;

      Transaction t = new Transaction( doc );
      t.Start( "Create Section View" );
      
      ViewSection viewSection = doc.Create.NewViewSection( bbView );
      
      t.Commit();

      return viewSection;
    }
        private void Stream(ArrayList data, BoundingBoxXYZ bndBox)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(BoundingBoxXYZ)));

            data.Add(new Snoop.Data.Bool("Enabled", bndBox.Enabled));
            data.Add(new Snoop.Data.Xyz("Min", bndBox.Min));
            data.Add(new Snoop.Data.Xyz("Max", bndBox.Max));
            data.Add(new Snoop.Data.Object("Transform", bndBox.Transform));
        }
示例#49
0
        /// <summary>
        ///    Initializes the transformation in the transform setter.
        /// </summary>
        /// <param name="exporterIFC">The exporter.</param>
        /// <param name="bbox">The bounding box.</param>
        /// <param name="ecData">The extrusion creation data which contains the local placement.</param>
        /// <param name="unscaledTrfOrig">The scaled local placement origin.</param>
        /// <returns>The transform corresponding to the movement, if any.</returns>
        public Transform InitializeFromBoundingBox(ExporterIFC exporterIFC, BoundingBoxXYZ bbox, IFCExtrusionCreationData ecData, out XYZ unscaledTrfOrig)
        {
            unscaledTrfOrig = new XYZ();
            if (ecData == null)
                return null;

            Transform trf = Transform.Identity;
            IFCAnyHandle localPlacement = ecData.GetLocalPlacement();
            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(localPlacement))
            {
                IFCFile file = exporterIFC.GetFile();
                
                // If the BBox passes through (0,0, 0), or no bbox, do nothing.
                if (bbox == null ||
                    ((bbox.Min.X < MathUtil.Eps() && bbox.Max.X > -MathUtil.Eps()) &&
                     (bbox.Min.Y < MathUtil.Eps() && bbox.Max.Y > -MathUtil.Eps()) &&
                     (bbox.Min.Z < MathUtil.Eps() && bbox.Max.Z > -MathUtil.Eps())))
                    return trf;
                
                XYZ bboxMin = bbox.Min;
                XYZ scaledOrig = UnitUtil.ScaleLength(bboxMin);

                Transform scaledTrf = GeometryUtil.GetScaledTransform(exporterIFC);

                XYZ lpOrig = scaledTrf.OfPoint(scaledOrig);
                if (!ecData.AllowVerticalOffsetOfBReps)
                    lpOrig = new XYZ(lpOrig.X, lpOrig.Y, 0.0);

                Transform scaledTrfInv = scaledTrf.Inverse;
                XYZ scaledInvOrig = scaledTrfInv.OfPoint(XYZ.Zero);

                XYZ unscaledInvOrig = UnitUtil.UnscaleLength(scaledInvOrig);

                unscaledTrfOrig = unscaledInvOrig - bboxMin;
                if (!ecData.AllowVerticalOffsetOfBReps)
                    unscaledTrfOrig = new XYZ(unscaledTrfOrig.X, unscaledTrfOrig.Y, 0.0);

                if (!MathUtil.IsAlmostZero(unscaledTrfOrig.DotProduct(unscaledTrfOrig)))
                {
                    Initialize(exporterIFC, unscaledTrfOrig, XYZ.BasisX, XYZ.BasisY);
                    if (!ecData.ReuseLocalPlacement)
                    {
                    }
                    else
                    {
                        IFCAnyHandle relativePlacement = GeometryUtil.GetRelativePlacementFromLocalPlacement(localPlacement);
                        if (!IFCAnyHandleUtil.IsNullOrHasNoValue(relativePlacement))
                        {
                            IFCAnyHandle oldOriginHnd, zDirHnd, xDirHnd;
                            xDirHnd = IFCAnyHandleUtil.GetInstanceAttribute(relativePlacement, "RefDirection");
                            zDirHnd = IFCAnyHandleUtil.GetInstanceAttribute(relativePlacement, "Axis");
                            oldOriginHnd = IFCAnyHandleUtil.GetInstanceAttribute(relativePlacement, "Location");

                            bool trfSet = false;
                            XYZ xDir = XYZ.BasisX; XYZ zDir = XYZ.BasisZ; XYZ oldCoords = XYZ.Zero;
                            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(xDirHnd))
                            {
                                xDir = GeometryUtil.GetDirectionRatios(xDirHnd);
                                trfSet = true;
                            }
                            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(zDirHnd))
                            {
                                zDir = GeometryUtil.GetDirectionRatios(zDirHnd);
                                trfSet = true;
                            }
                            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(oldOriginHnd))
                            {
                                oldCoords = GeometryUtil.GetCoordinates(oldOriginHnd);
                            }

                            if (trfSet)
                            {
                                XYZ yDir = zDir.CrossProduct(xDir);
                                Transform relPlacementTrf = Transform.Identity;
                                relPlacementTrf.Origin = oldCoords; relPlacementTrf.BasisX = xDir;
                                relPlacementTrf.BasisY = yDir; relPlacementTrf.BasisZ = zDir;
                                lpOrig = relPlacementTrf.OfPoint(lpOrig);
                            }
                            else
                                lpOrig = oldCoords + lpOrig;
                        }
                    }

                    trf.Origin = lpOrig;
                }
            }
            return trf;
        }
示例#50
0
文件: Command.cs 项目: AMEE/revit
        /// <summary>
        /// Generate a BoundingBoxXYZ instance which used in NewViewSection() method
        /// </summary>
        /// <returns>true if the instance can be created; otherwise, false.</returns>
        Boolean GenerateBoundingBoxXYZ()
        {
            Transaction transaction = new Transaction(m_project.Document, "GenerateBoundingBox");
            transaction.Start();
            // First new a BoundingBoxXYZ, and set the MAX and Min property.
            m_box = new BoundingBoxXYZ();
            m_box.Enabled = true;
            Autodesk.Revit.DB.XYZ maxPoint = new Autodesk.Revit.DB.XYZ (LENGTH, LENGTH, 0);
            Autodesk.Revit.DB.XYZ minPoint = new Autodesk.Revit.DB.XYZ (-LENGTH, -LENGTH, -HEIGHT);
            m_box.Max = maxPoint;
            m_box.Min = minPoint;

            // Set Transform property is the most important thing.
            // It define the Orgin and the directions(include RightDirection,
            // UpDirection and ViewDirection) of the created view.
            Transform transform = GenerateTransform();
            if (null == transform)
            {
                return false;
            }
            m_box.Transform = transform;
            transaction.Commit();

            // If all went well, return true.
            return true;
        }
        private static BoundingBoxXYZ ComputeApproximateCurveLoopBBoxForOpening(CurveLoop curveLoop, Plane plane)
        {
            Transform trf = null;
            Transform trfInv = null;

            XYZ ll = null;
            XYZ ur = null;
            if (plane != null)
            {
                trf = Transform.Identity;
                trf.BasisX = plane.XVec;
                trf.BasisY = plane.YVec;
                trf.BasisZ = plane.Normal;
                trf.Origin = plane.Origin;
                trfInv = trf.Inverse;
            }

            bool init = false;
            foreach (Curve curve in curveLoop)
            {
                IList<XYZ> pts = new List<XYZ>();
                if (curve is Line) 
                {
                    pts.Add(curve.GetEndPoint(0));
                    pts.Add(curve.GetEndPoint(1));
                }
                else if (curve is Arc)
                {
                    ComputeArcBoundingBox(curve as Arc, pts);
                }
                else
                    pts = curve.Tessellate();

                foreach (XYZ pt in pts)
                {
                    XYZ ptToUse = (trf != null) ? trfInv.OfPoint(pt) : pt;
                    if (!init)
                    {
                        ll = ptToUse;
                        ur = ptToUse;
                        init = true;
                    }
                    else
                    {
                        ll = new XYZ(Math.Min(ll.X, ptToUse.X), Math.Min(ll.Y, ptToUse.Y), Math.Min(ll.Z, ptToUse.Z));
                        ur = new XYZ(Math.Max(ur.X, ptToUse.X), Math.Max(ur.Y, ptToUse.Y), Math.Max(ur.Z, ptToUse.Z));
                    }
                }
            }

            if (!init)
                return null;

            if (trf != null)
            {
                ll = trf.OfPoint(ll);
                ur = trf.OfPoint(ur);
            }

            BoundingBoxXYZ curveLoopBounds = new BoundingBoxXYZ();
            curveLoopBounds.set_Bounds(0, ll);
            curveLoopBounds.set_Bounds(1, ur);
            return curveLoopBounds;
        }
示例#52
0
文件: View3D.cs 项目: heegwon/Dynamo
 /// <summary>
 /// Isolate the bounding box in the current view
 /// </summary>
 /// <param name="bbox"></param>
 protected void InternalIsolateInView(BoundingBoxXYZ bbox)
 {
     IsolateInView(this.InternalView3D, bbox);
 }
示例#53
0
文件: dynViews.cs 项目: kyoisi/Dynamo
        private static ViewSection CreateSectionView(BoundingBoxXYZ bbox)
        {
            //http://adndevblog.typepad.com/aec/2012/05/viewplancreate-method.html

            IEnumerable<ViewFamilyType> viewFamilyTypes = from elem in new
              FilteredElementCollector(dynRevitSettings.Doc.Document).OfClass(typeof(ViewFamilyType))
                                                          let type = elem as ViewFamilyType
                                                          where type.ViewFamily == ViewFamily.Section
                                                          select type;

            //create a new view
            ViewSection view = ViewSection.CreateSection(dynRevitSettings.Doc.Document, viewFamilyTypes.First().Id, bbox);
            return view;
        }
示例#54
0
文件: View3D.cs 项目: heegwon/Dynamo
 /// <summary>
 /// Set the cropping for the current view
 /// </summary>
 /// <param name="view3D"></param>
 /// <param name="bbox"></param>
 private void IsolateInView(Autodesk.Revit.DB.View3D view3D, BoundingBoxXYZ bbox)
 {
     view3D.CropBox = bbox;
 }
        // Takes into account the transform, assuming any rotation.
        private static IFCRange GetBoundingBoxZRange(BoundingBoxXYZ boundingBox)
        {
            double minZ = 1e+30;
            double maxZ = -1e+30;

            for (int ii = 0; ii < 8; ii++)
            {
                XYZ currXYZ = new XYZ(((ii & 1) == 0) ? boundingBox.Min.X : boundingBox.Max.X,
                    ((ii & 2) == 0) ? boundingBox.Min.Y : boundingBox.Max.Y,
                    ((ii & 4) == 0) ? boundingBox.Min.Z : boundingBox.Max.Z);
                XYZ transformedXYZ = boundingBox.Transform.OfPoint(currXYZ);

                minZ = Math.Min(minZ, transformedXYZ.Z);
                maxZ = Math.Max(maxZ, transformedXYZ.Z);
            }

            if (minZ >= maxZ)
                return null;

            return new IFCRange(minZ, maxZ);
        }
      /// <summary>
      /// Return a solid corresponding to the volume represented by boundingBoxXYZ. 
      /// </summary>
      /// <param name="lcs">The local coordinate system of the bounding box; if null, assume the Identity transform.</param>
      /// <param name="boundingBoxXYZ">The bounding box.</param>
      /// <param name="solidOptions">The options for creating the solid.  Allow null to mean default.</param>
      /// <returns>A solid of the same size and orientation as boundingBoxXYZ, or null if boundingBoxXYZ is invalid or null.</returns>
      /// <remarks>We don't do any checking on the input transform, which could have non-uniform scaling and/or mirroring.
      /// This could potentially lead to unexpected results, which we can examine if and when such cases arise.</remarks>
      public static Solid CreateSolidFromBoundingBox(Transform lcs, BoundingBoxXYZ boundingBoxXYZ, SolidOptions solidOptions)
      {
         // Check that the bounding box is valid.
         if (boundingBoxXYZ == null || !boundingBoxXYZ.Enabled)
            return null;

         try
         {
            // Create a transform based on the incoming local coordinate system and the bounding box coordinate system.
            Transform bboxTransform = (lcs == null) ? boundingBoxXYZ.Transform : lcs.Multiply(boundingBoxXYZ.Transform);

            XYZ[] profilePts = new XYZ[4];
            profilePts[0] = bboxTransform.OfPoint(boundingBoxXYZ.Min);
            profilePts[1] = bboxTransform.OfPoint(new XYZ(boundingBoxXYZ.Max.X, boundingBoxXYZ.Min.Y, boundingBoxXYZ.Min.Z));
            profilePts[2] = bboxTransform.OfPoint(new XYZ(boundingBoxXYZ.Max.X, boundingBoxXYZ.Max.Y, boundingBoxXYZ.Min.Z));
            profilePts[3] = bboxTransform.OfPoint(new XYZ(boundingBoxXYZ.Min.X, boundingBoxXYZ.Max.Y, boundingBoxXYZ.Min.Z));

            XYZ upperRightXYZ = bboxTransform.OfPoint(boundingBoxXYZ.Max);

            // If we assumed that the transforms had no scaling, 
            // then we could simply take boundingBoxXYZ.Max.Z - boundingBoxXYZ.Min.Z.
            // This code removes that assumption.
            XYZ origExtrusionVector = new XYZ(boundingBoxXYZ.Min.X, boundingBoxXYZ.Min.Y, boundingBoxXYZ.Max.Z) - boundingBoxXYZ.Min;
            XYZ extrusionVector = bboxTransform.OfVector(origExtrusionVector);

            double extrusionDistance = extrusionVector.GetLength();
            XYZ extrusionDirection = extrusionVector.Normalize();

            CurveLoop baseLoop = new CurveLoop();

            for (int ii = 0; ii < 4; ii++)
            {
               baseLoop.Append(Line.CreateBound(profilePts[ii], profilePts[(ii + 1) % 4]));
            }

            IList<CurveLoop> baseLoops = new List<CurveLoop>();
            baseLoops.Add(baseLoop);

            if (solidOptions == null)
               return GeometryCreationUtilities.CreateExtrusionGeometry(baseLoops, extrusionDirection, extrusionDistance);
            else
               return GeometryCreationUtilities.CreateExtrusionGeometry(baseLoops, extrusionDirection, extrusionDistance, solidOptions);
         }
         catch
         {
            return null;
         }
      }
        /// <summary>
        /// Checks whether a given Revit element 'e' is 
        /// hidden in a specified view 'v'. 
        /// If v has a crop box defined, e is 
        /// considered hidden if its bounding box is 
        /// outside or less than 25% contained in the 
        /// crop box. If e is not eliminated as hidden 
        /// by that test, its IsHidden predicate is 
        /// checked, followed by the visibility of its 
        /// category and all its parent categories in 
        /// the given view.
        /// Return true if the given element e is hidden
        /// in the view v. This might be due to:
        /// - e lies outside the view crop box
        /// - e is specifically hidden in the view, by element
        /// - the category of e or one of its parent 
        /// categories is hidden in v.
        /// </summary>
        bool IsElementHiddenInView(
            Element e,
            View v)
        {
            if( v.CropBoxActive )
              {
            BoundingBoxXYZ viewBox = v.CropBox;
            BoundingBoxXYZ elBox = e.get_BoundingBox( v );

            Transform transInv = v.CropBox.Transform.Inverse;

            elBox.Max = transInv.OfPoint( elBox.Max );
            elBox.Min = transInv.OfPoint( elBox.Min );

            // The transform above might switch
            // max and min values.

            if( elBox.Min.X > elBox.Max.X )
            {
              XYZ tmpP = elBox.Min;
              elBox.Min = new XYZ( elBox.Max.X, elBox.Min.Y, 0 );
              elBox.Max = new XYZ( tmpP.X, elBox.Max.Y, 0 );
            }

            if( elBox.Min.Y > elBox.Max.Y )
            {
              XYZ tmpP = elBox.Min;
              elBox.Min = new XYZ( elBox.Min.X, elBox.Max.Y, 0 );
              elBox.Max = new XYZ( tmpP.X, elBox.Min.Y, 0 );
            }

            if( elBox.Min.X > viewBox.Max.X
              || elBox.Max.X < viewBox.Min.X
              || elBox.Min.Y > viewBox.Max.Y
              || elBox.Max.Y < viewBox.Min.Y )
            {
              return true;
            }
            else
            {
              BoundingBoxXYZ inside = new BoundingBoxXYZ();

              double x, y;

              x = elBox.Max.X;

              if( elBox.Max.X > viewBox.Max.X )
            x = viewBox.Max.X;

              y = elBox.Max.Y;

              if( elBox.Max.Y > viewBox.Max.Y )
            y = viewBox.Max.Y;

              inside.Max = new XYZ( x, y, 0 );

              x = elBox.Min.X;

              if( elBox.Min.X < viewBox.Min.X )
            x = viewBox.Min.X;

              y = elBox.Min.Y;

              if( elBox.Min.Y < viewBox.Min.Y )
            y = viewBox.Min.Y;

              inside.Min = new XYZ( x, y, 0 );

              double eBBArea = ( elBox.Max.X - elBox.Min.X )
            * ( elBox.Max.Y - elBox.Min.Y );

              double einsideArea =
            ( inside.Max.X - inside.Min.X )
            * ( inside.Max.Y - inside.Min.Y );

              double factor = einsideArea / eBBArea;

              if( factor < 0.25 )
            return true;
            }
              }

              bool hidden = e.IsHidden( v );

              if( !hidden )
              {
            Category cat = e.Category;

            while( null != cat && !hidden )
            {
              hidden = !cat.get_Visible( v );
              cat = cat.Parent;
            }
              }
              return hidden;
        }
示例#58
0
        /// <summary>
        /// Constructor, Construct a new object with an element's geometry Solid,
        /// and its corresponding bounding box.
        /// </summary>
        /// <param name="solid">Element's geometry Solid</param>
        /// <param name="box">Element's geometry bounding box</param>
        public ElementGeometry(Solid solid, BoundingBoxXYZ box)
        {
            m_solid = solid;
            m_bBoxMin = box.Min;
            m_bBoxMax = box.Max;
            m_isDirty = true;

            // Initialize edge binding
            m_edgeBindinDic = new Dictionary<Edge, EdgeBinding>();
            foreach (Edge edge in m_solid.Edges)
            {
                EdgeBinding edgeBingding = new EdgeBinding(edge);
                m_edgeBindinDic.Add(edge, edgeBingding);
            }
        }
 /// <summary>
 /// Return a string for a bounding box
 /// which may potentially be null
 /// with its coordinates formatted to two
 /// decimal places.
 /// </summary>
 public static string BoundingBoxString2( BoundingBoxXYZ bb )
 {
     return null == bb
     ? "<null>"
     : Util.BoundingBoxString( bb );
 }
        /// <summary>
        /// Return bounding box calculated from the room 
        /// boundary segments. The lower left corner turns 
        /// out to be identical with the one returned by 
        /// the standard room bounding box.
        /// </summary>
        static BoundingBoxXYZ GetBoundingBox(
            IList<IList<BoundarySegment>> boundary)
        {
            BoundingBoxXYZ bb = new BoundingBoxXYZ();
              double infinity = double.MaxValue;

              bb.Min = new XYZ( infinity, infinity, infinity );
              bb.Max = -bb.Min;

              foreach( IList<BoundarySegment> loop in boundary )
              {
            foreach( BoundarySegment seg in loop )
            {
              Curve c = seg.GetCurve();
              IList<XYZ> pts = c.Tessellate();
              foreach( XYZ p in pts )
              {
            bb.ExpandToContain( p );
              }
            }
              }
              return bb;
        }