Esempio n. 1
0
        public static Elements.Element RevitWallToHyparWall(Wall revitWall)
        {
            Polygon        outerPolygon = null;
            List <Polygon> voids        = new List <Polygon>();

            var polygons = revitWall.GetProfile();

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

            outerPolygon = polygons[0];
            if (polygons.Count > 1)
            {
                voids.AddRange(polygons.Skip(1));
            }

            //build our profile
            Profile prof = new Profile(outerPolygon, voids, Guid.NewGuid(), "revit Wall");
            //get the location curve as an Elements.Line
            Curve curve = (revitWall.Location as LocationCurve).Curve;
            Line  line  = new Line(curve.GetEndPoint(0).ToVector3(true), curve.GetEndPoint(1).ToVector3(true));

            //return a neat Hypar wall
            return(new WallByProfile(prof, revitWall.Width, line));
        }
        private static 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
            });
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a new Sketch Plane from a Curve
        /// </summary>
        /// <param name="document">Active Document</param>
        /// <param name="curve">Curve to get plane from</param>
        /// <returns>Plane of the curve</returns>
        public static SketchPlane NewSketchPlaneFromCurve(Document document, Autodesk.Revit.DB.Curve curve)
        {
            XYZ startPoint = curve.GetEndPoint(0);
            XYZ endPoint   = curve.GetEndPoint(1);

            // If Start end Endpoint are the same check further points.
            int i = 2;

            while (startPoint == endPoint && endPoint != null)
            {
                endPoint = curve.GetEndPoint(i);
                i++;
            }



            // Plane to return
            Plane plane;


            // If Z Values are equal the Plane is XY
            if (startPoint.Z == endPoint.Z)
            {
                plane = CreatePlane(document, XYZ.BasisZ, startPoint);
            }
            // If X Values are equal the Plane is YZ
            else if (startPoint.X == endPoint.X)
            {
                plane = CreatePlane(document, XYZ.BasisX, startPoint);
            }
            // If Y Values are equal the Plane is XZ
            else if (startPoint.Y == endPoint.Y)
            {
                plane = CreatePlane(document, XYZ.BasisY, startPoint);
            }
            // Otherwise the Planes Normal Vector is not X,Y or Z.
            // We draw lines from the Origin to each Point and use the Plane this one spans up.
            else
            {
                CurveArray curves = new CurveArray();
                curves.Append(curve);
                curves.Append(Autodesk.Revit.DB.Line.CreateBound(new XYZ(0, 0, 0), startPoint));
                curves.Append(Autodesk.Revit.DB.Line.CreateBound(endPoint, new XYZ(0, 0, 0)));
#if (Revit2015 || Revit2016 || Revit2017)
                plane = document.Application.Create.NewPlane(curves);
#else
                plane = Plane.CreateByThreePoints(startPoint, new XYZ(0, 0, 0), endPoint);
#endif
            }


            // return new Sketchplane
            return(SketchPlane.Create(document, plane));
        }
Esempio n. 4
0
        /// <summary>
        /// Checks whether the curve is vertical or not.
        /// </summary>
        /// <param name="curve"></param>
        /// <returns></returns>
        private bool IsVertical(DB.Curve curve)
        {
            var diffX = Math.Abs(curve.GetEndPoint(0).X - curve.GetEndPoint(1).X);
            var diffY = Math.Abs(curve.GetEndPoint(0).Y - curve.GetEndPoint(1).Y);

            if (diffX < 0.1 && diffY < 0.1)
            {
                return(true);
            }

            return(false);
        }
