Exemple #1
0
 /// <summary>
 /// Create from an existign Revit element
 /// </summary>
 /// <param name="wallType"></param>
 /// <param name="isRevitOwned"></param>
 /// <returns></returns>
 internal static WallType FromExisting(Autodesk.Revit.DB.WallType wallType, bool isRevitOwned)
 {
     return(new WallType(wallType)
     {
         IsRevitOwned = isRevitOwned
     });
 }
Exemple #2
0
 public void SetNecessaryData(RevitDB.XYZ startPoint, RevitDB.XYZ endPoint, RevitDB.Level level, RevitDB.WallType type)
 {
     m_startPoint  = startPoint;
     m_endPoint    = endPoint;
     m_createlevel = level;
     m_createType  = type;
 }
        protected override void TrySolveInstance(IGH_DataAccess DA)
        {
            // grab input wall type
            DB.WallType wallType = default;
            if (!DA.GetData("Basic Wall Type", ref wallType))
            {
                return;
            }

            // make sure input wall type is a DB.WallKind.Basic
            if (wallType.Kind != DB.WallKind.Basic)
            {
                return;
            }

            // grab compound structure
            DA.SetData(
                "Compound Structure",
                new Types.DataObject <DB.CompoundStructure>(
                    apiObject: wallType.GetCompoundStructure(),
                    srcDocument: wallType.Document
                    )
                );
            // pipe the wall type parameters directly to component outputs
            PipeHostParameter <Types.WallWrapping>(DA, wallType, DB.BuiltInParameter.WRAPPING_AT_INSERTS_PARAM, "Wrapping at Insert");
            PipeHostParameter <Types.WallWrapping>(DA, wallType, DB.BuiltInParameter.WRAPPING_AT_ENDS_PARAM, "Wrapping at End");
            PipeHostParameter(DA, wallType, DB.BuiltInParameter.WALL_ATTR_WIDTH_PARAM, "Width");
            PipeHostParameter <Types.WallFunction>(DA, wallType, DB.BuiltInParameter.FUNCTION_PARAM, "Wall Function");
        }
Exemple #4
0
        /// <summary>
        /// Initialize a Wall element
        /// </summary>
        /// <param name="curve"></param>
        /// <param name="wallType"></param>
        /// <param name="baseLevel"></param>
        /// <param name="height"></param>
        /// <param name="offset"></param>
        /// <param name="flip"></param>
        /// <param name="isStructural"></param>
        private void InitWall(Curve curve, Autodesk.Revit.DB.WallType wallType, Autodesk.Revit.DB.Level baseLevel, double height, double offset, bool flip, bool isStructural)
        {
            // This creates a new wall and deletes the old one
            TransactionManager.Instance.EnsureInTransaction(Document);

            //Phase 1 - Check to see if the object exists and should be rebound
            var wallElem =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.Wall>(Document);

            bool successfullyUsedExistingWall = false;

            //There was a modelcurve, try and set sketch plane
            // if you can't, rebuild
            if (wallElem != null && wallElem.Location is Autodesk.Revit.DB.LocationCurve)
            {
                var wallLocation = wallElem.Location as Autodesk.Revit.DB.LocationCurve;
                if ((wallLocation.Curve is Autodesk.Revit.DB.Line == curve is Autodesk.Revit.DB.Line) ||
                    (wallLocation.Curve is Autodesk.Revit.DB.Arc == curve is Autodesk.Revit.DB.Arc) ||
                    (wallLocation.Curve is Autodesk.Revit.DB.Ellipse == curve is Autodesk.Revit.DB.Ellipse))
                {
                    if (!CurveUtils.CurvesAreSimilar(wallLocation.Curve, curve))
                    {
                        wallLocation.Curve = curve;
                    }

                    Autodesk.Revit.DB.Parameter baseLevelParameter =
                        wallElem.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.WALL_BASE_CONSTRAINT);
                    Autodesk.Revit.DB.Parameter topOffsetParameter =
                        wallElem.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.WALL_USER_HEIGHT_PARAM);
                    Autodesk.Revit.DB.Parameter wallTypeParameter =
                        wallElem.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.ELEM_TYPE_PARAM);
                    if (baseLevelParameter.AsElementId() != baseLevel.Id)
                    {
                        baseLevelParameter.Set(baseLevel.Id);
                    }
                    if (Math.Abs(topOffsetParameter.AsDouble() - height) > 1.0e-10)
                    {
                        topOffsetParameter.Set(height);
                    }
                    if (wallTypeParameter.AsElementId() != wallType.Id)
                    {
                        wallTypeParameter.Set(wallType.Id);
                    }
                    successfullyUsedExistingWall = true;
                }
            }

            var wall = successfullyUsedExistingWall ? wallElem :
                       Autodesk.Revit.DB.Wall.Create(Document, curve, wallType.Id, baseLevel.Id, height, offset, flip, isStructural);

            InternalSetWall(wall);

            TransactionManager.Instance.TransactionTaskDone();

            // delete the element stored in trace and add this new one
            ElementBinder.CleanupAndSetElementForTrace(Document, InternalWall);
        }
