Beispiel #1
1
        /// <summary>
        /// Create a Revit Floor given it's curve outline and Level
        /// </summary>
        /// <param name="outline"></param>
        /// <param name="level"></param>
        /// <returns>The floor</returns>
        public static Floor ByOutlineTypeAndLevel( Autodesk.DesignScript.Geometry.Curve[] outline, FloorType floorType, Level level)
        {
            if (outline == null)
            {
                throw new ArgumentNullException("outline");
            }

            if (floorType == null)
            {
                throw new ArgumentNullException("floorType");
            }

            if ( level == null )
            {
                throw new ArgumentNullException("level");
            }

            if (outline.Count() < 3)
            {
                throw new Exception("Outline must have at least 3 edges to enclose an area.");
            }

            var ca = new CurveArray();
            outline.ToList().ForEach(x => ca.Append(x.ToRevitType()));

            return new Floor(ca, floorType.InternalFloorType, level.InternalLevel );
        }
Beispiel #2
0
        /// <summary>
        /// New Family Instance by Curve
        /// </summary>
        /// <param name="familyType">Family Type to be applied to new Family Instance.</param>
        /// <param name="line">Line to place Family Instance at.</param>
        /// <param name="level">Level to associate Family Instance with.</param>
        /// <returns>New Family Instance.</returns>
        public static Element ByLine(FamilyType familyType, Line line, Level level)
        {
            if (familyType == null)
            {
                throw new ArgumentNullException(nameof(familyType));
            }

            var symbol       = familyType.InternalElement as Autodesk.Revit.DB.FamilySymbol;
            var locationLine = line.ToRevitType() as Autodesk.Revit.DB.Line;
            var hostLevel    = level.InternalElement as Autodesk.Revit.DB.Level;

            return(new FamilyInstances(symbol, locationLine, hostLevel));
        }
Beispiel #3
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);
        }
Beispiel #4
0
        /// <summary>
        /// Create a Revit Wall from a guiding Curve, start Level, end Level, and WallType
        /// </summary>
        /// <param name="c"></param>
        /// <param name="startLevel"></param>
        /// <param name="endLevel"></param>
        /// <param name="wallType"></param>
        /// <returns></returns>
        public static Wall ByCurveAndLevels(Autodesk.DesignScript.Geometry.Curve c, Level startLevel, Level endLevel, WallType wallType)
        {
            if (endLevel == null)
            {
                throw new ArgumentNullException("endLevel");
            }

            if (startLevel == null)
            {
                throw new ArgumentNullException("startLevel");
            }

            var height = endLevel.Elevation - startLevel.Elevation;

            return ByCurveAndHeight(c, height, startLevel, wallType);
        }
Beispiel #5
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 #6
0
        /// <summary>
        /// Create a Revit Floor given it's curve outline and Level
        /// </summary>
        /// <param name="outline"></param>
        /// <param name="floorType"></param>
        /// <param name="level"></param>
        /// <returns>The floor</returns>
        public static Floor ByOutlineTypeAndLevel(PolyCurve outline, FloorType floorType, Level level)
        {
            if (outline == null)
            {
                throw new ArgumentNullException("outline");
            }

            if (floorType == null)
            {
                throw new ArgumentNullException("floorType");
            }

            if ( level == null )
            {
                throw new ArgumentNullException("level");
            }

            if (!outline.IsClosed)
            {
                throw new ArgumentException("The input PolyCurve is not closed");
            }

            var ca = new CurveArray();
            outline.Curves().ForEach(x => ca.Append(x.ToRevitType())); 

            return new Floor(ca, floorType.InternalFloorType, level.InternalLevel );
        }