Esempio n. 5
0
        public Autodesk.Revit.UI.Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            try
            {
                // get the active document and view
                UIDocument             revitDoc = commandData.Application.ActiveUIDocument;
                Autodesk.Revit.DB.View view     = revitDoc.ActiveView;
                Document  dbDoc             = revitDoc.Document;
                ElementId currentTextTypeId = dbDoc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType);

                foreach (ElementId elemId in revitDoc.Selection.GetElementIds())
                {
                    Element elem = dbDoc.GetElement(elemId);
                    if (elem.GetType() == typeof(Autodesk.Revit.DB.Structure.Rebar))
                    {
                        // cast to Rebar and get its first curve
                        Autodesk.Revit.DB.Structure.Rebar rebar = (Autodesk.Revit.DB.Structure.Rebar)elem;
                        Autodesk.Revit.DB.Curve           curve = rebar.GetCenterlineCurves(false, false, false)[0];

                        // calculate necessary arguments
                        Autodesk.Revit.DB.XYZ origin = new XYZ(
                            curve.GetEndPoint(0).X + curve.Length,
                            curve.GetEndPoint(0).Y,
                            curve.GetEndPoint(0).Z);
                        string strText = "This is " + rebar.Category.Name + " : " + rebar.Name;

                        // create the text
                        using (Transaction t = new Transaction(dbDoc))
                        {
                            t.Start("New text note");
                            TextNote.Create(dbDoc, view.Id, origin, strText, currentTextTypeId);
                            t.Commit();
                        }
                        return(Autodesk.Revit.UI.Result.Succeeded);
                    }
                }
                message = "No rebar selected!";
                return(Autodesk.Revit.UI.Result.Failed);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// This node will select grids along a model curve element ordered based on the start of the model curve.
        /// This works in the active view. So whatever plan representation your grids have, that is what is used.
        /// </summary>
        /// <param name="modelCurve">Revit model curve to select grids along.</param>
        /// <returns name="orderedGrids">The intersecting grids ordered from beginning to end of the line.</returns>
        public static List <global::Revit.Elements.Grid> IntersectingGridsByModelCurve(global::Revit.Elements.ModelCurve modelCurve)
        {
            ModelCurve mCurve = modelCurve.InternalElement as ModelCurve;

            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;

            List <global::Revit.Elements.Grid> intersectingGrids = new List <global::Revit.Elements.Grid>();

            IList <Autodesk.Revit.DB.Element> grids = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Grids).WhereElementIsNotElementType().ToElements();

            foreach (var grid in grids)
            {
                Grid  g  = grid as Grid;
                Curve c  = g.GetCurvesInView(DatumExtentType.ViewSpecific, doc.ActiveView).First();
                Curve c2 = mCurve.GeometryCurve;

                Point pt1 = Point.ByCoordinates(0, 0, c.GetEndPoint(0).Z);
                Point pt2 = Point.ByCoordinates(0, 0, c2.GetEndPoint(0).Z);
                XYZ   vec = Vector.ByTwoPoints(pt2, pt1).ToRevitType();

                var transformed = c2.CreateTransformed(Transform.CreateTranslation(vec));

                SetComparisonResult test = c.Intersect(transformed);

                if (test == SetComparisonResult.Overlap ||
                    test == SetComparisonResult.Subset ||
                    test == SetComparisonResult.Superset ||
                    test == SetComparisonResult.Equal)
                {
                    intersectingGrids.Add(g.ToDSType(true) as global::Revit.Elements.Grid);
                }
            }

            return(intersectingGrids.OrderBy(g => g.Curve.DistanceTo(modelCurve.Curve.StartPoint)).ToList());
        }
