Esempio n. 1
0
        /// <summary>
        /// Creates a Wall following the geometry of a surface.
        /// Walls by Faces cannot be updated, any geometry change will
        /// create a new wall and delete the old one.
        /// </summary>
        /// <param name="locationLine"></param>
        /// <param name="wallType"></param>
        /// <param name="surface"></param>
        /// <returns></returns>
        public static Element ByFace(string locationLine, WallType wallType, Autodesk.DesignScript.Geometry.Surface surface)
        {
            WallLocationLine loc = WallLocationLine.CoreCenterline;

            if (!Enum.TryParse <WallLocationLine>(locationLine, out loc))
            {
                loc = WallLocationLine.CoreCenterline;
            }

            return(FaceWall.ByFace(loc, wallType, surface));
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        internal static FaceWall ByFace(WallLocationLine locationLine, WallType wallType, Autodesk.DesignScript.Geometry.Surface surface)
        {
            object reference = surface.Tags.LookupTag("RevitFaceReference");

            if (reference != null && reference.GetType() == typeof(Reference))
            {
                try
                {
                    var revitReference = reference as Reference;
                    return(new FaceWall(locationLine, wallType.InternalWallType, revitReference));
                }
                catch (Exception) { throw new Exception(Properties.Resources.InvalidFace); }
            }
            return(null);
        }
Esempio n. 4
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);
                }
Esempio n. 5
0
        void ReconstructWallByCurve
        (
            Document doc,
            ref Autodesk.Revit.DB.Element element,

            Rhino.Geometry.Curve curve,
            Optional <Autodesk.Revit.DB.WallType> type,
            Optional <Autodesk.Revit.DB.Level> level,
            [Optional] bool structural,
            [Optional] double height,
            [Optional] WallLocationLine locationLine,
            [Optional] bool flipped,
            [Optional, NickName("J")] bool allowJoins
        )
        {
            var scaleFactor = 1.0 / Revit.ModelUnits;

            if
            (
                scaleFactor != 1.0 ? !curve.Scale(scaleFactor) : true &&
                curve.IsShort(Revit.ShortCurveTolerance) ||
                !(curve.IsLinear(Revit.VertexTolerance) || curve.IsArc(Revit.VertexTolerance)) ||
                !curve.TryGetPlane(out var axisPlane, Revit.VertexTolerance) ||
                axisPlane.ZAxis.IsParallelTo(Rhino.Geometry.Vector3d.ZAxis) == 0
            )
            {
                ThrowArgumentException(nameof(curve), "Curve must be a horizontal line or arc curve");
            }

            SolveOptionalType(ref type, doc, ElementTypeGroup.WallType, nameof(type));

            double axisMinZ     = Math.Min(curve.PointAtStart.Z, curve.PointAtEnd.Z);
            bool   levelIsEmpty = SolveOptionalLevel(ref level, doc, curve, nameof(level));

            height *= scaleFactor;
            if (height < Revit.VertexTolerance)
            {
                height = (type.HasValue ? type.Value : null)?.GetCompoundStructure()?.SampleHeight ?? LiteralLengthValue(6.0) / Revit.ModelUnits;
            }

            // Axis
            var levelPlane = new Rhino.Geometry.Plane(new Rhino.Geometry.Point3d(0.0, 0.0, level.Value.Elevation), Rhino.Geometry.Vector3d.ZAxis);

            curve = Rhino.Geometry.Curve.ProjectToPlane(curve, levelPlane);

            var curves = curve.ToHost().ToArray();

            Debug.Assert(curves.Length == 1);
            var centerLine = curves[0];

            // LocationLine
            if (locationLine != WallLocationLine.WallCenterline)
            {
                double offsetDist        = 0.0;
                var    compoundStructure = type.Value.GetCompoundStructure();
                if (compoundStructure == null)
                {
                    switch (locationLine)
                    {
                    case WallLocationLine.WallCenterline:
                    case WallLocationLine.CoreCenterline:
                        break;

                    case WallLocationLine.FinishFaceExterior:
                    case WallLocationLine.CoreExterior:
                        offsetDist = type.Value.Width / +2.0;
                        break;

                    case WallLocationLine.FinishFaceInterior:
                    case WallLocationLine.CoreInterior:
                        offsetDist = type.Value.Width / -2.0;
                        break;
                    }
                }
                else
                {
                    if (!compoundStructure.IsVerticallyHomogeneous())
                    {
                        compoundStructure = CompoundStructure.CreateSimpleCompoundStructure(compoundStructure.GetLayers());
                    }

                    offsetDist = compoundStructure.GetOffsetForLocationLine(locationLine);
                }

                if (offsetDist != 0.0)
                {
                    centerLine = centerLine.CreateOffset(flipped ? -offsetDist : offsetDist, XYZ.BasisZ);
                }
            }

            // Type
            ChangeElementTypeId(ref element, type.Value.Id);

            Wall newWall = null;

            if (element is Wall previousWall && previousWall.Location is LocationCurve locationCurve && centerLine.IsSameKindAs(locationCurve.Curve))
            {
                newWall = previousWall;

                locationCurve.Curve = centerLine;
            }
Esempio n. 6
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));
 }
Esempio n. 7
0
 internal static FaceWall ByFace(WallLocationLine location, WallType wallType, Reference reference)
 {
     return(new FaceWall(location, wallType.InternalWallType, reference));
 }