예제 #1
0
        public static re.Element WallByProfile(List <dg.PolyCurve> closedProfiles, re.WallType wallType, re.Level level)
        {
            rdb.Document doc = DocumentManager.Instance.CurrentDBDocument;

            // Try to get a wall from trace
            var wallElem = ElementBinder.GetElementFromTrace <rdb.Wall>(doc);

            dg.PolyCurve closedProfile = closedProfiles[0];
            if (!closedProfile.IsClosed || !closedProfile.IsPlanar)
            {
                DeleteWall(wallElem, true);
                return(null);
            }

            // Verify the wall profile is vertical
            dg.Plane basePlane = closedProfile.BasePlane();
            if (Math.Abs(basePlane.Normal.Z) > 0.0001)
            {
                DeleteWall(wallElem, true);
                return(null);
            }

            // Convert Polycurve segments to a list of Revit curves;
            List <rdb.Curve> rCrvs = new List <rdb.Curve>();

            foreach (dg.PolyCurve pCrv in closedProfiles)
            {
                List <dg.Curve> dCrvs = pCrv.Curves().ToList();
                foreach (dg.Curve dCrv in dCrvs)
                {
                    rdb.Curve rCrv = dCrv.ToRevitType();
                    rCrvs.Add(rCrv);
                }
            }


            TransactionManager.Instance.EnsureInTransaction(doc);
            DeleteWall(wallElem, false);

            // Build a wall
            try
            {
                rdb.Wall w     = rdb.Wall.Create(doc, rCrvs, new rdb.ElementId(wallType.Id), new rdb.ElementId(level.Id), false);
                re.Wall  rWall = re.ElementWrapper.ToDSType(w, true) as re.Wall;
                TransactionManager.Instance.TransactionTaskDone();
                ElementBinder.CleanupAndSetElementForTrace(doc, w);
                return(rWall);
            }
            catch (Exception ex)
            {
                TransactionManager.Instance.TransactionTaskDone();

                ElementBinder.CleanupAndSetElementForTrace(doc, null);
            }
            return(null);
        }
예제 #2
0
        public static Autodesk.DesignScript.Geometry.Curve GetWallBaseline(Revit.Elements.Wall wall)
        {
            //get Revit Wall element from the Dynamo-wrapped object
            var revitWall = wall.InternalElement;
            //get the location curve of the wall using the Revit API
            var locationCurve = revitWall.Location as LocationCurve;

            //convert the curve to Dynamo and return it
            return(locationCurve.Curve.ToProtoType());
        }
예제 #3
0
        public static Autodesk.DesignScript.Geometry.Curve GetWallBaseline(Revit.Elements.Wall wall)
        {
            //get Revit Wall
            var revitWall = wall.InternalElement;
            //revit API
            var locationCurve = revitWall.Location as LocationCurve;

            //convert to Dynamo and return it
            return(locationCurve.Curve.ToProtoType());
        }
예제 #4
0
        /// <summary>
        /// Convert a Revit wall to Elements.WallByProfile(s) for use in Hypar models.
        /// Sometimes a single wall in Revit needs to be converted to multiple Hypar walls.
        /// </summary>
        /// <param name="revitWall">The walls to be exported.</param>
        /// <returns name="WallByProfiles">The Hypar walls.</returns>
        public static Elements.WallByProfile[] FromRevitWall(DynamoRevit.Wall revitWall)
        {
            var revitWallElement = (Autodesk.Revit.DB.Wall)revitWall.InternalElement;

            // wrapped exception catching to deliver more meaningful message in Dynamo
            try
            {
                return(Create.WallsFromRevitWall(revitWallElement, DocumentManager.Instance.CurrentDBDocument));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
예제 #5
0
        public static re.Element CreateWallOpening(re.Wall wall, dg.PolyCurve polyCrv)
        {
            try
            {
                // Try to get a wall from trace
                rdb.Document doc         = DocumentManager.Instance.CurrentDBDocument;
                var          openingElem = ElementBinder.GetElementFromTrace <rdb.Element>(doc);
                rdb.Opening  opening     = null;
                if (openingElem != null && openingElem.Id.IntegerValue != (int)rdb.BuiltInCategory.OST_SWallRectOpening)
                {
                    opening = openingElem as rdb.Opening;
                }

                if (!VerifyRect(polyCrv))
                {
                    if (opening != null)
                    {
                        TransactionManager.Instance.EnsureInTransaction(doc);
                        doc.Delete(opening.Id);
                        TransactionManager.Instance.TransactionTaskDone();
                    }
                    TaskDialog.Show("Test", "VerifyRect failed");
                    return(null);
                }

                // Find the two corner points.
                if (!GetRectCorners(polyCrv, out rdb.XYZ corner0, out rdb.XYZ corner1))
                {
                    if (opening != null)
                    {
                        TransactionManager.Instance.EnsureInTransaction(doc);
                        doc.Delete(opening.Id);
                        TransactionManager.Instance.TransactionTaskDone();
                    }
                    TaskDialog.Show("Test", "GetRectCorners failed");
                    return(null);
                }

                if (corner0 == null || corner1 == null)
                {
                    if (opening != null)
                    {
                        TransactionManager.Instance.EnsureInTransaction(doc);
                        doc.Delete(opening.Id);
                        TransactionManager.Instance.TransactionTaskDone();
                    }
                    TaskDialog.Show("Test", "one of the corners is null");
                    return(null);
                }

                TransactionManager.Instance.EnsureInTransaction(doc);
                // Purge the original element
                if (opening != null)
                {
                    doc.Delete(opening.Id);
                }

                // Build a new opening;
                try
                {
                    rdb.Wall    w        = wall.InternalElement as rdb.Wall;
                    rdb.Opening o        = doc.Create.NewOpening(w, corner0, corner1);
                    re.Element  rOpening = re.ElementWrapper.ToDSType(o, true) as re.Element;
                    TransactionManager.Instance.TransactionTaskDone();
                    ElementBinder.CleanupAndSetElementForTrace(doc, o);
                    return(rOpening);
                }
                catch (Exception ex)
                {
                    TransactionManager.Instance.TransactionTaskDone();
                    TaskDialog.Show("CreateError", ex.ToString());
                    ElementBinder.CleanupAndSetElementForTrace(doc, null);
                }
            }
            catch (Exception e)
            {
                Autodesk.Revit.UI.TaskDialog.Show("Test", "Error:\n" + e.ToString());
                throw;
            }
            return(null);
        }
예제 #6
0
 public static Wall Wrap(Autodesk.Revit.DB.Wall ele, bool isRevitOwned)
 {
     return(Wall.FromExisting(ele, isRevitOwned));
 }