Esempio n. 7
0
        public Autodesk.Revit.UI.Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            try
            {
                // get the active document and view
                UIDocument             revitDoc = commandData.Application.ActiveUIDocument;
                Autodesk.Revit.DB.View view     = revitDoc.Document.ActiveView;
                foreach (Element elem in revitDoc.Selection.Elements)
                {
                    if (elem.GetType() == typeof(Autodesk.Revit.DB.Structure.Rebar))
                    {
                        // cast to Rebar and get its first curve
                        Autodesk.Revit.DB.Structure.Rebar rebar = (Autodesk.Revit.DB.Structure.Rebar)elem;
                        Autodesk.Revit.DB.Curve           curve = rebar.GetCenterlineCurves(false, false, false)[0];

                        // calculate necessary arguments
                        Autodesk.Revit.DB.XYZ origin = new XYZ(
                            curve.GetEndPoint(0).X + curve.Length,
                            curve.GetEndPoint(0).Y,
                            curve.GetEndPoint(0).Z);// draw the text at the right size
                        Autodesk.Revit.DB.XYZ baseVec = new Autodesk.Revit.DB.XYZ(1, 0, 0);
                        Autodesk.Revit.DB.XYZ upVec   = new Autodesk.Revit.DB.XYZ(0, 0, 1);
                        double lineWidth = curve.Length / 50;
                        string strText   = "This is " + rebar.Category.Name + " : " + rebar.Name;

                        // create the text
                        Transaction t = new Transaction(revitDoc.Document);
                        t.Start("Create new textnote");
                        Autodesk.Revit.DB.TextNote text = revitDoc.Document.Create.NewTextNote(view, origin, baseVec, upVec, lineWidth,
                                                                                               Autodesk.Revit.DB.TextAlignFlags.TEF_ALIGN_LEFT, strText);
                        text.Width = curve.Length; // set the text width
                        t.Commit();
                        return(Autodesk.Revit.UI.Result.Succeeded);
                    }
                }
                message = "No rebar selected!";
                return(Autodesk.Revit.UI.Result.Failed);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Credits: Grevit
        /// Creates a new Sketch Plane from a Curve
        /// https://github.com/grevit-dev/Grevit/blob/3c7a5cc198e00dfa4cc1e892edba7c7afd1a3f84/Grevit.Revit/Utilities.cs#L402
        /// </summary>
        /// <param name="curve">Curve to get plane from</param>
        /// <returns>Plane of the curve</returns>
        private SketchPlane NewSketchPlaneFromCurve(DB.Curve curve, Document doc)
        {
            XYZ startPoint = curve.GetEndPoint(0);
            XYZ endPoint   = curve.GetEndPoint(1);

            // If Start end Endpoint are the same check further points.
            int i = 2;

            while (startPoint == endPoint && endPoint != null)
            {
                endPoint = curve.GetEndPoint(i);
                i++;
            }

            // Plane to return
            DB.Plane plane;

            // If Z Values are equal the Plane is XY
            if (startPoint.Z == endPoint.Z)
            {
                plane = CreatePlane(XYZ.BasisZ, startPoint);
            }
            // If X Values are equal the Plane is YZ
            else if (startPoint.X == endPoint.X)
            {
                plane = CreatePlane(XYZ.BasisX, startPoint);
            }
            // If Y Values are equal the Plane is XZ
            else if (startPoint.Y == endPoint.Y)
            {
                plane = CreatePlane(XYZ.BasisY, startPoint);
            }
            // Otherwise the Planes Normal Vector is not X,Y or Z.
            // We draw lines from the Origin to each Point and use the Plane this one spans up.
            else
            {
                CurveArray curves = new CurveArray();
                curves.Append(curve);
                curves.Append(DB.Line.CreateBound(new XYZ(0, 0, 0), startPoint));
                curves.Append(DB.Line.CreateBound(endPoint, new XYZ(0, 0, 0)));

                plane = DB.Plane.CreateByThreePoints(startPoint, new XYZ(0, 0, 0), endPoint);
            }

            return(SketchPlane.Create(doc, plane));
        }
Esempio n. 9
0
        private static void MatchFlippingAndRotation(Autodesk.Revit.DB.FamilyInstance myInstance, Column myColumn, Autodesk.Revit.DB.Curve baseLine)
        {
            // TODO: All these try catches can be replaced with if ( Dictionary.ContainsKey(LOLOLO) )
            try
            {
                var handFlip = Convert.ToBoolean(myColumn.Properties["__handFlipped"]);
                if (handFlip != myInstance.HandFlipped)
                {
                    myInstance.flipHand();
                }
            }
            catch { }

            try
            {
                var faceFlip = Convert.ToBoolean(myColumn.Properties["__facingFlipped"]);
                if (faceFlip != myInstance.FacingFlipped)
                {
                    myInstance.flipFacing();
                }
            }
            catch { }

            try
            {
                // TODO: Check against existing rotation (if any) and deduct that)
                var rotation = Convert.ToDouble(myColumn.Properties["__rotation"]);

                var start  = baseLine.GetEndPoint(0);
                var end    = baseLine.GetEndPoint(1);
                var myLine = Autodesk.Revit.DB.Line.CreateBound(start, end);

                if (myInstance.Location is LocationPoint)
                {
                    ((LocationPoint)myInstance.Location).Rotate(myLine, rotation - ((LocationPoint)myInstance.Location).Rotation);
                }
                //else
                //  ElementTransformUtils.RotateElement( Doc, myInstance.Id, myLine, rotation );
            }
            catch (Exception e) { }
        }
Esempio n. 10
0
        private List <Rhino.Geometry.Brep> GetWallLayerGeometry(DB.Wall wall)
        {
            // determine wall anchor point to help in sorting layer breps
            DB.Curve wallLocationCurve       = (wall.Location as DB.LocationCurve).Curve;
            DB.XYZ   wallEndPoint            = wallLocationCurve.GetEndPoint(0);
            DB.XYZ   wallOrientation         = wall.Orientation;
            DB.XYZ   anchor                  = wallEndPoint + (wallOrientation * wallLocationCurve.Length);
            Rhino.Geometry.Point3d basePoint = anchor.ToPoint3d();

            return(GetCompoundStructureLayerGeom(wall)
                   .OrderBy(x => Rhino.Geometry.VolumeMassProperties.Compute(x, volume: true, firstMoments: true, secondMoments: false, productMoments: false).Centroid.DistanceTo(basePoint))
                   .ToList());
        }
Esempio n. 11
0
        /// <summary>
        /// Tag the beam's start and end.
        /// </summary>
        /// <param name="tagMode">Mode of tag</param>
        /// <param name="tagSymbol">Tag symbol wrapper</param>
        /// <param name="leader">Whether the tag has leader</param>
        /// <param name="tagOrientation">Orientation of tag</param>
        public void CreateTag(TagMode tagMode,
                              FamilySymbolWrapper tagSymbol, bool leader,
                              TagOrientation tagOrientation)
        {
            foreach (FamilyInstance beam in m_beamList)
            {
                //Get the start point and end point of the selected beam.
                Autodesk.Revit.DB.LocationCurve location = beam.Location as Autodesk.Revit.DB.LocationCurve;
                Autodesk.Revit.DB.Curve         curve    = location.Curve;

                Transaction t = new Transaction(m_revitDoc.Document);
                t.Start("Create new tag");
                //Create tag on the beam's start and end.
                IndependentTag tag1 = m_docCreator.NewTag(
                    m_view, beam, leader, tagMode, tagOrientation, curve.GetEndPoint(0));
                IndependentTag tag2 = m_docCreator.NewTag(
                    m_view, beam, leader, tagMode, tagOrientation, curve.GetEndPoint(1));

                //Change the tag's object Type.
                tag1.ChangeTypeId(tagSymbol.FamilySymbol.Id);
                tag2.ChangeTypeId(tagSymbol.FamilySymbol.Id);
                t.Commit();
            }
        }
        private static void CreateRevitElementInRevit(Autodesk.Revit.DB.Curve geomLine)
        {
            // var OriginShit = geomLine.ComputeDerivatives(0, true);
            //var normal = OriginShit.BasisZ;
            // var origin = OriginShit.Origin;
            // XYZ origin = new XYZ(0, 0, 0);
            // XYZ normal = new XYZ(0, 1, 0);
            var Origin = geomLine.GetEndPoint(0);

            Plane geomPlane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, Origin);
            // Create a sketch plane in current document
            SketchPlane sketch = SketchPlane.Create(Command.uidoc.Document, geomPlane);

            // Create a ModelLine element using the created geometry line and sketch plane
            var line = Command.uidoc.Document.Create.NewModelCurve(geomLine, sketch);
        }