Exemple #5
0
        void CommitInstance
        (
            Document doc, IGH_DataAccess DA, int Iteration,
            Rhino.Geometry.Curve curve,
            Autodesk.Revit.DB.WallType wallType,
            Autodesk.Revit.DB.Level level,
            bool structural,
            double height
        )
        {
            var element = PreviousElement(doc, Iteration);

            try
            {
                if (element?.Pinned ?? true)
                {
                    var scaleFactor = 1.0 / Revit.ModelUnits;
                    if (scaleFactor != 1.0)
                    {
                        height *= scaleFactor;
                        curve?.Scale(scaleFactor);
                    }

                    if
                    (
                        curve == null ||
                        curve.IsShort(Revit.ShortCurveTolerance) ||
                        !(curve.IsArc(Revit.VertexTolerance) || curve.IsLinear(Revit.VertexTolerance)) ||
                        !curve.TryGetPlane(out var axisPlane, Revit.VertexTolerance) ||
                        axisPlane.ZAxis.IsParallelTo(Rhino.Geometry.Vector3d.ZAxis) == 0
                    )
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Parameter '{0}' must be a horizontal line or arc curve.", Params.Input[0].Name));
                    }
                    else if (level == null)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Parameter '{0}' no suitable level is been found.", Params.Input[3].Name));
                    }
                    else if (height < Revit.VertexTolerance)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Parameter '{0}' is too small.", Params.Input[5].Name));
                    }
                    else
                    {
                        var axisList = curve.ToHost().ToList();
                        Debug.Assert(axisList.Count == 1);

                        element = Autodesk.Revit.DB.Wall.Create(doc, axisList[0], wallType.Id, level.Id, height, axisPlane.Origin.Z - level.Elevation, false, structural);
                    }
                }
            }
Exemple #6
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);
            }
        }
Exemple #7
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);
            }
        }
Exemple #8
0
        /// <summary>
        /// Initialize a Wall element
        /// </summary>
        /// <param name="location"></param>
        /// <param name="wallType"></param>
        /// <param name="reference"></param>
        private void InitFaceWall(WallLocationLine location, Autodesk.Revit.DB.WallType wallType, Autodesk.Revit.DB.Reference reference)
        {
            TransactionManager.Instance.EnsureInTransaction(Document);

            // there is no way of comparing the existing element to the new reference.
            // that's why the wall will be recreated.

            var wall = Autodesk.Revit.DB.FaceWall.Create(Document, wallType.Id, location, reference);

            InternalSetFaceWall(wall);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.CleanupAndSetElementForTrace(Document, InternalFaceWall);
        }
Exemple #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 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);
        }
Exemple #10
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);
        }
