Beispiel #1
0
        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="curves">curves represent the wireframe of the 2D geometry</param>
        public Graphics2DData(List <List <UV> > curves)
        {
            // initialize m_curves and m_bbox
            bool isFirst = true;    // is the first List<UV> instance in curves

            foreach (List <UV> uvs in curves)
            {
                PointF[] pnts = new PointF[uvs.Count];
                m_curves.Add(pnts);
                for (int i = 0; i < uvs.Count; i++)
                {
                    Autodesk.Revit.DB.UV uv = uvs[i];
                    pnts[i] = new PointF((float)uv.U, (float)uv.V);
                    RectangleF tmpBBox = new RectangleF(pnts[i], new SizeF(0.0f, 0.0f));
                    m_numPoints++;
                    if (!isFirst)
                    {
                        // union the m_bbox with next curve's BBox
                        m_bbox = RectangleF.Union(m_bbox, tmpBBox);
                    }
                    else
                    {
                        m_bbox  = tmpBBox;
                        isFirst = false;
                    }
                }
            }
        }
Beispiel #2
0
        private void InitSpace(
            DB.Level level,
            DB.UV point)
        {
            DB.Document document = DocumentManager.Instance.CurrentDBDocument;

            // This creates a new wall and deletes the old one
            TransactionManager.Instance.EnsureInTransaction(document);

            //Phase 1 - Check to see if the object exists and should be rebound
            var roomElem = ElementBinder.GetElementFromTrace <DB.Mechanical.Space>(document);

            if (roomElem == null)
            {
                roomElem = document.Create.NewSpace(level, point);
            }

            InternalSetSpace(roomElem);

            TransactionManager.Instance.TransactionTaskDone();

            if (roomElem != null)
            {
                ElementBinder.CleanupAndSetElementForTrace(document, this.InternalElement);
            }
            else
            {
                ElementBinder.SetElementForTrace(this.InternalElement);
            }
        }
Beispiel #3
0
        public static double GetLength(Autodesk.Revit.DB.UV vector)
        {
            double x = vector.U;
            double y = vector.V;

            return(Math.Sqrt(x * x + y * y));
        }
Beispiel #4
0
        /// <summary>
        /// Internal constructor for ReferencePoint Elements that a persistent relationship to a Face
        /// </summary>
        /// <param name="faceReference"></param>
        /// <param name="uv"></param>
        private ReferencePoint(Reference faceReference, UV uv)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldRefPt =
                ElementBinder.GetElementFromTrace<Autodesk.Revit.DB.ReferencePoint>(Document);

            //There was a point, rebind to that, and adjust its position
            if (oldRefPt != null)
            {
                InternalSetReferencePoint(oldRefPt);
                InternalSetPointOnFace(faceReference, uv);
                return;
            }

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

            var edgePoint = Document.Application.Create.NewPointOnFace(faceReference, uv);
            InternalSetReferencePoint(Document.FamilyCreate.NewReferencePoint(edgePoint));

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(InternalElement);

            // otherwise the point value is invalid for downstream requests
            DocumentManager.Regenerate();
        }
