示例#1
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(UV point2D1, 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;

            XYZ startPoint = m_doc.Document.Application.Create.NewXYZ(point2D1.U, point2D1.V, middleElevation);
            XYZ endPoint   = m_doc.Document.Application.Create.NewXYZ(point2D2.U, point2D2.V, middleElevation);
            XYZ middlePoint;

            if (isXDirection)
            {
                middlePoint = m_doc.Document.Application.Create.NewXYZ((point2D1.U + point2D2.U) / 2, point2D2.V, topHeight);
            }
            else
            {
                middlePoint = middlePoint = m_doc.Document.Application.Create.NewXYZ(point2D2.U, (point2D1.V + point2D2.V) / 2, topHeight);
            }

            //create two brace and set their location line
            STRUCTURALTYPE structuralType = Autodesk.Revit.DB.Structure.StructuralType.Brace;
            ElementId      levelId        = topLevel.Id;
            ElementId      startLevelId   = baseLevel.Id;
            ElementId      endLevelId     = topLevel.Id;

            FamilyInstance firstBrace  = m_doc.Document.Create.NewFamilyInstance(startPoint, braceType, structuralType);
            LocationCurve  braceCurve1 = firstBrace.Location as LocationCurve;

            if (null != braceCurve1)
            {
                Line line = Line.CreateBound(startPoint, middlePoint);
                braceCurve1.Curve = line;
            }

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

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

            FamilyInstance secondBrace = m_doc.Document.Create.NewFamilyInstance(endPoint, braceType, baseLevel, structuralType);
            LocationCurve  braceCurve2 = secondBrace.Location as LocationCurve;

            if (null != braceCurve2)
            {
                Line line = Line.CreateBound(endPoint, middlePoint);
                braceCurve2.Curve = line;
            }

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

            if (null != referenceLevel2)
            {
                referenceLevel2.Set(levelId);
            }
        }
示例#2
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);
            }
        }
示例#3
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);
        }
示例#4
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(UV point2D1, UV point2D2, Level baseLevel, Level topLevel, FamilySymbol beamType)
        {
            // create start and end points for beam
            double    height     = topLevel.Elevation;
            XYZ       startPoint = m_doc.Document.Application.Create.NewXYZ(point2D1.U, point2D1.V, height);
            XYZ       endPoint   = m_doc.Document.Application.Create.NewXYZ(point2D2.U, point2D2.V, height);
            ElementId topLevelId = topLevel.Id;

            STRUCTURALTYPE structuralType = Autodesk.Revit.DB.Structure.StructuralType.Beam;
            FamilyInstance beam           = m_doc.Document.Create.NewFamilyInstance(startPoint, beamType, topLevel, structuralType);

            LocationCurve beamCurve = beam.Location as LocationCurve;

            if (null != beamCurve)
            {
                Line line = Line.CreateBound(startPoint, endPoint);
                beamCurve.Curve = line;
            }
        }
示例#5
0
        private FamilyInstanceCreationData GetCreationData(Autodesk.Revit.DB.Curve curve, Autodesk.Revit.DB.XYZ upVector, Autodesk.Revit.DB.Level level, Autodesk.Revit.DB.Structure.StructuralType structuralType, Autodesk.Revit.DB.FamilySymbol symbol)
        {
            //calculate the desired rotation
            //we do this by finding the angle between the z axis
            //and vector between the start of the beam and the target point
            //both projected onto the start plane of the beam.
            var zAxis = new XYZ(0, 0, 1);
            var yAxis = new XYZ(0, 1, 0);

            //flatten the beam line onto the XZ plane
            //using the start's z coordinate
            var start  = curve.GetEndPoint(0);
            var end    = curve.GetEndPoint(1);
            var newEnd = new XYZ(end.X, end.Y, start.Z); //drop end point to plane

            //catch the case where the end is directly above
            //the start, creating a normal with zero length
            //in that case, use the Z axis
            XYZ planeNormal = newEnd.IsAlmostEqualTo(start) ? zAxis : (newEnd - start).Normalize();

            double gamma = upVector.AngleOnPlaneTo(zAxis.IsAlmostEqualTo(planeNormal) ? yAxis : zAxis, planeNormal);

            return(new FamilyInstanceCreationData(curve, symbol, level, structuralType)
            {
                RotateAngle = gamma
            });
        }
示例#6
0
        /// <summary>
        /// Internal constructor - creates a single StructuralFraming instance
        /// </summary>
        internal StructuralFraming(Autodesk.Revit.DB.Curve curve, Autodesk.Revit.DB.XYZ upVector, Autodesk.Revit.DB.Level level, Autodesk.Revit.DB.Structure.StructuralType structuralType, Autodesk.Revit.DB.FamilySymbol symbol)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldFam =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.FamilyInstance>(Document);

            //There was a point, rebind to that, and adjust its position
            if (oldFam != null)
            {
                InternalSetFamilyInstance(oldFam);
                InternalSetFamilySymbol(symbol);
                InternalSetCurve(curve);
                return;
            }

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

            var creationData = GetCreationData(curve, upVector, level, structuralType, symbol);

            Autodesk.Revit.DB.FamilyInstance fi;
            if (Document.IsFamilyDocument)
            {
                var elementIds = Document.FamilyCreate.NewFamilyInstances2(new List <FamilyInstanceCreationData>()
                {
                    creationData
                });

                if (elementIds.Count == 0)
                {
                    throw new Exception("Could not create the FamilyInstance");
                }

                fi = (Autodesk.Revit.DB.FamilyInstance)Document.GetElement(elementIds.First());
            }
            else
            {
                var elementIds = Document.Create.NewFamilyInstances2(new List <FamilyInstanceCreationData>()
                {
                    creationData
                });

                if (elementIds.Count == 0)
                {
                    throw new Exception("Could not create the FamilyInstance");
                }

                fi = (Autodesk.Revit.DB.FamilyInstance)Document.GetElement(elementIds.First());
            }

            InternalSetFamilyInstance(fi);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(this.InternalElement);
        }