Beispiel #7
0
        /// <summary>
        /// Create a Revit Structural Member - a special FamilyInstance
        /// </summary>
        /// <param name="curve">The curve path for the structural member</param>
        /// <param name="upVector">The up vector for the element - this is required to determine the orientation of the element</param>
        /// <param name="level">The level on which the member should appear</param>
        /// <param name="structuralType">The type of the structural element - a beam, column, etc</param>
        /// <param name="structuralFramingType">The structural framing type representing the structural type</param>
        /// <returns></returns>
        public static StructuralFraming ByCurveLevelUpVectorAndType(Autodesk.DesignScript.Geometry.Curve curve, Level level, 
            Autodesk.DesignScript.Geometry.Vector upVector, StructuralType structuralType, FamilySymbol structuralFramingType)
        {
            if (curve == null)
            {
                throw new System.ArgumentNullException("curve");
            }

            if (level == null)
            {
                throw new System.ArgumentNullException("level");
            }

            if (upVector == null)
            {
                throw new System.ArgumentNullException("upVector");
            }

            if (structuralFramingType == null)
            {
                throw new System.ArgumentNullException("structuralFramingType");
            }            

            return new StructuralFraming(curve.ToRevitType(), upVector.ToXyz(), level.InternalLevel,
                structuralType.ToRevitType(), structuralFramingType.InternalFamilySymbol);
        }
 /// <summary>
 /// Creates a ElementFilter that passes elements on the specified level.  The filter should then be passed to a Collector node and the Collector retrieves elements that pass the filter.
 /// </summary>
 /// <param name="level">A Dynamo wrapped Level.</param>
 /// <param name="inverted">If true, the filter elements NOT matching the filter criteria are chosen.</param>
 /// <returns name="ElementFilter">An Element Filter.  The filter should then be passed to a Collector node and the Collector retrieves elements that pass the filter.</returns>
 public static revitDB.ElementFilter FilterElementLevel(DynLevel level, [DefaultArgument("false")] bool inverted)
 {
     return(new revitDB.ElementLevelFilter(new revitDB.ElementId(level.Id), inverted));
 }
Beispiel #9
0
        /// <summary>
        /// Place a Revit FamilyInstance given the FamilySymbol (also known as the FamilyType), it's coordinates in world space, and the Level
        /// </summary>
        /// <param name="familySymbol"></param>
        /// <param name="point"></param>
        /// <param name="level"></param>
        /// <returns></returns>
        public static FamilyInstance ByPointAndLevel(FamilySymbol familySymbol, Point point, Level level)
        {
            if (familySymbol == null)
            {
                throw new ArgumentNullException("familySymbol");
            }

            return new FamilyInstance(familySymbol.InternalFamilySymbol, point.ToXyz(), level.InternalLevel);
        }
Beispiel #10
0
        //bits and pieces from https://github.com/DynamoDS/DynamoRevit/blob/Revit2017/src/Libraries/RevitNodes/Elements/Wall.cs
        /// <summary>
        /// Say Hello, generates Revit walls based on an input text as driving curve
        /// </summary>
        /// <param name="text">Text to cenvert into Wall baselines</param>
        /// <param name="height">Wall Height</param>
        /// <param name="level">Wall Level</param>
        /// <param name="wallType">Wall Type</param>
        /// <param name="size">Font Size</param>
        /// <returns></returns>
        public static IEnumerable <Revit.Elements.Wall> SayHello(string text, double height, Revit.Elements.Level level, Revit.Elements.WallType wallType, int size = 25)
        {
            //first check inputs
            if (level == null)
            {
                throw new ArgumentNullException("level");
            }

            if (wallType == null)
            {
                throw new ArgumentNullException("wallType");
            }

            var walls = new List <Revit.Elements.Wall>();
            var lines = TextUtils.TextToLines(text, size);

            //elements creation and modification has to be inside of a transaction
            TransactionManager.Instance.EnsureInTransaction(Document);

            foreach (var curve in lines)
            {
                if (curve == null)
                {
                    throw new ArgumentNullException("curve");
                }

                try
                {
                    var wall = Autodesk.Revit.DB.Wall.Create(Document, curve.ToRevitType(), wallType.InternalElement.Id, level.InternalElement.Id, height, 0.0, false, false);
                    walls.Add(wall.ToDSType(false) as Revit.Elements.Wall);
                }

                catch (Exception ex)
                {
                    throw new ArgumentException(ex.Message);
                }
            }

            TransactionManager.Instance.TransactionTaskDone();

            return(walls);
        }