Beispiel #5
0
        /// <summary>
        /// Batch creation of Rooms
        /// </summary>
        /// <returns>If batch creation succeeds, return true; otherwise, return false</returns>
        private bool CreateRooms()
        {
            try
            {
                if (null == m_level)
                {
                    return(false);
                }

                //Try to get Phase used to create Rooms
                Phase phase = (from elem in
                               new FilteredElementCollector(m_doc).OfClass(typeof(Phase)).ToElements()
                               select elem).First() as Phase;

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

                for (int i = 1; i < 6; i++)
                {
                    Autodesk.Revit.DB.UV point               = new Autodesk.Revit.DB.UV(i * 10, 0);
                    Autodesk.Revit.DB.UV tagPoint            = new Autodesk.Revit.DB.UV(i * 10, 0);
                    Autodesk.Revit.DB.Architecture.Room room = m_doc.Create.NewRoom(m_level, point);
                }
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
Beispiel #6
0
        public static Autodesk.Revit.DB.UV AddXYZ(Autodesk.Revit.DB.UV p1, Autodesk.Revit.DB.UV p2)
        {
            double x = p1.U + p2.U;
            double y = p1.V + p2.V;

            return(new Autodesk.Revit.DB.UV(x, y));
        }
Beispiel #7
0
        /// <summary>
        /// create 2 braces between the mid point of 2 column and the mid point of adjoining beam
        /// </summary>
        /// <param name="point2D1">first point of the location line in 2D</param>
        /// <param name="point2D2">second point of the location line in 2D</param>
        /// <param name="baseLevel">the base level of the brace</param>
        /// <param name="topLevel">the top level of the brace</param>
        private List <FamilyInstance> NewBraces(Autodesk.Revit.DB.UV point2D1, Autodesk.Revit.DB.UV point2D2, Level baseLevel, Level topLevel)
        {
            // calculate the start point and end point of the location lines of two braces
            double topHeight       = topLevel.Elevation;
            double baseHeight      = baseLevel.Elevation;
            double middleElevation = (topHeight + baseHeight) / 2;

            Autodesk.Revit.DB.XYZ startPoint  = new Autodesk.Revit.DB.XYZ(point2D1.U, point2D1.V, middleElevation);
            Autodesk.Revit.DB.XYZ endPoint    = new Autodesk.Revit.DB.XYZ(point2D2.U, point2D2.V, middleElevation);
            Autodesk.Revit.DB.XYZ middlePoint = new Autodesk.Revit.DB.XYZ((point2D1.U + point2D2.U) / 2, (point2D1.V + point2D2.V) / 2, topHeight);

            Autodesk.Revit.DB.ElementId levelId = topLevel.Id;
            // create two brace; then set their location line and reference level
            Line           firstBaseLine = Line.CreateBound(startPoint, middlePoint);
            FamilyInstance firstBrace    =
                m_docCreator.NewFamilyInstance(firstBaseLine, m_data.BraceSymbol, topLevel, StructuralType.Brace);

            Line           secondBaseLine = Line.CreateBound(endPoint, middlePoint);
            FamilyInstance secondBrace    =
                m_docCreator.NewFamilyInstance(secondBaseLine, m_data.BraceSymbol, topLevel, StructuralType.Brace);
            List <FamilyInstance> result = new List <FamilyInstance>();

            result.Add(firstBrace);
            result.Add(secondBrace);
            return(result);
        }
Beispiel #8
0
        /// <summary>
        /// Utility node to double check how many plan circuits exist, and where they are located.
        /// </summary>
        /// <param name="view">The view to check.</param>
        /// <returns></returns>
        public static List <Autodesk.DesignScript.Geometry.Point> GetCircuitPoints(Revit.Elements.Views.FloorPlanView view)
        {
            var dDoc = DocumentManager.Instance.CurrentDBDocument;
            var cDoc = dDoc.Create;

            // Extract the Revit objects from the view and room
            var iView = view.InternalElement as Autodesk.Revit.DB.ViewPlan;

            // Get the target topology and plan circuits
            var topology = dDoc.get_PlanTopology(iView.GenLevel);
            var circuits = topology.Circuits;

            var points  = new List <Autodesk.DesignScript.Geometry.Point>();
            var borders = new List <Autodesk.DesignScript.Geometry.Curve>();

            foreach (PlanCircuit pc in circuits)
            {
                Autodesk.Revit.DB.UV uv = pc.GetPointInside();
                var newU = UnitUtils.ConvertFromInternalUnits(uv.U, DisplayUnitType.DUT_MILLIMETERS);
                var newV = UnitUtils.ConvertFromInternalUnits(uv.V, DisplayUnitType.DUT_MILLIMETERS);
                //Autodesk.Revit.DB.XYZ xyz = new XYZ(uv.U, uv.V, baseLevel.Elevation);

                points.Add(Autodesk.DesignScript.Geometry.Point.ByCoordinates(newU, newV));
            }

            return(points);
        }
Beispiel #9
0
        /// <summary>
        /// Auto tag rooms with specified RoomTagType in a level
        /// </summary>
        /// <param name="level">The level where rooms will be auto tagged</param>
        /// <param name="tagType">The room tag type</param>
        public void AutoTagRooms(Level level, RoomTagType tagType)
        {
            PlanTopology planTopology = m_revit.ActiveUIDocument.Document.get_PlanTopology(level);

            SubTransaction subTransaction = new SubTransaction(m_revit.ActiveUIDocument.Document);

            subTransaction.Start();
            foreach (ElementId eid in planTopology.GetRoomIds())
            {
                Room tmpRoom = m_revit.ActiveUIDocument.Document.GetElement(eid) as Room;

                if (m_revit.ActiveUIDocument.Document.GetElement(tmpRoom.LevelId) != null && tmpRoom.Location != null)
                {
                    // Create a specified type RoomTag to tag a room
                    LocationPoint        locationPoint = tmpRoom.Location as LocationPoint;
                    Autodesk.Revit.DB.UV point         = new Autodesk.Revit.DB.UV(locationPoint.Point.X, locationPoint.Point.Y);
                    RoomTag newTag = m_revit.ActiveUIDocument.Document.Create.NewRoomTag(new LinkElementId(tmpRoom.Id), point, null);
                    newTag.RoomTagType = tagType;

                    List <RoomTag> tagListInTheRoom = m_roomWithTags[newTag.Room.Id];
                    tagListInTheRoom.Add(newTag);
                }
            }
            subTransaction.Commit();
        }
Beispiel #10
0
        /// <summary>
        /// Initialize a ReferencePoint element
        /// </summary>
        /// <param name="faceReference"></param>
        /// <param name="uv"></param>
        private void InitReferencePoint(Reference faceReference, UV uv)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldRefPt =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.ReferencePoint>(Document);

            //There was a point, rebind to that, and adjust its position
            if (oldRefPt != null)
            {
                InternalSetReferencePoint(oldRefPt);
                InternalSetPointOnFace(faceReference, uv);
                return;
            }

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

            var edgePoint = Document.Application.Create.NewPointOnFace(faceReference, uv);

            InternalSetReferencePoint(Document.FamilyCreate.NewReferencePoint(edgePoint));

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(InternalElement);

            // otherwise the point value is invalid for downstream requests
            DocumentManager.Regenerate();
        }
Beispiel #11
0
        /// <summary>
        /// Draw the curves of path reinforcement.
        /// </summary>
        /// <param name="graphics">Gdi object, used to draw curves of path reinforcement.</param>
        /// <param name="size">Bound to limit the size of the whole picture</param>
        /// <param name="pen">Gdi object,determine the color of the line.</param>
        public void Draw(Graphics graphics, Size size, Pen pen)
        {
            Autodesk.Revit.DB.UV delta = m_box.Max - m_box.Min;
            float scaleX = size.Width / (float)delta.U;
            float scaleY = size.Width / (float)delta.V;
            float scale  = scaleY > scaleX ? scaleX : scaleY;

            scale *= 0.90f;

            GraphicsContainer contain = graphics.BeginContainer();

            {
                //set graphics coordinate system to picture center
                //and  flip the yAxis.
                graphics.Transform = new Matrix(1, 0, 0, -1, size.Width / 2, size.Height / 2);

                //construct a matrix to transform the origin point to Bound center.
                Autodesk.Revit.DB.UV center = (m_box.Min + m_box.Max) / 2;
                Matrix toCenter             = new Matrix(1, 0, 0, 1, -(float)center.U, -(float)center.V);

                bool isDrawFinished       = false;
                List <List <UV> > point2d = m_point2d;
                Pen tmpPen = pen;

                while (!isDrawFinished)
                {
                    foreach (List <UV> arr in point2d)
                    {
                        for (int i = 0; i < arr.Count - 1; i++)
                        {
                            //get the two connection points to draw a line between them.
                            Autodesk.Revit.DB.UV uv1    = arr[i];
                            Autodesk.Revit.DB.UV uv2    = arr[i + 1];
                            PointF[]             points = new PointF[] {
                                new PointF((float)uv1.U, (float)uv1.V),
                                new PointF((float)uv2.U, (float)uv2.V)
                            };

                            //transform points to bound center.
                            toCenter.TransformPoints(points);

                            //Zoom(Scale) the points to fit the picture box.
                            PointF pf1 = new PointF(points[0].X * scale, points[0].Y * scale);
                            PointF pf2 = new PointF(points[1].X * scale, points[1].Y * scale);

                            //draw a line between pf1 and pf2.
                            graphics.DrawLine(tmpPen, pf1, pf2);
                        }
                    }
                    if (point2d == m_path2d)
                    {
                        isDrawFinished = true;
                    }
                    point2d = m_path2d;
                    tmpPen  = Pens.Blue;
                }
            }
            graphics.EndContainer(contain);
        }
Beispiel #12
0
        /// <summary>
        /// This method adds the collection of views to the existing ViewSheet and packs them
        /// </summary>
        /// <param name="views"></param>
        private void InternalAddViewsToSheetView(IEnumerable <Autodesk.Revit.DB.View> views)
        {
            var sheet = InternalViewSheet;

            TransactionManager.Instance.EnsureInTransaction(Document);

            // (sic) from Dynamo Legacy
            var width  = sheet.Outline.Max.U - sheet.Outline.Min.U;
            var height = sheet.Outline.Max.V - sheet.Outline.Min.V;
            var packer = new CygonRectanglePacker(width, height);
            int count  = 0;

            foreach (var view in views)
            {
                var viewWidth  = view.Outline.Max.U - view.Outline.Min.U;
                var viewHeight = view.Outline.Max.V - view.Outline.Min.V;

                Autodesk.Revit.DB.UV placement = null;
                if (packer.TryPack(viewWidth, viewHeight, out placement))
                {
                    var dbViews = sheet.GetAllPlacedViews().Select(x => Document.GetElement(x)).
                                  OfType <Autodesk.Revit.DB.View>();
                    if (dbViews.Contains(view))
                    {
                        //move the view
                        //find the corresponding viewport
                        var enumerable =
                            DocumentManager.Instance.ElementsOfType <Autodesk.Revit.DB.Viewport>()
                            .Where(x => x.SheetId == sheet.Id && x.ViewId == view.Id).ToArray();

                        if (!enumerable.Any())
                        {
                            continue;
                        }

                        var viewport = enumerable.First();
                        viewport.SetBoxCenter(new XYZ(placement.U + viewWidth / 2, placement.V + viewHeight / 2, 0));
                    }
                    else
                    {
                        //place the view on the sheet
                        if (Autodesk.Revit.DB.Viewport.CanAddViewToSheet(Document, sheet.Id, view.Id))
                        {
                            var viewport = Autodesk.Revit.DB.Viewport.Create(Document, sheet.Id, view.Id,
                                                                             new XYZ(placement.U + viewWidth / 2, placement.V + viewHeight / 2, 0));
                        }
                    }
                }
                else
                {
                    throw new Exception(String.Format("View {0} could not be packed on the Sheet.  The sheet is {1} x {2} and the view to be added is {3} x {4}",
                                                      count, width, height, viewWidth, viewHeight));
                }

                count++;
            }

            TransactionManager.Instance.TransactionTaskDone();
        }
Beispiel #13
0
        public static bool IsSameDirection(UV firstVec, UV secondVec)
        {
            Autodesk.Revit.DB.UV first  = UnitVector(firstVec);
            Autodesk.Revit.DB.UV second = UnitVector(secondVec);
            double dot = DotMatrix(first, second);

            return(IsEqual(dot, 1));
        }
Beispiel #14
0
        public static bool IsEqual(Autodesk.Revit.DB.UV first, Autodesk.Revit.DB.UV second)
        {
            bool flag = true;

            flag = flag && IsEqual(first.U, second.U);
            flag = flag && IsEqual(first.V, second.V);
            return(flag);
        }
Beispiel #15
0
        /// <summary>
        /// Create a Room
        /// based on a location and a level
        /// </summary>
        /// <param name="point">Location point for the room</param>
        /// <param name="level">Level of the room</param>
        /// <returns></returns>
        public static CustomRoom ByPointAndLevel(Point point, Level level)
        {
            DB.Level revitLevel = level.InternalElement as DB.Level;
            DB.XYZ   revitPoint = GeometryPrimitiveConverter.ToXyz(point);

            DB.UV uv = new DB.UV(revitPoint.X, revitPoint.Y);

            return(new CustomRoom(revitLevel, uv));
        }
Beispiel #16
0
        /// <summary>
        /// Create a `MEP Space
        /// based on a location
        /// </summary>
        /// <param name="point">Location point for the space</param>
        /// <returns></returns>
        public static Space ByPoint(Point point)
        {
            DB.XYZ   revitPoint = GeometryPrimitiveConverter.ToXyz(point);
            DB.Level revitLevel = GetNearestLevel(revitPoint);

            DB.UV uv = new DB.UV(revitPoint.X, revitPoint.Y);

            return(new Space(revitLevel, uv));
        }
Beispiel #17
0
        public static bool IsSameOrOppositeDirection(UV firstVec, UV secondVec)
        {
            Autodesk.Revit.DB.UV first  = UnitVector(firstVec);
            Autodesk.Revit.DB.UV second = UnitVector(secondVec);

            // if the dot product of two unit vectors is equal to 1, return true
            double dot = DotMatrix(first, second);

            return(IsEqual(dot, 1) || IsEqual(dot, -1));
        }
Beispiel #18
0
        private void InternalSetPointOnFace(Reference faceReference, UV uv)
        {
            TransactionManager.Instance.EnsureInTransaction(Document);

            var edgePoint = Document.Application.Create.NewPointOnFace(faceReference, uv);

            InternalReferencePoint.SetPointElementReference(edgePoint);

            TransactionManager.Instance.TransactionTaskDone();
        }
Beispiel #19
0
        public static bool IsOppositeDirection(Autodesk.Revit.DB.UV firstVec, Autodesk.Revit.DB.UV secondVec)
        {
            // get the unit vector for two vectors
            Autodesk.Revit.DB.UV first  = UnitVector(firstVec);
            Autodesk.Revit.DB.UV second = UnitVector(secondVec);

            // if the dot product of two unit vectors is equal to -1, return true
            double dot = DotMatrix(first, second);

            return(IsEqual(dot, -1));
        }
Beispiel #20
0
        public static Autodesk.Revit.DB.UV UnitVector(Autodesk.Revit.DB.UV vector)
        {
            // calculate the distance from grid origin to the XYZ
            double length = GetLength(vector);

            // changed the vector into the unit length
            double x = vector.U / length;
            double y = vector.V / length;

            return(new Autodesk.Revit.DB.UV(x, y));
        }
Beispiel #21
0
        /// <summary>
        /// create brace of certain type in certain position between two adjacent columns
        /// </summary>
        /// <param name="point2D1">one point of the location line in 2D</param>
        /// <param name="point2D2">another point of the location line in 2D</param>
        /// <param name="baseLevel">the base level of the brace</param>
        /// <param name="topLevel">the top level of the brace</param>
        /// <param name="braceType">type of beam</param>
        /// <param name="isXDirection">whether the location line is in x direction</param>
        private void PlaceBrace(Autodesk.Revit.DB.UV point2D1, Autodesk.Revit.DB.UV point2D2, Level baseLevel, Level topLevel, FamilySymbol braceType, bool isXDirection)
        {
            //get the start points and end points of location lines of two braces
            double topHeight       = topLevel.Elevation;
            double baseHeight      = baseLevel.Elevation;
            double middleElevation = (topHeight + baseHeight) / 2;
            double middleHeight    = (topHeight - baseHeight) / 2;

            Autodesk.Revit.DB.XYZ startPoint = new Autodesk.Revit.DB.XYZ(point2D1.U, point2D1.V, middleElevation);
            Autodesk.Revit.DB.XYZ endPoint   = new Autodesk.Revit.DB.XYZ(point2D2.U, point2D2.V, middleElevation);
            Autodesk.Revit.DB.XYZ middlePoint;

            if (isXDirection)
            {
                middlePoint = new Autodesk.Revit.DB.XYZ((point2D1.U + point2D2.U) / 2, point2D2.V, topHeight);
            }
            else
            {
                middlePoint = new Autodesk.Revit.DB.XYZ(point2D2.U, (point2D1.V + point2D2.V) / 2, topHeight);
            }

            //create two brace and set their location line
            STRUCTURALTYPE structuralType = Autodesk.Revit.DB.Structure.StructuralType.Brace;

            Autodesk.Revit.DB.ElementId levelId      = topLevel.Id;
            Autodesk.Revit.DB.ElementId startLevelId = baseLevel.Id;
            Autodesk.Revit.DB.ElementId endLevelId   = topLevel.Id;

            Line line1 = Line.CreateBound(startPoint, middlePoint);

            if (!braceType.IsActive)
            {
                braceType.Activate();
            }
            FamilyInstance firstBrace = m_revit.ActiveUIDocument.Document.Create.NewFamilyInstance(line1, braceType, baseLevel, structuralType);

            Parameter referenceLevel1 = firstBrace.get_Parameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM);

            if (null != referenceLevel1)
            {
                referenceLevel1.Set(levelId);
            }

            Line           line2       = Line.CreateBound(endPoint, middlePoint);
            FamilyInstance secondBrace = m_revit.ActiveUIDocument.Document.Create.NewFamilyInstance(line2, braceType, baseLevel, structuralType);

            Parameter referenceLevel2 = secondBrace.get_Parameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM);

            if (null != referenceLevel2)
            {
                referenceLevel2.Set(levelId);
            }
        }
