Beispiel #1
0
        /***************************************************/

        public static BH.oM.Geometry.Line LocationCurveColumn(this FamilyInstance familyInstance, RevitSettings settings = null)
        {
            settings = settings.DefaultIfNull();

            BH.oM.Geometry.Line curve = null;

            if (familyInstance.IsSlantedColumn)
            {
                curve = (familyInstance.Location as LocationCurve).Curve.IFromRevit() as BH.oM.Geometry.Line;
            }
            else
            {
                Parameter baseLevelParam = familyInstance.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_PARAM);
                if (baseLevelParam != null)
                {
                    Parameter topLevelParam   = familyInstance.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_PARAM);
                    Parameter baseOffsetParam = familyInstance.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM);
                    Parameter topOffsetParam  = familyInstance.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM);

                    double baseLevel  = (familyInstance.Document.GetElement(baseLevelParam.AsElementId()) as Level).ProjectElevation;
                    double topLevel   = (familyInstance.Document.GetElement(topLevelParam.AsElementId()) as Level).ProjectElevation;
                    double baseOffset = baseOffsetParam.AsDouble();
                    double topOffset  = topOffsetParam.AsDouble();

                    XYZ loc      = (familyInstance.Location as LocationPoint).Point;
                    XYZ baseNode = new XYZ(loc.X, loc.Y, baseLevel + baseOffset);
                    XYZ topNode  = new XYZ(loc.X, loc.Y, topLevel + topOffset);
                    curve = new oM.Geometry.Line {
                        Start = baseNode.PointFromRevit(), End = topNode.PointFromRevit()
                    };
                }
            }

            if (curve != null)
            {
                Output <double, double> extensions = familyInstance.ColumnExtensions(settings);
                double startExtension = extensions.Item1;
                double endExtension   = extensions.Item2;

                if (Math.Abs(startExtension) > settings.DistanceTolerance || Math.Abs(endExtension) > settings.DistanceTolerance)
                {
                    Vector direction = curve.Direction();
                    curve = new oM.Geometry.Line {
                        Start = curve.Start - direction * startExtension, End = curve.End + direction * endExtension
                    };
                }
            }

            if (curve == null)
            {
                familyInstance.FramingCurveNotFoundWarning();
            }

            return(curve);
        }
Beispiel #2
0
        /***************************************************/

        public static ICurve LocationCurveFraming(this FamilyInstance familyInstance, RevitSettings settings = null)
        {
            settings = settings.DefaultIfNull();

            ICurve curve = (familyInstance.Location as LocationCurve)?.Curve?.IFromRevit();

            if (curve == null || (!(curve is NurbsCurve) && curve.ILength() <= settings.DistanceTolerance))
            {
                familyInstance.FramingCurveNotFoundWarning();
                return(null);
            }

            BH.oM.Geometry.Line line = curve as BH.oM.Geometry.Line;
            if (line == null)
            {
                familyInstance.NonLinearFramingOffsetWarning();
                return(curve);
            }

            Transform transform = familyInstance.GetTotalTransform();
            Vector    dir       = line.Direction();

            BH.oM.Geometry.Plane startPlane = new oM.Geometry.Plane {
                Origin = line.Start, Normal = dir
            };
            BH.oM.Geometry.Plane endPlane = new oM.Geometry.Plane {
                Origin = line.End, Normal = dir
            };
            BH.oM.Geometry.Line transformedLine = BH.Engine.Geometry.Create.Line(transform.Origin.PointFromRevit(), transform.BasisX.VectorFromRevit());
            line = new BH.oM.Geometry.Line {
                Start = transformedLine.PlaneIntersection(startPlane, true), End = transformedLine.PlaneIntersection(endPlane, true)
            };

            double startExtension = familyInstance.LookupParameterDouble(BuiltInParameter.START_EXTENSION);

            if (!double.IsNaN(startExtension))
            {
                line.Start = line.Start - dir * startExtension;
            }

            double endExtension = familyInstance.LookupParameterDouble(BuiltInParameter.END_EXTENSION);

            if (!double.IsNaN(endExtension))
            {
                line.End = line.End + dir * endExtension;
            }

            return(line);
        }