Ejemplo n.º 1
0
        private Value GetCurvesFromFamily(Autodesk.Revit.DB.FamilyInstance fi, int count,
                                          Autodesk.Revit.DB.Options options)
        {
            FamilySymbol fs = fi.Symbol;

            //Autodesk.Revit.DB.GeometryElement geomElem = fs.get_Geometry(options);
            Autodesk.Revit.DB.GeometryElement geomElem = fi.get_Geometry(options);
            // our particular case of a loaded mass family with no joins has no geom in the instance

            //fi.GetOriginalGeometry(options);
            //fi.GetTransform()

            Autodesk.Revit.DB.CurveArray     curves    = new CurveArray();
            Autodesk.Revit.DB.ReferenceArray curveRefs = new ReferenceArray();


            //Find all curves and insert them into curve array
            AddCurves(fi, geomElem, count, ref curves);

            //curves.Append(GetCurve(fi, options)); //test

            //extract references for downstream use
            foreach (Curve c in curves)
            {
                curveRefs.Append(c.Reference);
            }

            //convert curvearray into list using Stephens MakeEnumerable
            Value result = Value.NewList(Utils.SequenceToFSharpList(
                                             dynUtils.MakeEnumerable(curves).Select(Value.NewContainer)
                                             ));


            return(result);
        }
        /// <summary>
        ///
        ///     Determine if the Geometry extracted from a FamilyInstance requires transformation.
        ///
        ///     Bizarrely, some FamilyInstance's geom is transformed and some not when obtained
        ///     from GetGeometryObjectFromReference.  This is because some need to be transformed
        ///     to interact with adjacent geometry in the document.  This stop-gap, suggested by
        ///     SC in the Revit API team, checks if there are any non-empty GeometryInstances in
        ///     FamilyInstance's geometry.  Apparently this is a good heuristic for checking if
        ///     the geometry requires a transform or not.
        ///
        /// </summary>
        /// <param name="familyInstance"></param>
        /// <returns></returns>
        private static bool RequiresTransform(Autodesk.Revit.DB.FamilyInstance familyInstance)
        {
            var geom = familyInstance.get_Geometry(new Options());

            return(geom.OfType <Autodesk.Revit.DB.GeometryInstance>()
                   .Any(x => x.GetInstanceGeometry().Any()));
        }
Ejemplo n.º 3
0
        public static Elements.Column ColumnFromRevitColumn(ADSK.FamilyInstance column, Document doc)
        {
            if (column.Category.Id.IntegerValue != (int)BuiltInCategory.OST_Columns)
            {
                throw new InvalidCastException("The incoming family instance is not a column");
            }

            var geom      = column.get_Geometry(new Options());
            var downfaces = geom.Where(g => g.GetType() == typeof(Solid)).Cast <Solid>().Where(s => s != null).SelectMany(s => s.GetMostLikelyHorizontalFaces(30, true));

            var profile = downfaces.First().GetProfiles(true).First();

            if (profile.Area() < 0)
            {
                profile = profile.Reverse();
            }

            var baseCenter = (column.Location as LocationPoint).Point.ToVector3(true);

            baseCenter.Z = baseCenter.Z + Elements.Units.FeetToMeters((doc.GetElement(column.LevelId) as Level).Elevation);
            var transform = new Elements.Geometry.Transform(-baseCenter.X, -baseCenter.Y, -baseCenter.Z);

            var zeroedProfile = transform.OfProfile(profile);

            transform.Invert();

            var col = new Elements.Column(transform.Origin, Elements.Units.FeetToMeters(GetHeightFromColumn(column)), zeroedProfile);

            return(col);
        }
        /// <summary>
        ///
        ///     Determine if the Geometry extracted from a FamilyInstance requires transformation.
        ///
        ///     Bizarrely, some FamilyInstance's geom is transformed and some not when obtained
        ///     from GetGeometryObjectFromReference.  This is because some need to be transformed
        ///     to interact with adjacent geometry in the document.  This stop-gap, suggested by
        ///     SC in the Revit API team, checks if there are any non-empty GeometryInstances in
        ///     FamilyInstance's geometry.  Apparently this is a good heuristic for checking if
        ///     the geometry requires a transform or not.
        ///
        /// </summary>
        /// <param name="familyInstance"></param>
        /// <returns></returns>
        private static bool RequiresTransform(Autodesk.Revit.DB.FamilyInstance familyInstance)
        {
            if (familyInstance.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Mass)
            {
                return(false);
            }
            var geom = familyInstance.get_Geometry(new Options());

            return(geom.OfType <Autodesk.Revit.DB.GeometryInstance>()
                   .Any(x => x.GetInstanceGeometry().Any()));
        }
Ejemplo n.º 5
0
        public static Elements.Column ColumnFromRevitColumn(Revit.FamilyInstance column)
        {
            if (column.Category.Id.IntegerValue != (int)BuiltInCategory.OST_StructuralColumns)
            {
                throw new InvalidCastException("The incoming family instance is not a structural column");
            }

            var geom = column.get_Geometry(new Options());

            return(new Elements.Column(Vector3.Origin, 10, Polygon.Rectangle(1, 2)));
        }