Beispiel #22
0
        /// <summary>
        /// generate 2D coordinates of matrix according to parameters
        /// </summary>
        /// <param name="xNumber">Number of Columns in the X direction</param>
        /// <param name="yNumber">Number of Columns in the Y direction</param>
        /// <param name="distance">Distance between columns</param>
        public void CreateMatrix(int xNumber, int yNumber, double distance)
        {
            m_matrixUV = new Autodesk.Revit.DB.UV[xNumber, yNumber];

            for (int i = 0; i < xNumber; i++)
            {
                for (int j = 0; j < yNumber; j++)
                {
                    m_matrixUV[i, j] = new Autodesk.Revit.DB.UV(i * distance, j * distance);
                }
            }
        }
Beispiel #23
0
        /// <summary>
        /// create a 2D matrix of coordinates to form an array format
        /// </summary>
        /// <param name="xNumber">number of Columns in the X direction</param>
        /// <param name="yNumber">number of Columns in the Y direction</param>
        /// <param name="distance">distance between columns</param>
        private static Autodesk.Revit.DB.UV[,] CreateMatrix(int xNumber, int yNumber, double distance)
        {
            Autodesk.Revit.DB.UV[,] result = new Autodesk.Revit.DB.UV[xNumber, yNumber];

            for (int i = 0; i < xNumber; i++)
            {
                for (int j = 0; j < yNumber; j++)
                {
                    result[i, j] = new Autodesk.Revit.DB.UV(i * distance, j * distance);
                }
            }
            return(result);
        }