Beispiel #11
0
        /// <summary>
        /// Returns a list of desk Revit family instances using the Desk stored in the DeskArrangement.
        /// </summary>
        /// <param name="deskArrangement"> The DeskArrangement object.</param>
        /// <param name="deskType"> The desk type.</param>
        /// <param name="hostLevel"> The host hostLevel for the new desks.</param>
        public static List <DynamoElement> Generate(DeskArrangement deskArrangement, DynamoFamilyType deskType, DynamoLevel hostLevel)
        {
            Document doc = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(doc);

            FamilySymbol newDeskType = FamilyTypeCreator.Desk((FamilySymbol)deskType.InternalElement, deskArrangement, "AU 2019 Vegas Desk");

            // Get the Revit Document factory object from the Autodesk.Revit.DB.Creation namespace.
            // This object is used to instantiate most Revit Elements.
            var revitFactory = doc.Create;

            var revitDesks = new List <DynamoElement>();

            foreach (var desk in deskArrangement.Desks)
            {
                XYZ location       = desk.Origin.ToXyz();
                var familyInstance = revitFactory.NewFamilyInstance(location, newDeskType, hostLevel.InternalElement, StructuralType.NonStructural);

                // Wrap and bind the new desk instance.
                revitDesks.Add(familyInstance.ToDSType(false));
            }

            TransactionManager.Instance.TransactionTaskDone();

            return(revitDesks);
        }
Beispiel #12
0
        /// <summary>
        /// Place a Revit FamilyInstance given the FamilySymbol (also known as the FamilyType), it's coordinates in world space, and the Level
        /// </summary>
        /// <param name="familySymbol"></param>
        /// <param name="point">Point in meters</param>
        /// <param name="level"></param>
        /// <returns></returns>
        public static FamilyInstance ByPointAndLevel(FamilySymbol familySymbol, Point point, Level level)
        {
            if (familySymbol == null)
            {
                throw new ArgumentNullException("familySymbol");
            }

            return(new FamilyInstance(familySymbol.InternalFamilySymbol, point.ToXyz(), level.InternalLevel));
        }
Beispiel #13
0
        /// <summary>
        /// Create a Revit Floor given it's curve outline and Level
        /// </summary>
        /// <param name="outline"></param>
        /// <param name="floorType"></param>
        /// <param name="level"></param>
        /// <returns>The floor</returns>
        public static Floor ByOutlineTypeAndLevel(PolyCurve outline, FloorType floorType, Level level)
        {
            if (outline == null)
            {
                throw new ArgumentNullException("outline");
            }

            if (floorType == null)
            {
                throw new ArgumentNullException("floorType");
            }

            if (level == null)
            {
                throw new ArgumentNullException("level");
            }

            if (!outline.IsClosed)
            {
                throw new ArgumentException("The input PolyCurve is not closed");
            }

            var ca = new CurveArray();

            outline.Curves().ForEach(x => ca.Append(x.ToRevitType()));

            return(new Floor(ca, floorType.InternalFloorType, level.InternalLevel));
        }
Beispiel #14
0
        /// <summary>
        /// Create a Revit Floor given it's curve outline and Level
        /// </summary>
        /// <param name="outlineCurves"></param>
        /// <param name="floorType"></param>
        /// <param name="level"></param>
        /// <returns>The floor</returns>
        public static Floor ByOutlineTypeAndLevel(Curve[] outlineCurves, FloorType floorType, Level level)
        {
            if (outlineCurves == null)
            {
                throw new ArgumentNullException("outlineCurves");
            }

            return(ByOutlineTypeAndLevel(PolyCurve.ByJoinedCurves(outlineCurves), floorType, level));
        }
Beispiel #15
0
        /// <summary>
        /// Create a Revit Level given it's length offset from an existing level
        /// </summary>
        /// <param name="level"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public static Level ByLevelAndOffset(Level level, double offset)
        {
            if (level == null)
            {
                throw new ArgumentNullException("level");
            }

            return new Level(level.Elevation + offset * UnitConverter.DynamoToHostFactor, null);
        }