Exemple #11
0
        protected override void TrySolveInstance(IGH_DataAccess DA)
        {
            // grab input wall type
            DB.WallType wallType = default;
            if (!DA.GetData("Curtain Wall Type", ref wallType))
            {
                return;
            }

            if (wallType.Kind == DB.WallKind.Curtain)
            {
                // properties of the wall type
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.FUNCTION_PARAM, "Function");
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.ALLOW_AUTO_EMBED, "Automatically Embed");
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.AUTO_PANEL_WALL, "Curtain Panel");
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.AUTO_JOIN_CONDITION_WALL, "Join Condition");

                // layout (vertical)
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.SPACING_LAYOUT_VERT, "Vertical Grid : Layout");
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.SPACING_LENGTH_VERT, "Vertical Grid : Spacing");
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.CURTAINGRID_ADJUST_BORDER_VERT, "Vertical Grid : Adjust for Mullion Size");

                // layout (horizontal)
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.SPACING_LAYOUT_HORIZ, "Horizontal Grid : Layout");
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.SPACING_LENGTH_HORIZ, "Horizontal Grid : Spacing");
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.CURTAINGRID_ADJUST_BORDER_HORIZ, "Horizontal Grid : Adjust for Mullion Size");

                // mullion types(vertical)
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.AUTO_MULLION_INTERIOR_VERT, "Vertical Mullions : Interior Type");
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.AUTO_MULLION_BORDER1_VERT, "Vertical Mullions : Border 1 Type");
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.AUTO_MULLION_BORDER2_VERT, "Vertical Mullions : Border 2 Type");

                // mullion types (horizontal)
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.AUTO_MULLION_INTERIOR_HORIZ, "Horizontal Mullions : Interior Type");
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.AUTO_MULLION_BORDER1_HORIZ, "Horizontal Mullions : Border 1 Type");
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.AUTO_MULLION_BORDER2_HORIZ, "Horizontal Mullions : Border 2 Type");
            }
        }
        protected override void TrySolveInstance(IGH_DataAccess DA)
        {
            // grab input wall type
            DB.WallType wallType = default;
            if (!DA.GetData("Curtain Wall Type", ref wallType))
            {
                return;
            }

            if (wallType.Kind == DB.WallKind.Curtain)
            {
                // properties of the wall type
                PipeHostParameter <Types.WallFunction>(DA, wallType, DB.BuiltInParameter.FUNCTION_PARAM, "Wall Function");
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.ALLOW_AUTO_EMBED, "Automatically Embed?");
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.AUTO_PANEL_WALL, "Curtain Panel Type");
                PipeHostParameter <Types.CurtainGridJoinCondition>(DA, wallType, DB.BuiltInParameter.AUTO_JOIN_CONDITION_WALL, "Curtain Grid Join Condition");

                // layout (vertical)
                PipeHostParameter <Types.CurtainGridLayout>(DA, wallType, DB.BuiltInParameter.SPACING_LAYOUT_VERT, "Vertical Grid Layout (U Axis)");
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.SPACING_LENGTH_VERT, "Vertical Grid Spacing (U Axis)");
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.CURTAINGRID_ADJUST_BORDER_VERT, "Vertical Grid Adjust for Mullion Size? (U Axis)");

                // layout (horizontal)
                PipeHostParameter <Types.CurtainGridLayout>(DA, wallType, DB.BuiltInParameter.SPACING_LAYOUT_HORIZ, "Horizontal Grid Layout (V Axis)");
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.SPACING_LENGTH_HORIZ, "Horizontal Grid Spacing (V Axis)");
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.CURTAINGRID_ADJUST_BORDER_HORIZ, "Horizontal Grid Adjust for Mullion Size? (V Axis)");

                // mullion types(vertical)
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.AUTO_MULLION_INTERIOR_VERT, "Vertical Interior Mullion Type (U Axis)");
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.AUTO_MULLION_BORDER1_VERT, "Vertical Start Mullion Type (U Axis / Border 1)");
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.AUTO_MULLION_BORDER2_VERT, "Vertical End Mullion Type (U Axis / Border 2)");

                // mullion types (horizontal)
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.AUTO_MULLION_INTERIOR_HORIZ, "Horizontal Interior Mullion Type (V Axis)");
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.AUTO_MULLION_BORDER1_HORIZ, "Horizontal Bottom Mullion Type (V Axis / Border 1)");
                PipeHostParameter(DA, wallType, DB.BuiltInParameter.AUTO_MULLION_BORDER2_HORIZ, "Horizontal Top Mullion Type (V Axis / Border 2)");
            }
        }