Beispiel #24
0
        /// <summary>
        /// create beam of certain type in certain position
        /// </summary>
        /// <param name="point2D1">one point of the location line in 2D</param>
        /// <param name="point2D2">another point of the location line in 2D</param>
        /// <param name="baseLevel">the base level of the beam</param>
        /// <param name="topLevel">the top level of the beam</param>
        /// <param name="beamType">type of beam</param>
        /// <returns>nothing</returns>
        private void PlaceBeam(Autodesk.Revit.DB.UV point2D1, Autodesk.Revit.DB.UV point2D2, Level baseLevel, Level topLevel, FamilySymbol beamType)
        {
            double height = topLevel.Elevation;

            Autodesk.Revit.DB.XYZ       startPoint = new Autodesk.Revit.DB.XYZ(point2D1.U, point2D1.V, height);
            Autodesk.Revit.DB.XYZ       endPoint   = new Autodesk.Revit.DB.XYZ(point2D2.U, point2D2.V, height);
            Autodesk.Revit.DB.ElementId topLevelId = topLevel.Id;

            Line           line           = Line.CreateBound(startPoint, endPoint);
            STRUCTURALTYPE structuralType = Autodesk.Revit.DB.Structure.StructuralType.Beam;

            m_revit.ActiveUIDocument.Document.Create.NewFamilyInstance(line, beamType, topLevel, structuralType);
        }
Beispiel #25
0
        public static double DotMatrix(Autodesk.Revit.DB.UV p1, Autodesk.Revit.DB.UV p2)
        {
            //get the coordinate of the Autodesk.Revit.DB.XYZ
            double v1 = p1.U;
            double v2 = p1.V;


            double u1 = p2.U;
            double u2 = p2.V;


            return(v1 * u1 + v2 * u2);
        }
Beispiel #26
0
        /// <summary>
        /// Frame a Wall
        /// </summary>
        /// <param name="rvtApp">Revit application></param>
        /// <param name="wall">Wall as host to place column objects</param>
        /// <param name="spacing">spacing between two columns</param>
        /// <param name="columnType">column type</param>
        private void FrameWall(Autodesk.Revit.ApplicationServices.Application rvtApp, Autodesk.Revit.DB.Wall wall,
                               double spacing, Autodesk.Revit.DB.FamilySymbol columnType)
        {
            Autodesk.Revit.DB.Document rvtDoc = wall.Document;

            // get wall location
            Autodesk.Revit.DB.LocationCurve loc     = (Autodesk.Revit.DB.LocationCurve)wall.Location;
            Autodesk.Revit.DB.XYZ           startPt = loc.Curve.GetEndPoint(0);
            Autodesk.Revit.DB.XYZ           endPt   = loc.Curve.GetEndPoint(1);

            // get wall's vector
            Autodesk.Revit.DB.UV wallVec = new Autodesk.Revit.DB.UV(
                endPt.X - startPt.X,
                endPt.Y - startPt.Y);

            // get the axis vector
            Autodesk.Revit.DB.UV axis = new Autodesk.Revit.DB.UV(1.0, 0.0);

            Autodesk.Revit.DB.ElementId baseLevelId = wall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId();
            Autodesk.Revit.DB.ElementId topLevelId  = wall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).AsElementId();

            // get wall length and vector
            double wallLength = wallVec.GetLength();

            wallVec = wallVec.Normalize();

            // get # of column
            int nmax = (int)(wallLength / spacing);

            TaskDialog.Show("Revit", "wallLength = " + wallLength + "\r\nspacing = " + spacing.ToString() + "\r\nnmax = " + nmax.ToString());

            // get angle of wall and axis
            double angle = wallVec.AngleTo(axis);

            // place all column
            Autodesk.Revit.DB.XYZ loc2 = startPt;
            double dx = wallVec.U * spacing;
            double dy = wallVec.V * spacing;

            for (int i = 0; i < nmax; i++)
            {
                PlaceColumn(rvtApp, rvtDoc, loc2, angle, columnType, baseLevelId, topLevelId);

                loc2 = new XYZ(loc2.X + dx,
                               loc2.Y + dy,
                               loc2.Z);
            }

            // place column at end point of wall
            PlaceColumn(rvtApp, rvtDoc, endPt, angle, columnType, baseLevelId, topLevelId);
        }