Beispiel #16
0
        public static Dictionary <string, object> ChangeFittingsLevel(List <Revit.Elements.Element> elements, Revit.Elements.Level endLevel)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            string result = "";

            Autodesk.Revit.DB.Element ll = doc.GetElement(endLevel.UniqueId.ToString());
            double    ofEndLevel         = ll.get_Parameter(BuiltInParameter.LEVEL_ELEV).AsDouble();
            ElementId endLeveliD         = ll.Id;

            try
            {
                foreach (Revit.Elements.Element e in elements)
                {
                    Autodesk.Revit.DB.Element el = doc.GetElement(e.UniqueId.ToString());
                    double    elOffset           = el.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM).AsDouble();
                    ElementId startLevel         = el.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).AsElementId();
                    double    ofStartLevel       = doc.GetElement(startLevel).get_Parameter(BuiltInParameter.LEVEL_ELEV).AsDouble();
                    double    newOffset          = -ofEndLevel + elOffset + ofStartLevel;
                    el.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM).Set(newOffset);
                    el.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).Set(endLeveliD);
                }

                result = "Executed";
            }
            catch (Exception ex)
            {
                result = "Not executed: " + ex.Message;
            }

            return(new Dictionary <string, object>
            {
                { "elements", elements },
                { "result", result }
            });
        }
Beispiel #17
0
        /// <summary>
        /// Create a Revit Level given a distance offset from an existing 
        /// level and a name for the new level
        /// </summary>
        /// <param name="level"></param>
        /// <param name="offset"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Level ByLevelOffsetAndName(Level level, double offset, string name)
        {
            if (level == null)
            {
                throw new ArgumentNullException("level");
            }

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            return new Level(level.Elevation + offset * UnitConverter.DynamoToHostFactor, name);
        }
Beispiel #18
0
        //bits and pieces from https://github.com/DynamoDS/DynamoRevit/blob/Revit2017/src/Libraries/RevitNodes/Elements/Wall.cs
        /// <summary>
        /// Say Hello, generates Revit walls based on an input text as driving curve
        /// </summary>
        /// <param name="text">Text to cenvert into Wall baselines</param>
        /// <param name="height">Wall Height</param>
        /// <param name="level">Wall Level</param>
        /// <param name="wallType">Wall Type</param>
        /// <param name="size">Font Size</param>
        /// <returns></returns>
        public static IEnumerable <Revit.Elements.Wall> SayHello(
            string text,
            double height,
            Revit.Elements.Level level,
            Revit.Elements.WallType wallType,
            int size = 25
            )
        {
            //first check inputs
            if (level == null)
            {
                throw new ArgumentNullException("level");
            }
            if (wallType == null)
            {
                throw new ArgumentNullException("wallType");
            }

            // allocate a new list to hold the Revit walls we create
            var walls = new List <Revit.Elements.Wall>();

            // convert the text to Dynamo lines using our utility function
            var lines = TextUtils.TextToLines(text, size);

            // remember : elements creation and modification has to be inside of a transaction
            TransactionManager.Instance.EnsureInTransaction(Document);

            foreach (var curve in lines)
            {
                // we can't skip null curves so let's check for this
                if (curve == null)
                {
                    throw new ArgumentNullException("curve");
                }

                try
                {
                    // now let's create the wall in Revit
                    var wall = Autodesk.Revit.DB.Wall.Create(
                        Document,                    // the current Revit document
                        curve.ToRevitType(),         // the curve to create wall on, note we need to convert Dynamo curves to Revit types
                        wallType.InternalElement.Id, // Revit elements returned from Dynamo are wrapped, so we need to access the internal element directly
                        level.InternalElement.Id,    // the level to base this wall at
                        height,                      // the unconnected height of the wall
                        0.0,                         // the offset
                        false,                       // flip or not
                        false                        // structural or not
                        );

                    // then add this to our list of new Revit walls
                    walls.Add(wall.ToDSType(false) as Revit.Elements.Wall);
                }
                catch (Exception ex)
                {
                    // if something went wrong when creating the Revit wall,
                    // raise an exception so the error is surfaced in Dynamo
                    throw new ArgumentException(ex.Message);
                }
            }
            // we need to close the transaction, telling Revit we are done with creating and modifying elements
            TransactionManager.Instance.TransactionTaskDone();

            // finally, let's return our walls.
            return(walls);
        }
