Пример #1
0
        public static Dictionary <string, object> AllWallsOfType(Revit.Elements.WallType wallType)
        {
            Document doc = DocumentManager.Instance.CurrentDBDocument;
            FilteredElementCollector wallsCollector =
                new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType();

            var wallCollection = wallsCollector.ToElements();

            List <Revit.Elements.Element> wallTypes = new List <Revit.Elements.Element>();

            foreach (var element in wallCollection)
            {
                var wall = (Wall)element;
                if (wall.WallType.Id == wallType.InternalElement.Id)
                {
                    wallTypes.Add(wall.ToDSType(true));
                }
            }
            ;
            //returns the outputs
            var outInfo = new Dictionary <string, object>
            {
                { "walls", wallTypes }
            };

            return(outInfo);
        }
Пример #2
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);
        }
Пример #3
0
        /// <summary>
        /// Creates a compound structure from a wall type.
        /// </summary>
        /// <param name="wallType">A Dynamo wrapped Revit.WallType.</param>
        /// <param name="document">An unwrapped document associated with the CompoundStructure.</param>
        /// <returns name="compoundStructure">A Compound Structure.</returns>
        public static CompoundStructure FromWallType(dynamoElements.WallType wallType,
                                                     [DefaultArgument("Synthetic.Revit.Document.Current()")] revitDoc document)
        {
            revitDB.WallType unwrappedWall     = (revitDB.WallType)wallType.InternalElement;
            revitCS          compoundStructure = unwrappedWall.GetCompoundStructure();

            if (compoundStructure != null)
            {
                return(new CompoundStructure(compoundStructure, document));
            }
            else
            {
                return(null);
            }
        }
Пример #4
0
        /// <summary>
        /// Gets the compound structure from a wall type.
        /// </summary>
        /// <param name="WallType">A Dynamo wrapped Revit.WallType</param>
        /// <returns name="CompoundStructure">A Compound Structure</returns>
        public static CompoundStructure GetCompoundStructure(dynaWallType WallType)
        {
            revitDB.WallType unwrappedWall     = (revitDB.WallType)WallType.InternalElement;
            revitDoc         document          = unwrappedWall.Document;
            revitCS          compoundStructure = unwrappedWall.GetCompoundStructure();

            if (compoundStructure != null)
            {
                return(new CompoundStructure(compoundStructure, document));
            }
            else
            {
                return(null);
            }
        }
Пример #5
0
        public void ByElement_ValidArgs()
        {
            var line = Line.ByStartPointEndPoint(Point.ByCoordinates(0, 0, 0), Point.ByCoordinates(1000, 0, 0));

            Assert.NotNull(line);

            Autodesk.Revit.DB.FilteredElementCollector collector = new Autodesk.Revit.DB.FilteredElementCollector(Revit.Application.Document.Current.InternalDocument).OfClass(typeof(Autodesk.Revit.DB.WallType));
            Revit.Elements.WallType wt = Revit.Elements.WallType.FromExisting((Autodesk.Revit.DB.WallType)collector.FirstOrDefault(), true);

            var wall = Wall.ByCurveAndHeight(line, 300, Level.ByElevation(100), wt);

            Assert.NotNull(wall);

            var tag = Tag.ByElement(Revit.Application.Document.Current.ActiveView, wall, true, false, "Center", "Middle", Vector.ByCoordinates(0, 0, 0));

            Assert.NotNull(tag);
        }
Пример #6
0
        /// <summary>
        /// Replaces a Wall Type's compound structure with the given one.  Please note that the compound structure's materials and the wall type must be in the same document or unexpected results may occur.
        /// </summary>
        /// <param name="WallType">The wall type to be modified.</param>
        /// <param name="compoundStructure">A compound structure</param>
        /// <returns name="wallType">The modified wall type.</returns>
        public static dynamoElements.WallType ToWallType(dynamoElements.WallType WallType, CompoundStructure compoundStructure)
        {
            revitDB.WallType revitWallType = (revitDB.WallType)WallType.InternalElement;

            using (Autodesk.Revit.DB.Transaction trans = new Autodesk.Revit.DB.Transaction(compoundStructure.internalDocument))
            {
                try
                {
                    trans.Start("Apply Structure to Wall Type");
                    revitWallType.SetCompoundStructure(compoundStructure.internalCompoundStructure);
                    trans.Commit();
                }
                catch
                {
                    revitWallType.SetCompoundStructure(compoundStructure.internalCompoundStructure);
                }
            }
            return(WallType);
        }