Exemple #13
0
        private void ReadJournalData()
        {
            RevitDB.Document             doc     = m_commandData.Application.ActiveUIDocument.Document;
            IDictionary <string, string> dataMap = m_commandData.JournalData;
            string dataValue = null;

            dataValue = GetSpecialData(dataMap, "Wall Type Name");
            foreach (RevitDB.WallType type in m_wallTypeList)
            {
                if (dataValue == type.Name)
                {
                    m_createType = type;
                    break;
                }
            }
            if (null == m_createType)
            {
                throw new InvalidDataException("Can't find the wall type from the journal.");
            }

            dataValue = GetSpecialData(dataMap, "Level Id");
            RevitDB.ElementId id = new RevitDB.ElementId(Convert.ToInt32(dataValue));

            m_createlevel = doc.GetElement(id) as RevitDB.Level;
            if (null == m_createlevel)
            {
                throw new InvalidDataException("Can't find the level from the journal.");
            }

            dataValue    = GetSpecialData(dataMap, "Start Point");
            m_startPoint = StringToXYZ(dataValue);

            if (m_startPoint.Equals(m_endPoint))
            {
                throw new InvalidDataException("Start point is equal to end point.");
            }
        }
Exemple #14
0
        /// <summary>
        /// Converts Face3D to Wall
        /// </summary>
        /// <param name="face3D">SAM Geometry Face3D</param>
        /// <param name="document">Revit Document</param>
        /// <param name="wallType">Revit WallType. Default WallType will be used if null</param>
        /// <param name="level">Revit Level. Low Level for Face3D will be used if null</param>
        /// <returns>Revit Wall</returns>
        public static Autodesk.Revit.DB.Wall ToRevit_Wall(this Geometry.Spatial.Face3D face3D, Document document, Autodesk.Revit.DB.WallType wallType = null, Level level = null)
        {
            if (face3D == null || document == null)
            {
                return(null);
            }

            if (face3D.GetArea() < Core.Tolerance.MacroDistance)
            {
                return(null);
            }

            Geometry.Spatial.Vector3D normal = face3D.GetPlane().Normal;
            if (normal == null)
            {
                return(null);
            }

            if (wallType == null)
            {
                ElementId elementId = document.Settings.Categories.get_Item(BuiltInCategory.OST_Walls).Id;
                if (elementId != null && elementId != ElementId.InvalidElementId)
                {
                    elementId = document.GetDefaultFamilyTypeId(elementId);
                    if (elementId != null && elementId != ElementId.InvalidElementId)
                    {
                        wallType = document.GetElement(elementId) as Autodesk.Revit.DB.WallType;
                    }
                }
            }

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

            if (level == null)
            {
                double elevation = Geometry.Revit.Convert.ToRevit(face3D.GetBoundingBox().Min).Z;
                level = Core.Revit.Query.LowLevel(document, elevation);
            }

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

            List <CurveLoop> curveLoops = Geometry.Revit.Convert.ToRevit(face3D);

            curveLoops?.RemoveAll(x => x == null);
            if (curveLoops == null || curveLoops.Count == 0)
            {
                return(null);
            }

            XYZ xyz_Normal = Geometry.Revit.Convert.ToRevit(normal, false);

            if (curveLoops.Count == 1)
            {
                return(Autodesk.Revit.DB.Wall.Create(document, curveLoops[0].ToList(), wallType.Id, level.Id, false, xyz_Normal));
            }

            //The Wall.Create method requires the curveLoops to be in either all counter-clockwise direction or all clockwise direction.
            for (int i = 0; i < curveLoops.Count; i++)
            {
                if (curveLoops[i].IsCounterclockwise(xyz_Normal))
                {
                    curveLoops[i].Flip();
                }
            }

            List <Curve> curves = new List <Curve>();


            //According to https://forums.autodesk.com/t5/revit-api-forum/wall-create-by-profile/td-p/8961085
            //CurveLoops have to be organised in correct order. Hypothesis :
            //If the curveLoop contains 1 (or more) vertical Line(s), the vertical line should be the first to add to the List.
            foreach (CurveLoop curveLoop in curveLoops)
            {
                List <Curve> curves_Temp = curveLoop?.ToList();
                if (curveLoop == null)
                {
                    continue;
                }

                List <Curve> curves_Postponed = new List <Curve>();

                int startindex = 0;
                while (startindex < curves_Temp.Count)
                {
                    Curve curve = curves_Temp[startindex];
                    if (!(curve is Line))
                    {
                        curves_Postponed.Add(curve);
                        startindex++;
                        continue;
                    }
                    XYZ dir = curve.GetEndPoint(1).Subtract(curve.GetEndPoint(0)).Normalize();
                    if (!dir.IsAlmostEqualTo(XYZ.BasisZ) && !dir.IsAlmostEqualTo(XYZ.BasisZ.Negate()))
                    {
                        curves_Postponed.Add(curve);
                        startindex++;
                    }
                    else
                    {
                        break;
                    }
                }

                for (int i = startindex; i < curves_Temp.Count; i++)
                {
                    Curve curve = curves_Temp[i];
                    curves.Add(curve);
                }

                if (curves_Postponed.Count > 0)
                {
                    curves.AddRange(curves_Postponed);
                }
            }

            if (curves == null || curves.Count == 0)
            {
                return(null);
            }

            return(Autodesk.Revit.DB.Wall.Create(document, curves, wallType.Id, level.Id, false, xyz_Normal));
        }