Beispiel #27
0
        /// <summary>
        /// create beam of certain type in given position
        /// </summary>
        /// <param name="point2D1">first point of the location line in 2D</param>
        /// <param name="point2D2">second point of the location line in 2D</param>
        /// <param name="baseLevel">base level of the beam</param>
        /// <param name="topLevel">top level of the beam</param>
        /// <returns>nothing</returns>
        private FamilyInstance NewBeam(Autodesk.Revit.DB.UV point2D1, Autodesk.Revit.DB.UV point2D2, Level topLevel)
        {
            // calculate the start point and end point of Beam's location line in 3D
            double height = topLevel.Elevation;

            Autodesk.Revit.DB.XYZ startPoint = new Autodesk.Revit.DB.XYZ(point2D1.U, point2D1.V, height);
            Autodesk.Revit.DB.XYZ endPoint   = new Autodesk.Revit.DB.XYZ(point2D2.U, point2D2.V, height);
            // create Beam and set its location
            Line           baseLine = Line.CreateBound(startPoint, endPoint);
            FamilyInstance beam     =
                m_docCreator.NewFamilyInstance(baseLine, m_data.BeamSymbol, topLevel, StructuralType.Beam);

            return(beam);
        }
Beispiel #28
0
        /// <summary>
        /// Compute the bound of the curves of path reinforcement.
        /// </summary>
        private void ComputeBound()
        {
            //make the bound
            Autodesk.Revit.DB.UV min = m_box.get_Bounds(0);
            Autodesk.Revit.DB.UV max = m_box.get_Bounds(1);

            Matrix4 transform = GetActiveViewMatrix().Inverse();

            bool isFirst = true;

            foreach (List <XYZ> arr in m_curves)
            {
                List <UV> uvarr = new List <UV>();
                foreach (Autodesk.Revit.DB.XYZ xyz in arr)
                {
                    Vector4 tmpVector          = transform.Transform(new Vector4(xyz));
                    Autodesk.Revit.DB.UV tmpUv = new Autodesk.Revit.DB.UV(
                        tmpVector.X,
                        tmpVector.Y);
                    uvarr.Add(tmpUv);

                    if (isFirst)
                    {
                        isFirst = false;
                        min     = new UV(tmpUv.U, tmpUv.V);
                        max     = new UV(tmpUv.U, tmpUv.V);
                    }
                    if (tmpUv.U < min.U)
                    {
                        min = new UV(tmpUv.U, min.V);
                    }
                    else if (tmpUv.U > max.U)
                    {
                        max = new UV(tmpUv.U, max.V);
                    }
                    if (tmpUv.V < min.V)
                    {
                        min = new UV(min.U, tmpUv.V);
                    }
                    else if (tmpUv.V > max.V)
                    {
                        max = new UV(max.U, tmpUv.V);
                    }
                }
                m_point2d.Add(uvarr);
            }
            m_box.Min = min;
            m_box.Max = max;
        }
Beispiel #29
0
        /// <summary>
        /// Create a MEP Space
        /// based on a location and a level
        /// </summary>
        /// <param name="point">Location point for the space</param>
        /// <param name="level">Level of the space</param>
        /// <returns></returns>
        public static Space ByPointAndLevel(Point point, Level level)
        {
            //Check if the level is in the document
            if (level.InternalElement.Document != DocumentManager.Instance.CurrentDBDocument)
            {
                throw new ArgumentException("The level does not exist in the given document");
            }

            DB.Level revitLevel = level.InternalElement as DB.Level;
            DB.XYZ   revitPoint = GeometryPrimitiveConverter.ToXyz(point);

            DB.UV uv = new DB.UV(revitPoint.X, revitPoint.Y);

            return(new Space(revitLevel, uv));
        }