Esempio n. 13
0
        public static BoundaryConditionBase DF_Init(
            IEnumerable <SpatialObjectWrapper> objects,
            RVT.Curve curve,
            SpatialObjectWrapper sow,
            bool allowAdiabatic)
        {
            var adjacentRoomName   = string.Empty;
            var adjacentCurveIndex = -1;

            foreach (var so in objects)
            {
                if (adjacentCurveIndex != -1 && adjacentRoomName != null)
                {
                    break;
                }

                var boundarySegments = so.Room2D.FloorBoundary.GetCurves(so.Level.Elevation);
                for (var i = 0; i < boundarySegments.Count; i++)
                {
                    var c = boundarySegments[i];
                    if (!c.OverlapsWithIn2D(curve))
                    {
                        continue;
                    }

                    adjacentCurveIndex = i;
                    adjacentRoomName   = so.Room2D.Identifier;
                    break;
                }
            }

            if (adjacentCurveIndex != -1 && !string.IsNullOrWhiteSpace(adjacentRoomName))
            {
                // (Konrad) We found a matching Surface Boundary Condition.
                var bConditionObj = new Tuple <string, string, string>(string.Empty, adjacentCurveIndex.ToString(), adjacentRoomName);

                return(new Surface(bConditionObj));
            }

            if (!allowAdiabatic)
            {
                return(new Outdoors());
            }

            // (Konrad) We can try assigning Adiabatic and Outdoors.
            var direction = curve is RVT.Line
                ? curve.ComputeDerivatives(0, true).BasisX.Normalize()
                : (curve.GetEndPoint(1) - curve.GetEndPoint(0)).Normalize();
            var perpendicular = RVT.XYZ.BasisZ.CrossProduct(direction).Multiply(2);

            var start    = curve.GetEndPoint(0);
            var end      = curve.GetEndPoint(1);
            var midPoint = new RVT.XYZ((start.X + end.X) / 2, (start.Y + end.Y) / 2, start.Z + 1);
            var outPt    = midPoint + perpendicular;
            var doc      = sow.Self.Document;
            var phases   = doc.Phases;
            var room     = phases.Cast <RVT.Phase>().Select(x => doc.GetRoomAtPoint(outPt, x)).FirstOrDefault(x => x != null);

            if (room != null && room.Id != sow.Self.Id)
            {
                return(new Adiabatic());
            }

            var inPt = midPoint + perpendicular.Negate();

            room = phases.Cast <RVT.Phase>().Select(x => doc.GetRoomAtPoint(inPt, x)).FirstOrDefault(x => x != null);
            if (room != null && room.Id != sow.Self.Id)
            {
                return(new Adiabatic());
            }

            // (Konrad) We can't find the Room adjacent to this Curve.
            return(new Outdoors());
        }