Пример #7
0
        public void ByElementAndOffset_ValidArgs()
        {
            var line = Line.ByStartPointEndPoint(Point.ByCoordinates(0, 0, 0), Point.ByCoordinates(1000, 0, 0));

            Assert.NotNull(line);

            Autodesk.Revit.DB.FilteredElementCollector collector = new Autodesk.Revit.DB.FilteredElementCollector(Revit.Application.Document.Current.InternalDocument).OfClass(typeof(Autodesk.Revit.DB.WallType));
            Revit.Elements.WallType wt = Revit.Elements.WallType.FromExisting((Autodesk.Revit.DB.WallType)collector.FirstOrDefault(), true);

            var wall = Wall.ByCurveAndHeight(line, 300, Level.ByElevation(100), wt);

            Assert.NotNull(wall);

            var tag = Tag.ByElementAndOffset(Revit.Application.Document.Current.ActiveView, wall, Vector.ByCoordinates(0, 0, 0));

            Assert.NotNull(tag);
            Assert.NotNull(tag.InternalElement);
            Assert.IsInstanceOf(typeof(Autodesk.Revit.DB.IndependentTag), tag.InternalElement);
            var itag = tag.InternalElement as Autodesk.Revit.DB.IndependentTag;

            itag.TagHeadPosition.DistanceTo(new Autodesk.Revit.DB.XYZ(500, 0, 0)).ShouldBeApproximately(0);
        }
Пример #8
0
        public static List <Layer> GetLayers(Revit.Elements.WallType wallType)
        {
            Document document = DocumentManager.Instance.CurrentDBDocument;

            var wt = wallType.InternalElement as Autodesk.Revit.DB.WallType;
            CompoundStructure structure = wt.GetCompoundStructure();
            int layerCount     = structure.LayerCount;
            int strMaterialInd = structure.StructuralMaterialIndex;

            List <Layer> layers = new List <Layer>();

            for (int i = 0; i < layerCount; i++)
            {
                layers.Add(new Layer(structure.GetLayerFunction(i).ToString(),
                                     document.GetElement(structure.GetMaterialId(i)) as Autodesk.Revit.DB.Material,
                                     UnitUtils.ConvertFromInternalUnits(structure.GetLayerWidth(i), DisplayUnitType.DUT_MILLIMETERS),
                                     i == strMaterialInd,
                                     structure.IsCoreLayer(i)));
            }

            return(layers);
        }
Пример #9
0
        /// <summary>
        /// Replaces a Wall Type's compound structure with the given one.  Please note that the compound structure's materials and the wall type must be in the same document or unexpected results may occur.
        /// </summary>
        /// <param name="WallType">The wall type to be modified.</param>
        /// <param name="compoundStructure">A compound structure</param>
        /// <returns name="WallType">The modified wall type.</returns>
        public static dynaWallType SetCompoundStructure(dynaWallType WallType, CompoundStructure compoundStructure)
        {
            revitDB.WallType revitWallType = (revitDB.WallType)WallType.InternalElement;
            revitDoc         document      = compoundStructure.internalDocument;

            if (document.IsModifiable)
            {
                TransactionManager.Instance.EnsureInTransaction(document);
                revitWallType.SetCompoundStructure(compoundStructure.internalCompoundStructure);
                TransactionManager.Instance.TransactionTaskDone();
            }
            else
            {
                using (Autodesk.Revit.DB.Transaction trans = new Autodesk.Revit.DB.Transaction(document))
                {
                    trans.Start("Apply Structure to Wall Type");
                    revitWallType.SetCompoundStructure(compoundStructure.internalCompoundStructure);
                    trans.Commit();
                }
            }
            return(WallType);
        }
Пример #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");
            }

            // 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);
        }
Пример #11
0
 /// <summary>
 /// Get the document that the wall type belongs too.
 /// </summary>
 /// <param name="WallType">A Dynamo wrapped Revit.WallType</param>
 /// <returns name="Document">The Autodesk.Revit.DB.Document that the wall type belongs too.</returns>
 public static revitDoc Document(dynaWallType WallType)
 {
     return(WallType.InternalElement.Document);
 }
Пример #12
0
 public static string FamilyName(Revit.Elements.WallType wallType)
 {
     return((wallType.InternalElement as Autodesk.Revit.DB.WallType).FamilyName);
 }
Пример #13
0
 public static WallType Wrap(Autodesk.Revit.DB.WallType ele, bool isRevitOwned)
 {
     return(WallType.FromExisting(ele, isRevitOwned));
 }
Пример #14
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);
        }
Пример #15
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);
        }
Пример #16
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);
        }
Пример #17
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));
        }
Пример #18
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));
        }
Пример #19
0
 /// <summary>
 /// Overwrites the parameters and compound structure of the destintation wall type with the source wall type.
 /// </summary>
 /// <param name="wallType">A dynamo wrappped WallType to overwrite</param>
 /// <param name="SourceWallType">A dynamo wrapped WallType to use as the source</param>
 /// <returns name="DestinationWallType">The destinatio WallType</returns>
 public static dynaWallType TransferWallTypeProperties(dynaWallType wallType, dynaWallType SourceWallType)
 {
     Elements.TransferParameters(SourceWallType, wallType);
     WallType.SetCompoundStructure(wallType, WallType.GetCompoundStructure(SourceWallType));
     return(wallType);
 }
Пример #20
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(UnitType.UT_Length);

            if (height < 1e-6 || height > 30000)
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidWallHeight, height));
            }

            return(new Wall(curve.ToRevitType(), wallType.InternalWallType, level.InternalLevel, height, 0.0, false, false));
        }