Beispiel #30
0
        /// <summary>
        /// create column of certain type in given position
        /// </summary>
        /// <param name="point2D">2D coordinate of the column</param>
        /// <param name="columnType">specified type of the column</param>
        /// <param name="baseLevel">base level of the column</param>
        /// <param name="topLevel">top level of the colunm</param>
        private FamilyInstance NewColumn(Autodesk.Revit.DB.UV point2D, Level baseLevel, Level topLevel)
        {
            //create column of specified type with certain level and start point
            Autodesk.Revit.DB.XYZ point = new Autodesk.Revit.DB.XYZ(point2D.U, point2D.V, 0);

            FamilyInstance column =
                m_docCreator.NewFamilyInstance(point, m_data.ColumnSymbol, baseLevel, StructuralType.Column);

            //set baselevel & toplevel of the column
            SetParameter(column, BuiltInParameter.FAMILY_TOP_LEVEL_PARAM, topLevel.Id);
            SetParameter(column, BuiltInParameter.FAMILY_BASE_LEVEL_PARAM, baseLevel.Id);
            SetParameter(column, BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM, 0.0);
            SetParameter(column, BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM, 0.0);
            return(column);
        }
        /// <summary>
        /// Batch creation of Rooms
        /// </summary>
        /// <returns>If batch creation succeeds, return true; otherwise, return false</returns>
        private bool CreateRooms()
        {
            try
            {
                if (null == m_level)
                {
                    return(false);
                }

                //Try to get Phase used to create Rooms
                Phase phase = (from elem in
                               new FilteredElementCollector(m_doc).OfClass(typeof(Phase)).ToElements()
                               select elem).First() as Phase;

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

                // Create AreaCreateDatas for Rooms' batch creation
                List <RoomCreationData> roomCreationDatas = new List <RoomCreationData>();
                for (int i = 1; i < 6; i++)
                {
                    Autodesk.Revit.DB.UV point            = new Autodesk.Revit.DB.UV(i * 10, 0);
                    Autodesk.Revit.DB.UV tagPoint         = new Autodesk.Revit.DB.UV(i * 10, 0);
                    RoomCreationData     roomCreationData = new RoomCreationData(m_level, point);
                    if (null != roomCreationData)
                    {
                        roomCreationData.TagPoint = tagPoint;
                        roomCreationDatas.Add(roomCreationData);
                    }
                }

                // Create Rooms
                if (0 == roomCreationDatas.Count)
                {
                    return(false);
                }
                m_doc.Create.NewRooms(roomCreationDatas);
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
Beispiel #32
0
        private void InternalSetPointOnFace(Reference faceReference, UV uv)
        {
            TransactionManager.Instance.EnsureInTransaction(Document);

            var edgePoint = Document.Application.Create.NewPointOnFace(faceReference, uv);
            InternalReferencePoint.SetPointElementReference(edgePoint);

            TransactionManager.Instance.TransactionTaskDone();
        }
Beispiel #33
0
        /// <summary>
        /// Auto tag rooms with specified RoomTagType in a level
        /// </summary>
        /// <param name="level">The level where rooms will be auto tagged</param>
        /// <param name="tagType">The room tag type</param>
        public void AutoTagRooms(Level level, RoomTagType tagType)
        {
            PlanTopology planTopology = m_revit.ActiveUIDocument.Document.get_PlanTopology(level);

            SubTransaction subTransaction = new SubTransaction(m_revit.ActiveUIDocument.Document);
            subTransaction.Start();
            foreach (Room tmpRoom in planTopology.Rooms)
            {
                if (tmpRoom.Level != null && tmpRoom.Location != null)
                {
                    // Create a specified type RoomTag to tag a room
                    LocationPoint locationPoint = tmpRoom.Location as LocationPoint;
                    Autodesk.Revit.DB.UV point = new Autodesk.Revit.DB.UV (locationPoint.Point.X, locationPoint.Point.Y);
                    RoomTag newTag = m_revit.ActiveUIDocument.Document.Create.NewRoomTag(tmpRoom, point, null);
                    newTag.RoomTagType = tagType;

                    List<RoomTag> tagListInTheRoom = m_roomWithTags[newTag.Room.Id.IntegerValue];
                    tagListInTheRoom.Add(newTag);
                }

            }
            subTransaction.Commit();
        }
Beispiel #34
0
        /// <summary>
        /// Place all selected views on this sheet's appropriate location.
        /// </summary>
        /// <param name="views">all selected views</param>
        /// <param name="sheet">all views located sheet</param>
        private void PlaceViews(ViewSet views, ViewSheet sheet)
        {
            double xDistance = 0;
            double yDistance = 0;
            CalculateDistance(sheet.Outline, views.Size, ref xDistance, ref yDistance);

            Autodesk.Revit.DB.UV origin = GetOffSet(sheet.Outline, xDistance, yDistance);
            //Autodesk.Revit.DB.UV temp = new Autodesk.Revit.DB.UV (origin.U, origin.V);
            double tempU = origin.U;
            double tempV = origin.V;
            int n = 1;
            foreach (Autodesk.Revit.DB.View v in views)
            {
                Autodesk.Revit.DB.UV location = new Autodesk.Revit.DB.UV (tempU, tempV);
                Autodesk.Revit.DB.View view = v;
                Rescale(view, xDistance, yDistance);
                try
                {
                    sheet.AddView(view, location);
                }
                catch (ArgumentException /*ae*/)
                {
                    throw new InvalidOperationException("The view '" + view.Name +
                        "' can't be added, it may have already been placed in another sheet.");
                }

                if (0 != n++ % m_rows)
                {
                    tempU = tempU + xDistance * (1 - TITLEBAR);
                }
                else
                {
                    tempU = origin.U;
                    tempV = tempV + yDistance;
                }
            }
        }
Beispiel #35
0
        /// <summary>
        /// Compute the bound of the curves of path reinforcement.
        /// </summary>
        private void ComputeBound()
        {
            //make the bound
            Autodesk.Revit.DB.UV min = m_box.get_Bounds(0);
            Autodesk.Revit.DB.UV max = m_box.get_Bounds(1);

            Matrix4 transform = GetActiveViewMatrix().Inverse();

            bool isFirst = true;
            foreach (List<XYZ> arr in m_curves)
            {
                List<UV> uvarr = new List<UV>();
                foreach (Autodesk.Revit.DB.XYZ xyz in arr)
                {
                    Vector4 tmpVector = transform.Transform(new Vector4(xyz));
                    Autodesk.Revit.DB.UV tmpUv = new Autodesk.Revit.DB.UV(
                        tmpVector.X,
                        tmpVector.Y);
                    uvarr.Add(tmpUv);

                    if (isFirst)
                    {
                        isFirst = false;
                        min = new UV(tmpUv.U, tmpUv.V);
                        max = new UV(tmpUv.U, tmpUv.V);
                    }
                    if (tmpUv.U < min.U)
                    {
                        min = new UV(tmpUv.U, min.V);
                    }
                    else if (tmpUv.U > max.U)
                    {
                        max = new UV(tmpUv.U, max.V);
                    }
                    if (tmpUv.V < min.V)
                    {
                        min = new UV(min.U, tmpUv.V);
                    }
                    else if (tmpUv.V > max.V)
                    {
                        max = new UV(max.U, tmpUv.V);
                    }
                }
                m_point2d.Add(uvarr);
            }
            m_box.Min = min;
            m_box.Max = max;
        }
Beispiel #36
0
        /// <summary>
        /// generate 2D coordinates of matrix according to parameters
        /// </summary>
        /// <param name="xNumber">Number of Columns in the X direction</param>
        /// <param name="yNumber">Number of Columns in the Y direction</param>
        /// <param name="distance">Distance between columns</param>
        public void CreateMatrix(int xNumber, int yNumber, double distance)
        {
            m_matrixUV = new Autodesk.Revit.DB.UV [xNumber, yNumber];

            for(int i = 0; i < xNumber; i++)
            {
                for(int j = 0; j < yNumber; j++)
                {
                    m_matrixUV[i, j] = new Autodesk.Revit.DB.UV (i * distance, j * distance);
                }
            }
        }
        /// <summary>
        /// Returns a vector represnting the normal of an analysis surface.  Useful for sorting/grouping surfaces upstream of a SetSurfaceParameters node.
        /// </summary>
        /// <param name="SurfaceId">The ElementId of the surface to create a vector from.  Get this from AnalysisZones > CreateFrom* > SurfaceIds output list</param>
        /// <returns></returns>
        public static Autodesk.DesignScript.Geometry.Vector AnalysisSurfaceVector(ElementId SurfaceId)
        {
            //local varaibles
            Document RvtDoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument.Document;
            MassSurfaceData surf = null;
            Autodesk.Revit.DB.ElementId myEnergyModelId = null;

            //try to get the MassSurfaceData object from the document
            try
            {
                surf = (MassSurfaceData)RvtDoc.GetElement(new Autodesk.Revit.DB.ElementId(SurfaceId.InternalId));
                if (surf == null) throw new Exception();
            }
            catch (Exception)
            {
                throw new Exception("Couldn't find a MassSurfaceData object with Id #: " + SurfaceId.ToString());
            }

            //try to get the element id of the MassEnergyAnalyticalModel - we need this to pull faces from
            try
            {
                myEnergyModelId = surf.ReferenceElementId;
                if (myEnergyModelId == null) throw new Exception();
            }
            catch (Exception)
            {
                throw new Exception("Couldn't find a MassEnergyAnalyticalModel object belonging to the Mass instance with Id #: " + surf.ReferenceElementId.ToString());
            }

            //try to get the MassSurfaceData object from the document
            try
            {
                surf = (MassSurfaceData)RvtDoc.GetElement(new Autodesk.Revit.DB.ElementId(SurfaceId.InternalId));
                if (surf == null) throw new Exception();
            }
            catch (Exception)
            {
                throw new Exception("Couldn't find a MassSurfaceData object with Id #: " + SurfaceId.ToString());
            }

            //get the smallest face
            Autodesk.Revit.DB.Face bigFace = GetLargestFace(RvtDoc, surf, myEnergyModelId);

            // Find the face normal at the center of the face
            BoundingBoxUV bbox = bigFace.GetBoundingBox();
            // center of the face in the UV of the face
            Autodesk.Revit.DB.UV center = new Autodesk.Revit.DB.UV((bbox.Max.U - bbox.Min.U) / 2 + bbox.Min.U, (bbox.Max.V - bbox.Min.V) / 2 + bbox.Min.V);
            XYZ faceNormal = bigFace.ComputeNormal(center);
            XYZ normal = faceNormal.Normalize();
            return Autodesk.DesignScript.Geometry.Vector.ByCoordinates(normal.X, normal.Y, normal.Z, true);
        }
Beispiel #38
0
        /// <summary>
        /// Create a Room
        /// based on a location and a level
        /// </summary>
        /// <param name="point">Location point for the room</param>
        /// <param name="level">Level of the room</param>
        /// <returns></returns>
        public static CustomRoom ByPointAndLevel(Point point, Level level)
        {
            DB.Level revitLevel = level.InternalElement as DB.Level;
            DB.XYZ revitPoint = GeometryPrimitiveConverter.ToXyz(point);

            DB.UV uv = new DB.UV(revitPoint.X, revitPoint.Y);

            return new CustomRoom(revitLevel, uv);
        }
Beispiel #39
0
        /// <summary>
        /// Convert a 2d array of doubles into an array of UV
        /// </summary>
        /// <param name="uvArr"></param>
        /// <returns></returns>
        internal static Autodesk.Revit.DB.UV[] ToUvs(this double[][] uvArr)
        {
            var uvs = new Autodesk.Revit.DB.UV[uvArr.Length];
            var count = 0;
            foreach (var row in uvArr)
            {
                if (row.Length != 2)
                {
                    throw new Exception("Each element of the input array should be length 2");
                }
                else
                {
                    uvs[count++] = new Autodesk.Revit.DB.UV(row[0], row[1]);
                }
            }

            return uvs;
        }
Beispiel #40
0
        /// <summary>
        /// Batch creation of Areas
        /// </summary>
        /// <returns>If batch creation succeeds, return true; otherwise, return false</returns>
        private bool CreateAreas()
        {
            try
            {
                if (null == m_viewPlan)
                {
                    return false;
                }

                List<AreaCreationData> areaCreationDatas = new List<AreaCreationData>();
                //Create AreaCreateDatas for Areas' batch creation
                for (int i = 1; i < 11; i++)
                {
                    Autodesk.Revit.DB.UV point = new Autodesk.Revit.DB.UV (i * -10, 100);
                    Autodesk.Revit.DB.UV tagPoint = new Autodesk.Revit.DB.UV (i * -10, 100);
                    AreaCreationData areaCreationData = new AreaCreationData(m_viewPlan, point);
                    if (null != areaCreationData)
                    {
                        areaCreationData.TagPoint = tagPoint;
                        areaCreationDatas.Add(areaCreationData);
                    }
                }

                // Create Areas
                if (0 == areaCreationDatas.Count)
                {
                    return false;
                }
                m_doc.Create.NewAreas(areaCreationDatas);
            }
            catch (Exception)
            {
                return false;
            }

            return true;
        }
Beispiel #41
0
        /// <summary>
        /// create a 2D matrix of coordinates to form an array format
        /// </summary>
        /// <param name="xNumber">number of Columns in the X direction</param>
        /// <param name="yNumber">number of Columns in the Y direction</param>
        /// <param name="distance">distance between columns</param>
        private static Autodesk.Revit.DB.UV[,] CreateMatrix(int xNumber, int yNumber, double distance)
        {
            Autodesk.Revit.DB.UV[,] result = new Autodesk.Revit.DB.UV[xNumber, yNumber];

            for (int i = 0; i < xNumber; i++)
            {
                for (int j = 0; j < yNumber; j++)
                {
                    result[i, j] = new Autodesk.Revit.DB.UV (i * distance, j * distance);
                }
            }
            return result;
        }
Beispiel #42
0
        /// <summary>
        /// Rescale the view's Scale value for suitable.
        /// </summary>
        /// <param name="view">The view to be located on sheet.</param>
        /// <param name="x">Distance in x axis between each view</param>
        /// <param name="y">Distance in y axis between each view</param>
        private static void Rescale(Autodesk.Revit.DB.View view, double x, double y)
        {
            double Rescale = 2;
            Autodesk.Revit.DB.UV outline = new Autodesk.Revit.DB.UV (view.Outline.Max.U - view.Outline.Min.U,
                view.Outline.Max.V - view.Outline.Min.V);

            if (outline.U > outline.V)
            {
                Rescale = outline.U / x * Rescale;
            }
            else
            {
                Rescale = outline.V / y * Rescale;
            }

            if (1 != view.Scale && 0 != Rescale)
            {
                view.Scale = (int)(view.Scale * Rescale);
            }
        }
Beispiel #43
0
        /// <summary>
        /// create the room tags for the rooms which lack room tag
        /// </summary>
        public void CreateTags()
        {
            try
            {
                foreach (Room tmpRoom in m_roomsWithoutTag)
                {
                    // get the location point of the room
                    LocationPoint locPoint = tmpRoom.Location as LocationPoint;
                    if (null == locPoint)
                    {
                        String roomId = "Room Id:  " + tmpRoom.Id.IntegerValue.ToString();
                        String errMsg = roomId + "\r\nFault to create room tag," +
                                                   "can't get the location point!";
                        throw new Exception(errMsg);
                    }

                    // create a instance of Autodesk.Revit.DB.UV class
                    Autodesk.Revit.DB.UV point = new Autodesk.Revit.DB.UV (locPoint.Point.X, locPoint.Point.Y);

                    //create room tag
                    RoomTag tmpTag;
                    tmpTag = m_revit.ActiveUIDocument.Document.Create.NewRoomTag(tmpRoom, point, null);
                    if (null != tmpTag)
                    {
                        m_roomTags.Add(tmpTag);
                    }
                }

                // classify rooms
                ClassifyRooms();

                // display a message box
                MessageBox.Show("Add room tags complete!", "Revit");
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "Revit");
            }
        }
        /// <summary>
        /// Frame a Wall
        /// </summary>
        /// <param name="rvtApp">Revit application></param>
        /// <param name="wall">Wall as host to place column objects</param>
        /// <param name="spacing">spacing between two columns</param>
        /// <param name="columnType">column type</param>
        private void FrameWall(Autodesk.Revit.ApplicationServices.Application rvtApp, Autodesk.Revit.DB.Wall wall,
            double spacing, Autodesk.Revit.DB.FamilySymbol columnType)
        {
            Autodesk.Revit.DB.Document rvtDoc = wall.Document;

            // get wall location
            Autodesk.Revit.DB.LocationCurve loc = (Autodesk.Revit.DB.LocationCurve)wall.Location;
            Autodesk.Revit.DB.XYZ startPt = loc.Curve.get_EndPoint(0);
            Autodesk.Revit.DB.XYZ endPt = loc.Curve.get_EndPoint(1);

            // get wall's vector
            Autodesk.Revit.DB.UV wallVec = new Autodesk.Revit.DB.UV(
                endPt.X - startPt.X,
                endPt.Y - startPt.Y);

            // get the axis vector
            Autodesk.Revit.DB.UV axis = new Autodesk.Revit.DB.UV(1.0, 0.0);

            Autodesk.Revit.DB.ElementId baseLevelId = wall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId();
            Autodesk.Revit.DB.ElementId topLevelId = wall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).AsElementId();

            // get wall length and vector
            double wallLength = wallVec.GetLength();
            wallVec = wallVec.Normalize();

            // get # of column
            int nmax = (int)(wallLength / spacing);

            MessageBox.Show("wallLength = " + wallLength + "\r\nspacing = " + spacing.ToString() + "\r\nnmax = " + nmax.ToString());

            // get angle of wall and axis
            double angle = wallVec.AngleTo(axis);

            // place all column
            Autodesk.Revit.DB.XYZ loc2 = startPt;
            double dx = wallVec.U * spacing;
            double dy = wallVec.V * spacing;
            for (int i = 0; i < nmax; i++)
            {
                PlaceColumn(rvtApp, rvtDoc, loc2, angle, columnType, baseLevelId, topLevelId);

                loc2 = new XYZ(loc2.X + dx,
                    loc2.Y + dy,
                    loc2.Z);
            }

            // place column at end point of wall
            PlaceColumn(rvtApp, rvtDoc, endPt, angle, columnType, baseLevelId, topLevelId);
        }