Exemple #15
0
        public static Autodesk.Revit.DB.Wall CopyWall(this Document document, IEnumerable <Reference> references, Level level_Bottom, Level level_Top)
        {
            if (document == null || references == null || references.Count() < 1 || level_Bottom == null || level_Top == null)
            {
                return(null);
            }

            Dictionary <BuiltInCategory, FamilySymbol> dictionary_FamilySymbol = new Dictionary <BuiltInCategory, FamilySymbol>();

            dictionary_FamilySymbol.Add(BuiltInCategory.OST_Windows, new FilteredElementCollector(document).OfCategory(BuiltInCategory.OST_Windows).OfClass(typeof(FamilySymbol)).Cast <FamilySymbol>().ToList().Find(x => x.Name == "SIM_EXT_GLZ"));
            dictionary_FamilySymbol.Add(BuiltInCategory.OST_Doors, new FilteredElementCollector(document).OfCategory(BuiltInCategory.OST_Doors).OfClass(typeof(FamilySymbol)).Cast <FamilySymbol>().ToList().Find(x => x.Name == "SIM_INT_SLD"));

            Autodesk.Revit.DB.Wall result = null;

            Dictionary <ElementId, Tuple <Document, Dictionary <ElementId, List <FamilyInstance> > > > dictionary = new Dictionary <ElementId, Tuple <Document, Dictionary <ElementId, List <FamilyInstance> > > >();

            using (Transaction transaction = new Transaction(document, "Copy Wall"))
            {
                transaction.Start();
                foreach (Reference reference in references)
                {
                    if (reference.ElementId == null || reference.ElementId == ElementId.InvalidElementId)
                    {
                        continue;
                    }

                    if (reference.LinkedElementId == null || reference.LinkedElementId == ElementId.InvalidElementId)
                    {
                        continue;
                    }

                    RevitLinkInstance revitLinkInstance = document.GetElement(reference.ElementId) as RevitLinkInstance;

                    if (revitLinkInstance == null)
                    {
                        continue;
                    }

                    Tuple <Document, Dictionary <ElementId, List <FamilyInstance> > > tuple = null;
                    if (!dictionary.TryGetValue(revitLinkInstance.Id, out tuple))
                    {
                        Document document_RevitLinkInstance = revitLinkInstance.GetLinkDocument();

                        List <ElementFilter> elementFilters = new List <ElementFilter>();
                        elementFilters.Add(new ElementCategoryFilter(BuiltInCategory.OST_Doors));
                        elementFilters.Add(new ElementCategoryFilter(BuiltInCategory.OST_Windows));

                        List <FamilyInstance> familyInstances = new FilteredElementCollector(document_RevitLinkInstance).OfClass(typeof(FamilyInstance)).WherePasses(new LogicalOrFilter(elementFilters)).Cast <FamilyInstance>().ToList();

                        Dictionary <ElementId, List <FamilyInstance> > dictionary_FamilyInstance = new Dictionary <ElementId, List <FamilyInstance> >();
                        foreach (FamilyInstance familyInstance in familyInstances)
                        {
                            if (familyInstance.Host == null || familyInstance.Host.Id == null || familyInstance.Host.Id == ElementId.InvalidElementId)
                            {
                                continue;
                            }

                            List <FamilyInstance> familyInstances_Temp = null;
                            if (!dictionary_FamilyInstance.TryGetValue(familyInstance.Host.Id, out familyInstances_Temp))
                            {
                                familyInstances_Temp = new List <FamilyInstance>();
                                dictionary_FamilyInstance.Add(familyInstance.Host.Id, familyInstances_Temp);
                            }
                            familyInstances_Temp.Add(familyInstance);
                        }

                        tuple = new Tuple <Document, Dictionary <ElementId, List <FamilyInstance> > >(document_RevitLinkInstance, dictionary_FamilyInstance);

                        dictionary.Add(revitLinkInstance.Id, tuple);
                    }

                    if (tuple.Item1 == null)
                    {
                        continue;
                    }

                    Element element = tuple.Item1.GetElement(reference.LinkedElementId);
                    if (element == null)
                    {
                        continue;
                    }

                    if (element is Autodesk.Revit.DB.Wall)
                    {
                        Autodesk.Revit.DB.Wall     wall     = element as Autodesk.Revit.DB.Wall;
                        Autodesk.Revit.DB.WallType wallType = UpdateWallType(document, wall);
                        result = CopyWall(wallType, wall, level_Bottom, level_Top, tuple.Item2, dictionary_FamilySymbol);
                    }
                }
                transaction.Commit();
            }

            return(result);
        }