Beispiel #19
0
 public static double InternalElevation(Revit.Elements.Level level)
 {
     return((level.InternalElement as Autodesk.Revit.DB.Level).Elevation);
 }
Beispiel #20
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 #21
0
        /// <summary>
        /// Creates a PipePlaceholder by two points.
        /// </summary>
        /// <param name="pipeType">Type of the pipe.</param>
        /// <param name="systemType">Type of the system.</param>
        /// <param name="start">The start.</param>
        /// <param name="end">The end.</param>
        /// <param name="level">The level.</param>
        /// <returns></returns>
        public static PipePlaceHolder ByPoints(Revit.Elements.Element pipeType, Revit.Elements.Element systemType, Autodesk.DesignScript.Geometry.Point start, Autodesk.DesignScript.Geometry.Point end, Revit.Elements.Level level)
        {
            Utils.Log(string.Format("PipePlaceHolder.ByPoints started...", ""));

            var oType          = pipeType.InternalElement as Autodesk.Revit.DB.Plumbing.PipeType;
            var oSystemType    = systemType.InternalElement as Autodesk.Revit.DB.Plumbing.PipingSystemType;
            var totalTransform = RevitUtils.DocumentTotalTransform();

            var nstart = start.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point;
            var s      = nstart.ToXyz();
            var nend   = end.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point;
            var e      = nend.ToXyz();
            var l      = level.InternalElement as Autodesk.Revit.DB.Level;

            if (nstart != null)
            {
                nstart.Dispose();
            }
            if (nend != null)
            {
                nend.Dispose();
            }

            Utils.Log(string.Format("PipePlaceHolder.ByPoints completed.", ""));

            return(new PipePlaceHolder(oType, oSystemType, s, e, l));
        }
Beispiel #22
0
        /// <summary>
        /// Create a Revit Wall from a guiding Curve, height, Level, and WallType
        /// </summary>
        /// <param name="curve"></param>
        /// <param name="height"></param>
        /// <param name="level"></param>
        /// <param name="wallType"></param>
        /// <returns></returns>
        public static Wall ByCurveAndHeight(Autodesk.DesignScript.Geometry.Curve curve, double height, Level level, WallType wallType)
        {
            if (curve == null)
            {
                throw new ArgumentNullException("curve");
            }

            if (level == null)
            {
                throw new ArgumentNullException("level");
            }

            if (wallType == null)
            {
                throw new ArgumentNullException("wallType");
            }

            height = height*UnitConverter.DynamoToHostFactor;

            if (height < 1e-6 || height > 30000)
            {
                throw new ArgumentException(
                    "The height must be greater than 0 and less that 30000 ft.  You provided a height of "
                        + height + " ft.");
            }

            return new Wall(curve.ToRevitType(), wallType.InternalWallType, level.InternalLevel, height, 0.0, false, false);
        }
Beispiel #23
0
        /// <summary>
        /// Create a Revit Floor given it's curve outline and Level
        /// </summary>
        /// <param name="outlineCurves"></param>
        /// <param name="floorType"></param>
        /// <param name="level"></param>
        /// <returns>The floor</returns>
        public static Floor ByOutlineTypeAndLevel(Curve[] outlineCurves, FloorType floorType, Level level)
        {
            if (outlineCurves == null)
            {
                throw new ArgumentNullException("outlineCurves");
            }

            return ByOutlineTypeAndLevel(PolyCurve.ByJoinedCurves(outlineCurves), floorType, level);
        }
Beispiel #24
0
        /// <summary>
        /// Create a Revit Level given it's length offset from an existing level
        /// </summary>
        /// <param name="level"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public static Level ByLevelAndOffset(Level level, double offset)
        {
            if (level == null)
            {
                throw new ArgumentNullException("level");
            }

            return new Level(level.Elevation + offset, null);
        }