Beispiel #45
0
        /// <summary>
        /// Batch creation of Rooms
        /// </summary>
        /// <returns>If batch creation succeeds, return true; otherwise, return false</returns>
        private bool CreateRooms()
        {
            try
            {
                if (null == m_level)
                {
                    return false;
                }

                //Try to get Phase used to create Rooms
                Phase phase = (from elem in
                                   new FilteredElementCollector(m_doc).OfClass(typeof(Phase)).ToElements()
                               select elem).First() as Phase;

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

                // Create AreaCreateDatas for Rooms' batch creation
                List<RoomCreationData> roomCreationDatas = new List<RoomCreationData>();
                for (int i = 1; i < 6; i++)
                {
                    Autodesk.Revit.DB.UV point = new Autodesk.Revit.DB.UV (i * 10, 0);
                    Autodesk.Revit.DB.UV tagPoint = new Autodesk.Revit.DB.UV (i * 10, 0);
                    RoomCreationData roomCreationData = new RoomCreationData(m_level, point);
                    if (null != roomCreationData)
                    {
                        roomCreationData.TagPoint = tagPoint;
                        roomCreationDatas.Add(roomCreationData);
                    }
                }

                // Create Rooms
                if (0 == roomCreationDatas.Count)
                {
                    return false;
                }
                m_doc.Create.NewRooms(roomCreationDatas);
            }
            catch (Exception)
            {
                return false;
            }

            return true;
        }
Beispiel #46
0
        /// <summary>
        /// Create a Room
        /// based on a location
        /// </summary>
        /// <param name="point">Location point for the room</param>
        /// <returns></returns>
        public static CustomRoom ByPoint(Point point)
        {
            DB.XYZ revitPoint = GeometryPrimitiveConverter.ToXyz(point);
            DB.Level revitLevel = GetNearestLevel(revitPoint);

            DB.UV uv = new DB.UV(revitPoint.X, revitPoint.Y);

            return new CustomRoom(revitLevel, uv);
        }
Beispiel #47
0
        /// <summary>
        /// Create a MEP Space
        /// based on a location and a level
        /// </summary>
        /// <param name="point">Location point for the space</param>
        /// <param name="level">Level of the space</param>
        /// <returns></returns>
        public static Space ByPointAndLevel(Point point, Level level)
        {
            //Check if the level is in the document
            if (level.InternalElement.Document != DocumentManager.Instance.CurrentDBDocument)
            {
                throw new ArgumentException("The level does not exist in the given document");
            }

            DB.Level revitLevel = level.InternalElement as DB.Level;
            DB.XYZ revitPoint = GeometryPrimitiveConverter.ToXyz(point);

            DB.UV uv = new DB.UV(revitPoint.X, revitPoint.Y);

            return new Space(revitLevel, uv);
        }
Beispiel #48
0
 /// <summary>
 /// Transform 3d path to 2d path.
 /// </summary>
 /// <returns></returns>
 private void ComputePathTo2D()
 {
     Matrix4 transform = GetActiveViewMatrix().Inverse();
     foreach (List<XYZ> arr in m_path)
     {
         List<UV> uvarr = new List<UV>();
         foreach (Autodesk.Revit.DB.XYZ xyz in arr)
         {
             Vector4 tmpVector = transform.Transform(new Vector4(xyz));
             Autodesk.Revit.DB.UV tmpUv = new Autodesk.Revit.DB.UV(
                 tmpVector.X,
                 tmpVector.Y);
             uvarr.Add(tmpUv);
         }
         m_path2d.Add(uvarr);
     }
 }