Esempio n. 14
0
 public static Autodesk.Revit.DB.Curve OffsetCurve(Autodesk.Revit.DB.Curve c, Autodesk.Revit.DB.XYZ direction, double offset)
 {
     c = Line.CreateBound(OffsetPoint(c.GetEndPoint(0), direction, offset), OffsetPoint(c.GetEndPoint(1), direction, offset));
     return(c);
 }
Esempio n. 15
0
 public static Autodesk.Revit.DB.Curve TransformCurve(Autodesk.Revit.DB.Curve curve, Transform transform)
 {
     return(Line.CreateBound(TransformPoint(curve.GetEndPoint(0), transform), TransformPoint(curve.GetEndPoint(1), transform)));
 }
Esempio n. 16
0
        Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document    revitDoc = commandData.Application.ActiveUIDocument.Document; //取得文档
            Application revitApp = commandData.Application.Application;               //取得应用程序
            UIDocument  uiDoc    = commandData.Application.ActiveUIDocument;          //取得当前活动文档

            Document document = commandData.Application.ActiveUIDocument.Document;

            Window1 window1 = new Window1();

            //载入族
            FamilySymbol familySymbol;

            using (Transaction tran = new Transaction(uiDoc.Document))
            {
                tran.Start("载入族");

                //载入弦杆族
                string file = @"C:\Users\zyx\Desktop\2RevitArcBridge\CrossBeam\CrossBeam\source\crossBeam.rfa";
                familySymbol = loadFaimly(file, commandData);
                familySymbol.Activate();

                tran.Commit();
            }


            //把这组模型线通过获取首尾点,生成dynamo里的curve
            List <XYZ> ps = new List <XYZ>();

            using (Transaction transaction = new Transaction(uiDoc.Document))
            {
                transaction.Start("选取模型线生成Curve");

                Selection         sel        = uiDoc.Selection;
                IList <Reference> modelLines = sel.PickObjects(ObjectType.Element, "选一组模型线");

                foreach (Reference reference in modelLines)
                {
                    Element   elem            = revitDoc.GetElement(reference);
                    ModelLine modelLine       = elem as ModelLine;
                    Autodesk.Revit.DB.Curve c = modelLine.GeometryCurve;

                    ps.Add(c.GetEndPoint(0));
                    ps.Add(c.GetEndPoint(1));
                }

                for (int i = ps.Count - 1; i > 0; i--)
                {
                    XYZ p1 = ps[i];
                    XYZ p2 = ps[i - 1];

                    //注意此处重合点有一个闭合差
                    if (p1.DistanceTo(p2) < 0.0001)
                    {
                        ps.RemoveAt(i);
                    }
                }

                transaction.Commit();
            }


            //做一个revit和dynamo点的转换
            DG.CoordinateSystem coordinateSystem = DG.CoordinateSystem.ByOrigin(0, 0, 0);//标准坐标系
            List <DG.Point>     DGps             = new List <DG.Point>();

            foreach (XYZ p in ps)
            {
                DGps.Add(p.ToPoint(false));
            }

            DG.PolyCurve polyCurve = DG.PolyCurve.ByPoints(DGps);
            DG.Curve     curve     = polyCurve as DG.Curve;

            List <DG.Point> DGCBps      = new List <DG.Point>();//横梁的放置点位列表
            double          StartLength = 0;

            if (window1.ShowDialog() == true)
            {
                //窗口打开并停留,只有点击按键之后,窗口关闭并返回true
            }


            //按键会改变window的属性,通过对属性的循环判断来实现对按键的监测
            while (!window1.Done)
            {
                //选择起点
                if (window1.StartPointSelected)
                {
                    using (Transaction transaction = new Transaction(uiDoc.Document))
                    {
                        transaction.Start("选择起点");

                        double   r1   = SelectPoint(commandData);
                        DG.Point dgp1 = curve.PointAtParameter(r1);
                        DGCBps.Add(dgp1);
                        StartLength = curve.SegmentLengthAtParameter(r1);


                        transaction.Commit();
                    }

                    //2、重置window1.StartPointSelected

                    window1.StartPointSelected = false;
                }

                if (window1.ShowDialog() == true)
                {
                    //窗口打开并停留,只有点击按键之后,窗口关闭并返回true
                }
            }



            //在这里根据间距获取到各个点
            for (int i = 1; i < window1.cbNumber; i++)
            {
                double   L     = StartLength + window1.cbDistance * i;
                DG.Point point = curve.PointAtSegmentLength(L);
                DGCBps.Add(point);
                MessageBox.Show(i.ToString());
            }

            List <FamilyInstance> instances = new List <FamilyInstance>();

            using (Transaction transaction = new Transaction(uiDoc.Document))
            {
                transaction.Start("创建横梁实例");

                foreach (DG.Point p in DGCBps)
                {
                    FamilyInstance familyInstance;
                    familyInstance = CreateFamlyInstance(p, curve, familySymbol, commandData);
                    instances.Add(familyInstance);
                }


                transaction.Commit();
            }


            //给每个族实例设置参数
            using (Transaction transaction = new Transaction(uiDoc.Document))
            {
                transaction.Start("族实例参数设置");

                foreach (FamilyInstance instance in instances)
                {
                    double h1 = instance.LookupParameter("l1/2").AsDouble();
                    instance.LookupParameter("l1/2").Set(window1.l1 / 2);
                    instance.LookupParameter("l2").Set(window1.l2);

                    //instance.LookupParameter("h1").Set(window1.l1);
                    //instance.LookupParameter("h2").Set(window1.l1);
                }
                transaction.Commit();
            }

            return(Result.Succeeded);
        }