Exemple #16
0
        private static Autodesk.Revit.DB.Wall CopyWall(Autodesk.Revit.DB.WallType wallType, Autodesk.Revit.DB.Wall Wall, Level level_Bottom, Level level_Top, Dictionary <ElementId, List <FamilyInstance> > dictionary_Hosts, Dictionary <BuiltInCategory, FamilySymbol> dictionary_Symbols)
        {
            if (wallType == null || Wall == null)
            {
                return(null);
            }

            if (!(Wall.Location is LocationCurve))
            {
                return(null);
            }

            LocationCurve locationCurve = Wall.Location as LocationCurve;

            Document document = wallType.Document;

            Autodesk.Revit.DB.Wall result = Autodesk.Revit.DB.Wall.Create(wallType.Document, locationCurve.Curve, level_Bottom.Id, false);

            result.WallType = wallType;

            //FamilyInstance aFamilyInstance = aDocument.Create.NewFamilyInstance(aLocationCurve.Curve, ElementType, Level_Bottom, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
            if (result == null)
            {
                return(null);
            }

            if (Wall.Flipped != result.Flipped)
            {
                result.Flip();
            }

            Parameter parameter = null;

            if (level_Top.Elevation > level_Bottom.Elevation)
            {
                parameter = result.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE);
                if (parameter != null)
                {
                    parameter.Set(level_Top.Id);
                }
            }
            else
            {
                parameter = result.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM);
                if (parameter != null && !parameter.IsReadOnly)
                {
#if Revit2017 || Revit2018 || Revit2019 || Revit2020
                    parameter.Set(UnitUtils.ConvertToInternalUnits(2000, DisplayUnitType.DUT_MILLIMETERS));
#else
                    parameter.Set(UnitUtils.ConvertToInternalUnits(2000, UnitTypeId.Millimeters));
#endif
                }
            }

            parameter = result.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS);
            if (parameter != null)
            {
                parameter.Set(Wall.Id.IntegerValue.ToString());
            }

            document.Regenerate();

            AddHosts(result, Wall.Id, dictionary_Hosts, dictionary_Symbols);

            return(result);
        }
Exemple #17
0
 /// <summary>
 /// Create a new instance of WallType, deleting the original
 /// </summary>
 /// <param name="curve"></param>
 /// <param name="wallType"></param>
 /// <param name="baseLevel"></param>
 /// <param name="height"></param>
 /// <param name="offset"></param>
 /// <param name="flip"></param>
 /// <param name="isStructural"></param>
 private Wall(Curve curve, Autodesk.Revit.DB.WallType wallType, Autodesk.Revit.DB.Level baseLevel,
              double height, double offset, bool flip, bool isStructural)
 {
     SafeInit(() => InitWall(curve, wallType, baseLevel, height, offset, flip, isStructural));
 }
Exemple #18
0
        public static Autodesk.Revit.DB.WallType UpdateWallType(this Document document, Autodesk.Revit.DB.Wall wall)
        {
            List <Autodesk.Revit.DB.WallType> wallTypes = new FilteredElementCollector(document).OfCategory(BuiltInCategory.OST_Walls).OfClass(typeof(Autodesk.Revit.DB.WallType)).Cast <Autodesk.Revit.DB.WallType>().ToList();

            if (wallTypes == null || wallTypes.Count < 1)
            {
                return(null);
            }

            Autodesk.Revit.DB.WallType wallType = null;
            foreach (Autodesk.Revit.DB.WallType wallType_Temp in wallTypes)
            {
                Parameter parameter = wallType_Temp.LookupParameter("SAM_BuildingElementDescription");
                if (parameter != null)
                {
                    string value = parameter.AsString();
                    if (!string.IsNullOrEmpty(value) && value == wall.Name)
                    {
                        wallType = wallType_Temp;
                        break;
                    }
                }
            }

            if (wallType == null)
            {
                string name = string.Format("ARCH_Wall_{0}", wall.Name);
                wallType = wallTypes.Find(x => x.Name == name);
                if (wallType == null)
                {
                    wallType = wallTypes.Find(x => x.Name == "ARCH_Wall");
                    if (wallType == null)
                    {
                        wallType = wallTypes.First();
                        wallType = wallType.Duplicate(name) as Autodesk.Revit.DB.WallType;
                    }
                }

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

                Element element = wall.Document.GetElement(wall.GetTypeId());
                if (element == null)
                {
                    return(wallType);
                }

                Parameter parameter_Source      = null;
                Parameter parameter_Destination = null;

                parameter_Source = element.get_Parameter(BuiltInParameter.WALL_ATTR_WIDTH_PARAM);
                if (parameter_Source != null)
                {
                    parameter_Destination = wallType.LookupParameter("SAM_BuildingElementThickness");
                    if (parameter_Destination != null)
                    {
                        parameter_Destination.Set(parameter_Source.AsDouble());
                    }
                }

                parameter_Source = element.get_Parameter(BuiltInParameter.FUNCTION_PARAM);
                if (parameter_Source != null)
                {
                    parameter_Destination = wallType.LookupParameter("SAM_BuildingElementDescription");
                    if (parameter_Destination != null)
                    {
                        parameter_Destination.Set(name);
                    }

                    parameter_Destination = wallType.get_Parameter(BuiltInParameter.FUNCTION_PARAM);
                    if (parameter_Destination != null)
                    {
                        parameter_Destination.Set(parameter_Destination.AsInteger());
                    }
                }
            }

            return(wallType);
        }
Exemple #19
0
 public static WallType Wrap(Autodesk.Revit.DB.WallType ele, bool isRevitOwned)
 {
     return(WallType.FromExisting(ele, isRevitOwned));
 }
Exemple #20
0
        void CommitInstance
        (
            Document doc, IGH_DataAccess DA, int Iteration,
            Rhino.Geometry.Curve curve,
            Autodesk.Revit.DB.WallType wallType,
            Autodesk.Revit.DB.Level level,
            bool structural,
            double height
        )
        {
            var element = PreviousElement(doc, Iteration);

            try
            {
                if (element?.Pinned ?? true)
                {
                    var scaleFactor = 1.0 / Revit.ModelUnits;
                    if (scaleFactor != 1.0)
                    {
                        height *= scaleFactor;
                        curve?.Scale(scaleFactor);
                    }

                    if
                    (
                        curve == null ||
                        curve.IsShort(Revit.ShortCurveTolerance) ||
                        !(curve.IsArc(Revit.VertexTolerance) || curve.IsLinear(Revit.VertexTolerance)) ||
                        !curve.TryGetPlane(out var axisPlane, Revit.VertexTolerance) ||
                        axisPlane.ZAxis.IsParallelTo(Rhino.Geometry.Vector3d.ZAxis) == 0
                    )
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Parameter '{0}' must be a horizontal line or arc curve.", Params.Input[0].Name));
                    }
                    else if (level == null)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Parameter '{0}' no suitable level is been found.", Params.Input[3].Name));
                    }
                    else if (height < Revit.VertexTolerance)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Parameter '{0}' is too small.", Params.Input[5].Name));
                    }
                    else
                    {
                        var axisList = curve.ToHost().ToList();
                        Debug.Assert(axisList.Count == 1);

                        if (element != null && wallType.Id != element.GetTypeId())
                        {
                            var newElmentId = element.ChangeTypeId(wallType.Id);
                            if (newElmentId != ElementId.InvalidElementId)
                            {
                                element = doc.GetElement(newElmentId);
                            }
                        }

                        if (element is Wall wall && element?.Location is LocationCurve locationCurve)
                        {
                            locationCurve.Curve = axisList[0];
                            wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET).Set(0.0);
                            wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).Set(height);
                        }
                        else
                        {
                            element = Autodesk.Revit.DB.Wall.Create(doc, axisList[0], wallType.Id, level.Id, height, axisPlane.Origin.Z - level.Elevation, false, structural);
                        }
                    }
Exemple #21
0
 /// <summary>
 /// Construct from an existing Revit Element
 /// </summary>
 /// <param name="type"></param>
 private WallType(Autodesk.Revit.DB.WallType type) : base(type)
 {
 }
Exemple #22
0
        void CommitInstance
        (
            Document doc, IGH_DataAccess DA, int Iteration,
            Rhino.Geometry.Curve curve,
            Autodesk.Revit.DB.WallType wallType,
            Autodesk.Revit.DB.Level level,
            bool structural,
            double height,
            WallLocationLine locationLine
        )
        {
            var element = PreviousElement(doc, Iteration);

            if (!element?.Pinned ?? false)
            {
                ReplaceElement(doc, DA, Iteration, element);
            }
            else
            {
                try
                {
                    var scaleFactor = 1.0 / Revit.ModelUnits;
                    if (scaleFactor != 1.0)
                    {
                        height *= scaleFactor;
                        curve?.Scale(scaleFactor);
                    }

                    if
                    (
                        curve == null ||
                        curve.IsShort(Revit.ShortCurveTolerance) ||
                        !(curve.IsArc(Revit.VertexTolerance) || curve.IsLinear(Revit.VertexTolerance)) ||
                        !curve.TryGetPlane(out var axisPlane, Revit.VertexTolerance) ||
                        axisPlane.ZAxis.IsParallelTo(Rhino.Geometry.Vector3d.ZAxis) == 0
                    )
                    {
                        throw new Exception(string.Format("Parameter '{0}' must be a horizontal line or arc curve.", Params.Input[0].Name));
                    }

                    if (level == null)
                    {
                        throw new Exception(string.Format("Parameter '{0}' no suitable level is been found.", Params.Input[2].Name));
                    }

                    if (height < Revit.VertexTolerance)
                    {
                        throw new Exception(string.Format("Parameter '{0}' is too small.", Params.Input[4].Name));
                    }

                    var axisList = curve.ToHost().ToList();
                    Debug.Assert(axisList.Count == 1);
                    var    axis       = axisList[0];
                    double offsetDist = wallType.GetCompoundStructure().GetOffsetForLocationLine(locationLine);

                    if (offsetDist != 0.0)
                    {
                        axis = axis.CreateOffset(offsetDist, XYZ.BasisZ);
                    }

                    if (element != null && wallType.Id != element.GetTypeId())
                    {
                        var newElmentId = element.ChangeTypeId(wallType.Id);
                        if (newElmentId != ElementId.InvalidElementId)
                        {
                            element = doc.GetElement(newElmentId);
                            ReplaceElement(doc, DA, Iteration, element);
                        }
                    }

                    if (element is Wall wall && element?.Location is LocationCurve locationCurve && axisList[0].IsSameKindAs(locationCurve.Curve))
                    {
                        locationCurve.Curve = axis;
                        wall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).Set(level.Id);
                        wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET).Set(0.0);
                        wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).Set(height);
                    }
                    else
                    {
                        element = CopyParametersFrom(Wall.Create(doc, axis, wallType.Id, level.Id, height, axisPlane.Origin.Z - level.Elevation, false, structural), element);
                    }

                    element?.get_Parameter(BuiltInParameter.WALL_KEY_REF_PARAM).Set((int)locationLine);

                    ReplaceElement(doc, DA, Iteration, element);
                }
Exemple #23
0
 /// <summary>
 /// Create a new instance of WallType, deleting the original
 /// </summary>
 /// <param name="location"></param>
 /// <param name="wallType"></param>
 /// <param name="reference"></param>
 private FaceWall(WallLocationLine location, Autodesk.Revit.DB.WallType wallType, Autodesk.Revit.DB.Reference reference)
 {
     SafeInit(() => InitFaceWall(location, wallType, reference));
 }