Esempio n. 17
0
        public Autodesk.Revit.UI.Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            try
            {
                // Get the active document and view
                UIDocument             revitDoc = commandData.Application.ActiveUIDocument;
                Autodesk.Revit.DB.View view     = revitDoc.Document.ActiveView;
                foreach (ElementId elemId in revitDoc.Selection.GetElementIds())
                {
                    Element elem = revitDoc.Document.GetElement(elemId);
                    if (elem.GetType() == typeof(Autodesk.Revit.DB.Structure.Rebar))
                    {
                        // cast to Rebar and get its first curve
                        Autodesk.Revit.DB.Structure.Rebar rebar = (Autodesk.Revit.DB.Structure.Rebar)elem;
                        Autodesk.Revit.DB.Curve           curve = rebar.GetCenterlineCurves(false, false, false)[0];

                        // create a rebar tag at the first end point of the first curve
                        using (Transaction t = new Transaction(revitDoc.Document))
                        {
                            t.Start("Create new tag");
                            IndependentTag tag = revitDoc.Document.Create.NewTag(view, rebar, true,
                                                                                 Autodesk.Revit.DB.TagMode.TM_ADDBY_CATEGORY,
                                                                                 Autodesk.Revit.DB.TagOrientation.Horizontal, curve.GetEndPoint(0));
                            t.Commit();
                        }
                        return(Autodesk.Revit.UI.Result.Succeeded);
                    }
                }
                message = "No rebar selected!";
                return(Autodesk.Revit.UI.Result.Failed);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }