public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            string msg = string.Empty;

            //Selection sel = uidoc.Selection; // 2014
            //foreach( Element e in sel.Elements ) // 2014

            List <Element> walls = new List <Element>();

            if (Util.GetSelectedElementsOrAll(walls, uidoc, typeof(Wall)))
            {
                foreach (Wall wall in walls)
                {
                    msg += ProcessWall(wall);
                }
            }

            if (0 == msg.Length)
            {
                msg = "Please select some walls.";
            }

            Util.InfoMsg(msg);

            return(Result.Succeeded);
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            List <Element> rooms = new List <Element>();

            if (!Util.GetSelectedElementsOrAll(
                    rooms, uidoc, typeof(Room)))
            {
                Selection sel = uidoc.Selection;
                message = (0 < sel.GetElementIds().Count)
          ? "Please select some room elements."
          : "No room elements found.";
                return(Result.Failed);
            }
            foreach (Room room in rooms)
            {
                BumpOccupancy(room);
            }
            return(Result.Succeeded);
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            // retrieve selected walls, or all walls,
            // if nothing is selected:

            List <Element> walls = new List <Element>();

            if (!Util.GetSelectedElementsOrAll(
                    walls, uidoc, typeof(Wall)))
            {
                Selection sel = uidoc.Selection;
                message = (0 < sel.GetElementIds().Count)
          ? "Please select some wall elements."
          : "No wall elements found.";
                return(Result.Failed);
            }


            // mapping of compound wall layers to total cumulated volume;
            // the key is "<wall type name> : <wall layer function>",
            // the value is its cumulated volume across all selected walls:

            MapLayerToVolume totalVolumes
                = new MapLayerToVolume();

            foreach (Wall wall in walls)
            {
                GetWallLayerVolumes(wall, ref totalVolumes);
            }

            string msg
                = "Compound wall layer volumes formatted as '"
                  + "wall type : layer function :"
                  + " volume in cubic meters':\n";

            List <string> keys = new List <string>(
                totalVolumes.Keys);

            keys.Sort();

            foreach (string key in keys)
            {
                msg += "\n" + key + " : "
                       + Util.RealString(
                    Util.CubicFootToCubicMeter(
                        totalVolumes[key]));
            }

            Util.InfoMsg(msg);

            return(Result.Cancelled);
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            List <Element> floors = new List <Element>();

            if (!Util.GetSelectedElementsOrAll(
                    floors, uidoc, typeof(Floor)))
            {
                Selection sel = uidoc.Selection;
                message = (0 < sel.GetElementIds().Count)
          ? "Please select some floor elements."
          : "No floor elements found.";
                return(Result.Failed);
            }

            List <Face> faces = new List <Face>();
            Options     opt   = app.Application.Create.NewGeometryOptions();

            foreach (Floor floor in floors)
            {
                GeometryElement geo = floor.get_Geometry(opt);
                //GeometryObjectArray objects = geo.Objects; // 2012
                //foreach( GeometryObject obj in objects ) // 2012
                foreach (GeometryObject obj in geo) // 2013
                {
                    Solid solid = obj as Solid;
                    if (solid != null)
                    {
                        GetSideFaces(faces, solid);
                    }
                }
            }

            int n = faces.Count;

            Debug.Print(
                "{0} side face{1} found.",
                n, Util.PluralSuffix(n));

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Draw Face Triangle Normals");
                Creator creator = new Creator(doc);
                foreach (Face f in faces)
                {
                    creator.DrawFaceTriangleNormals(f);
                }
                t.Commit();
            }
            return(Result.Succeeded);
        }
        static Transform _t = Transform.CreateTranslation(_offset); // 2014

        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            List <Element> walls = new List <Element>();

            if (!Util.GetSelectedElementsOrAll(
                    walls, uidoc, typeof(Wall)))
            {
                Selection sel = uidoc.Selection;
                //message = ( 0 < sel.Elements.Size ) // 2014
                message = (0 < sel.GetElementIds().Count) // 2015
          ? "Please select some wall elements."
          : "No wall elements found.";
                return(Result.Failed);
            }

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Create model curve copies of analytical model curves");

                Creator creator = new Creator(doc);

                foreach (Wall wall in walls)
                {
                    AnalyticalModel am = wall.GetAnalyticalModel();

                    foreach (AnalyticalCurveType ct in _curveTypes)
                    {
                        IList <Curve> curves = am.GetCurves(ct);

                        int n = curves.Count;

                        Debug.Print("{0} {1} curve{2}.",
                                    n, ct, Util.PluralSuffix(n));

                        foreach (Curve curve in curves)
                        {
                            //creator.CreateModelCurve( curve.get_Transformed( _t ) ); // 2013

                            creator.CreateModelCurve(curve.CreateTransformed(_t)); // 2014
                        }
                    }
                }
                tx.Commit();
            }
            return(Result.Succeeded);
        }
Example #6
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            // retrieve selected floors, or all floors, if nothing is selected:

            List <Element> floors = new List <Element>();

            if (!Util.GetSelectedElementsOrAll(
                    floors, uidoc, typeof(Floor)))
            {
                Selection sel = uidoc.Selection;

                message = (0 < sel.GetElementIds().Count)
          ? "Please select some floor elements."
          : "No floor elements found.";

                return(Result.Failed);
            }

            Options opt = app.Application.Create.NewGeometryOptions();

            List <List <XYZ> > polygons
                = GetFloorBoundaryPolygons(floors, opt);

            int n = polygons.Count;

            Debug.Print(
                "{0} boundary loop{1} found.",
                n, Util.PluralSuffix(n));

            Creator creator = new Creator(doc);

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Draw Slab Boundaries");

                creator.DrawPolygons(polygons);

                t.Commit();
            }

            return(Result.Succeeded);
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            List <Element> filledRegions
                = new List <Element>();

            if (Util.GetSelectedElementsOrAll(
                    filledRegions, uidoc, typeof(FilledRegion)))
            {
                int n = filledRegions.Count;

                string[] results = new string [n];

                int i = 0;

                foreach (FilledRegion region in
                         filledRegions.Cast <FilledRegion>())
                {
                    string desc = Util.ElementDescription(region);

                    List <XYZ> corners = GetBoundaryCorners(
                        region);

                    string result = (null == corners) ? "failed"
            : string.Join(", ",
                          corners.ConvertAll <string>(
                              p => Util.PointString(p))
                          .ToArray());

                    results[i++] = string.Format("{0}: {1}",
                                                 desc, result);
                }
                string s = string.Format(
                    "Retrieving corners for {0} filled region{1}{2}",
                    n, Util.PluralSuffix(n), Util.DotOrColon(n));

                string t = string.Join("\r\n", results);

                Util.InfoMsg2(s, t);
            }
            return(Result.Succeeded);
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            List <Element> spaces = new List <Element>();

            if (!Util.GetSelectedElementsOrAll(
                    spaces, uidoc, typeof(Space)))
            {
                Selection sel = uidoc.Selection;
                message = (0 < sel.GetElementIds().Count)
          ? "Please select some space elements."
          : "No space elements found.";
                return(Result.Failed);
            }

            List <Segment> segments = new List <Segment>();

            foreach (Space space in spaces)
            {
                GetBoundaries(segments, space);
            }

            Dictionary <Segment, Segment> segmentPairs
                = new Dictionary <Segment, Segment>();

            FindClosestSegments(segmentPairs, segments);

            Dictionary <Space, List <Space> > spaceAdjacencies
                = new Dictionary <Space, List <Space> >();

            DetermineAdjacencies(
                spaceAdjacencies, segmentPairs);

            ReportAdjacencies(spaceAdjacencies);

            return(Result.Failed);
        }
Example #9
0
        /// <summary>
        /// Original implementation published November 17, 2008:
        /// http://thebuildingcoder.typepad.com/blog/2008/11/wall-elevation-profile.html
        /// </summary>
        public Result Execute1(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            List <Element> walls = new List <Element>();

            if (!Util.GetSelectedElementsOrAll(
                    walls, uidoc, typeof(Wall)))
            {
                Selection sel = uidoc.Selection;
                message = (0 < sel.GetElementIds().Count)
          ? "Please select some wall elements."
          : "No wall elements found.";

                return(Result.Failed);
            }

            Options opt = app.Application.Create.NewGeometryOptions();

            List <List <XYZ> > polygons
                = GetWallProfilePolygons(walls, opt);

            int n = polygons.Count;

            Debug.Print(
                "{0} boundary loop{1} found.",
                n, Util.PluralSuffix(n));

            Creator creator = new Creator(doc);

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Draw Wall Elevation Profile Model Lines");
                creator.DrawPolygons(polygons);
                tx.Commit();
            }
            return(Result.Succeeded);
        }
Example #10
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = app.ActiveUIDocument.Document;

            // Retrieve selected walls, or all walls,
            // if nothing is selected:

            List <Element> walls = new List <Element>();

            if (!Util.GetSelectedElementsOrAll(
                    walls, uidoc, typeof(Wall)))
            {
                Selection sel = uidoc.Selection;
                message = (0 < sel.GetElementIds().Count)
          ? "Please select some wall elements."
          : "No wall elements found.";
                return(Result.Failed);
            }

            //int i; // 2011
            int    n;
            double halfThickness, layerOffset;
            //Creator creator = new Creator( doc );
            XYZ lcstart, lcend, v, w, p, q;

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Draw wall layer sepearation lines");

                foreach (Wall wall in walls)
                {
                    string desc = Util.ElementDescription(wall);

                    LocationCurve curve
                        = wall.Location as LocationCurve;

                    if (null == curve)
                    {
                        message = desc + ": No wall curve found.";
                        return(Result.Failed);
                    }

                    // Wall centre line and thickness:

                    lcstart       = curve.Curve.GetEndPoint(0);
                    lcend         = curve.Curve.GetEndPoint(1);
                    halfThickness = 0.5 * wall.WallType.Width;
                    v             = lcend - lcstart;
                    v             = v.Normalize(); // one foot long
                    w             = XYZ.BasisZ.CrossProduct(v).Normalize();
                    if (wall.Flipped)
                    {
                        w = -w;
                    }

                    p = lcstart - 2 * v;
                    q = lcend + 2 * v;
                    Creator.CreateModelLine(doc, p, q);

                    q = p + halfThickness * w;
                    Creator.CreateModelLine(doc, p, q);

                    // Exterior edge

                    p = lcstart - v + halfThickness * w;
                    q = lcend + v + halfThickness * w;
                    Creator.CreateModelLine(doc, p, q);

                    //CompoundStructure structure = wall.WallType.CompoundStructure; // 2011
                    CompoundStructure structure = wall.WallType.GetCompoundStructure(); // 2012

                    if (null == structure)
                    {
                        message = desc + ": No compound structure "
                                  + "found. Is this a stacked wall?";

                        return(Result.Failed);
                    }

                    //CompoundStructureLayerArray layers = structure.Layers; // 2011
                    IList <CompoundStructureLayer> layers = structure.GetLayers(); // 2012

                    //i = 0; // 2011
                    //n = layers.Size; // 2011
                    n = layers.Count; // 2012

                    Debug.Print(
                        "{0} with thickness {1}"
                        + " has {2} layer{3}{4}",
                        desc,
                        Util.MmString(2 * halfThickness),
                        n, Util.PluralSuffix(n),
                        Util.DotOrColon(n));

                    if (0 == n)
                    {
                        // Interior edge

                        p = lcstart - v - halfThickness * w;
                        q = lcend + v - halfThickness * w;
                        Creator.CreateModelLine(doc, p, q);
                    }
                    else
                    {
                        layerOffset = halfThickness;
                        foreach (CompoundStructureLayer layer
                                 in layers)
                        {
                            Debug.Print(
                                "  Layer {0}: function {1}, "
                                + "thickness {2}",
                                //++i, // 2011
                                layers.IndexOf(layer), // 2012
                                layer.Function,
                                Util.MmString(layer.Width));

                            //layerOffset -= layer.Thickness; // 2011
                            layerOffset -= layer.Width; // 2012

                            p = lcstart - v + layerOffset * w;
                            q = lcend + v + layerOffset * w;
                            Creator.CreateModelLine(doc, p, q);
                        }
                    }
                    tx.Commit();
                }
            }
            return(Result.Succeeded);
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            List <Element> floors = new List <Element>();

            if (!Util.GetSelectedElementsOrAll(
                    floors, uidoc, typeof(Floor)))
            {
                Selection sel = uidoc.Selection;
                message = (0 < sel.GetElementIds().Count)
          ? "Please select some floor elements."
          : "No floor elements found.";
                return(Result.Failed);
            }

            Options opt = app.Application.Create.NewGeometryOptions();

            List <List <XYZ> > polygons
                = CmdSlabBoundary.GetFloorBoundaryPolygons(
                      floors, opt);

            List <List <UV> > flat_polygons
                = Flatten(polygons);

            int i = 0, n = flat_polygons.Count;

            double[] areas = new double[n];
            double   a, maxArea = 0.0;

            foreach (List <UV> polygon in flat_polygons)
            {
                a = GetSignedPolygonArea(polygon);
                if (Math.Abs(maxArea) < Math.Abs(a))
                {
                    maxArea = a;
                }
                areas[i++] = a;
            }

            Debug.Print(
                "{0} boundary loop{1} found.",
                n, Util.PluralSuffix(n));

            for (i = 0; i < n; ++i)
            {
                Debug.Print(
                    "  Loop {0} area is {1} square feet{2}",
                    i,
                    Util.RealString(areas[i]),
                    (areas[i].Equals(maxArea)
            ? ", outer loop of largest floor slab"
            : ""));
            }

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Draw Polygons");

                Creator creator = new Creator(doc);
                creator.DrawPolygons(polygons);

                t.Commit();
            }
            return(Result.Succeeded);
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            List <Element> walls = new List <Element>();

            if (!Util.GetSelectedElementsOrAll(
                    walls, uidoc, typeof(Wall)))
            {
                Selection sel = uidoc.Selection;
                message = (0 < sel.GetElementIds().Count)
          ? "Please select some wall elements."
          : "No wall elements found.";
                return(Result.Failed);
            }

            Options opt = app.Application.Create.NewGeometryOptions();

            List <List <XYZ> > polygons
                = CmdWallProfile.GetWallProfilePolygons(
                      walls, opt);

            int i = 0, n = polygons.Count;

            double[] areas = new double[n];
            double   d, a, maxArea = 0.0;
            XYZ      normal;

            foreach (List <XYZ> polygon in polygons)
            {
                GetPolygonPlane(polygon,
                                out normal, out d, out a);
                if (Math.Abs(maxArea) < Math.Abs(a))
                {
                    maxArea = a;
                }
                areas[i++] = a;

#if DEBUG
                // transform the 3D polygon into a horizontal plane
                // so we can use the 2D GetSignedPolygonArea() and
                // compare its results with the 3D calculation.

                // todo: compare the relative speed of
                // transforming 3d to 2d and using 2d area
                // calculation versus direct 3d area calculation.


                Transform t = GetTransformToZ(normal);

                List <XYZ> polygonHorizontal
                    = ApplyTransform(polygon, t);

                List <UV> polygon2d
                    = CmdSlabBoundaryArea.Flatten(
                          polygonHorizontal);

                double a2
                    = CmdSlabBoundaryArea.GetSignedPolygonArea(
                          polygon2d);

                Debug.Assert(Util.IsEqual(a, a2),
                             "expected same area from 2D and 3D calculations");
#endif
            }

            Debug.Print(
                "{0} boundary loop{1} found.",
                n, Util.PluralSuffix(n));

            for (i = 0; i < n; ++i)
            {
                Debug.Print(
                    "  Loop {0} area is {1} square feet{2}",
                    i,
                    Util.RealString(areas[i]),
                    (areas[i].Equals(maxArea)
            ? ", outer loop of largest wall"
            : ""));
            }

            Creator creator = new Creator(doc);

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Draw wall profile loops");
                creator.DrawPolygons(polygons);
                tx.Commit();
            }
            return(Result.Succeeded);
        }
Example #13
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            // Retrieve selected floors, or all floors, if nothing is selected:

            List <Element> floors = new List <Element>();

            if (!Util.GetSelectedElementsOrAll(
                    floors, uidoc, typeof(Floor)))
            {
                Selection sel = uidoc.Selection;
                message = (0 < sel.GetElementIds().Count)
          ? "Please select some floor elements."
          : "No floor elements found.";
                return(Result.Failed);
            }

            // Determine top face of each selected floor:

            int         nNullFaces = 0;
            List <Face> topFaces   = new List <Face>();
            Options     opt        = app.Application.Create.NewGeometryOptions();

            foreach (Floor floor in floors)
            {
                GeometryElement geo = floor.get_Geometry(opt);

                //GeometryObjectArray objects = geo.Objects; // 2012

                foreach (GeometryObject obj in geo)
                {
                    Solid solid = obj as Solid;
                    if (solid != null)
                    {
                        PlanarFace f = GetTopFace(solid);
                        if (null == f)
                        {
                            Debug.WriteLine(
                                Util.ElementDescription(floor)
                                + " has no top face.");
                            ++nNullFaces;
                        }
                        topFaces.Add(f);
                    }
                }
            }

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Create Model Lines and Floor");

                // Create new floors from the top faces found.
                // Before creating the new floor, we would obviously
                // apply whatever modifications are required to the
                // new floor profile:

                Autodesk.Revit.Creation.Application creApp = app.Application.Create;
                Autodesk.Revit.Creation.Document    creDoc = doc.Create;

                int i = 0;
                int n = topFaces.Count - nNullFaces;

                Debug.Print(
                    "{0} top face{1} found.",
                    n, Util.PluralSuffix(n));

                foreach (Face f in topFaces)
                {
                    Floor floor = floors[i++] as Floor;

                    if (null != f)
                    {
                        EdgeArrayArray eaa = f.EdgeLoops;
                        CurveArray     profile;

                        #region Attempt to include inner loops
#if ATTEMPT_TO_INCLUDE_INNER_LOOPS
                        bool use_original_loops = true;
                        if (use_original_loops)
                        {
                            profile = Convert(eaa);
                        }
                        else
#endif // ATTEMPT_TO_INCLUDE_INNER_LOOPS
                        #endregion // Attempt to include inner loops

                        {
                            profile = new CurveArray();

                            // Only use first edge array,
                            // the outer boundary loop,
                            // skip the further items
                            // representing holes:

                            EdgeArray ea = eaa.get_Item(0);
                            foreach (Edge e in ea)
                            {
                                IList <XYZ> pts  = e.Tessellate();
                                int         m    = pts.Count;
                                XYZ         p    = pts[0];
                                XYZ         q    = pts[m - 1];
                                Line        line = Line.CreateBound(p, q);
                                profile.Append(line);
                            }
                        }
                        //Level level = floor.Level; // 2013

                        Level level = doc.GetElement(floor.LevelId)
                                      as Level; // 2014

                        // In this case we have a valid floor type given.
                        // In general, not that NewFloor will only accept
                        // floor types whose IsFoundationSlab predicate
                        // is false.

                        floor = creDoc.NewFloor(profile,
                                                floor.FloorType, level, true);

                        XYZ v = new XYZ(5, 5, 0);

                        //doc.Move( floor, v ); // 2011
                        ElementTransformUtils.MoveElement(doc, floor.Id, v); // 2012
                    }
                }
                t.Commit();
            }
            return(Result.Succeeded);
        }
Example #14
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            List <Element> a = new List <Element>();

            if (!Util.GetSelectedElementsOrAll(a, uidoc,
                                               typeof(FamilyInstance)))
            {
                Selection sel = uidoc.Selection;
                message = (0 < sel.GetElementIds().Count)
          ? "Please select some family instances."
          : "No family instances found.";
                return(Result.Failed);
            }
            FamilyInstance inst = a[0] as FamilyInstance;

            // Here are two ways to traverse the nested instance geometry.
            // The first way can get the right position, but can't get the right structure.
            // The second way can get the right structure, but can't get the right position.
            // What I want is the right structure and right position.

            // First way:

            // In the current project project1.rvt, I can get myFamily3 instance via API,
            // the class is Autodesk.Revit.Elements.FamilyInstance.
            // Then i try to get its geometry:

            Options         opt        = app.Application.Create.NewGeometryOptions();
            GeometryElement geoElement = inst.get_Geometry(opt);

            //GeometryObjectArray a1 = geoElement.Objects; // 2012
            //int n = a1.Size; // 2012

            int n = geoElement.Count <GeometryObject>(); // 2013

            Debug.Print(
                "Family instance geometry has {0} geometry object{1}{2}",
                n, Util.PluralSuffix(n), Util.DotOrColon(n));

            int i = 0;

            //foreach( GeometryObject o1 in a1 ) // 2012
            foreach (GeometryObject o1 in geoElement) // 2013
            {
                GeometryInstance geoInstance = o1 as GeometryInstance;
                if (null != geoInstance)
                {
                    // geometry includes one instance, so get its geometry:

                    GeometryElement symbolGeo = geoInstance.SymbolGeometry;

                    //GeometryObjectArray a2 = symbolGeo.Objects; // 2012
                    //foreach( GeometryObject o2 in a2 ) // 2012

                    // the symbol geometry contains five solids.
                    // how can I find out which solid belongs to which column?
                    // how to relate the solid to the family instance?

                    foreach (GeometryObject o2 in symbolGeo)
                    {
                        Solid s = o2 as Solid;
                        if (null != s && 0 < s.Edges.Size)
                        {
                            List <XYZ> vertices = new List <XYZ>();
                            GetVertices(vertices, s);
                            n = vertices.Count;

                            Debug.Print("Solid {0} has {1} vertices{2} {3}",
                                        i++, n, Util.DotOrColon(n),
                                        Util.PointArrayString(vertices));
                        }
                    }
                }
            }

            // In the Revit 2009 API, we can use
            // FamilyInstance.Symbol.Family.Components
            // to obtain the nested family instances
            // within the top level family instance.

            // In the Revit 2010 API, this property has been
            // removed, since we can iterate through the elements
            // of a family just like any other document;
            // cf. What's New in the RevitAPI.chm:


#if REQUIRES_REVIT_2009_API
            ElementSet components = inst.Symbol.Family.Components;
            n = components.Size;
#endif // REQUIRES_REVIT_2009_API

            Document fdoc = doc.EditFamily(inst.Symbol.Family);

#if REQUIRES_REVIT_2010_API
            List <Element> components = new List <Element>();
            fdoc.get_Elements(typeof(FamilyInstance), components);
            n = components.Count;
#endif // REQUIRES_REVIT_2010_API

            FilteredElementCollector collector
                = new FilteredElementCollector(fdoc);

            collector.OfClass(typeof(FamilyInstance));
            IList <Element> components = collector.ToElements();

            Debug.Print(
                "Family instance symbol family has {0} component{1}{2}",
                n, Util.PluralSuffix(n), Util.DotOrColon(n));

            foreach (Element e in components)
            {
                // there are 3 FamilyInstance: Column, myFamily1, myFamily2
                // then we can loop myFamily1, myFamily2 also.
                // then get all the Column geometry
                // But all the Column's position is the same,
                // because the geometry is defined by the Symbol.
                // Not the actually position in project1.rvt

                LocationPoint lp = e.Location as LocationPoint;
                Debug.Print("{0} at {1}",
                            Util.ElementDescription(e),
                            Util.PointString(lp.Point));
            }
            return(Result.Failed);
        }
Example #15
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = app.ActiveUIDocument.Document;

            List <Element> walls = new List <Element>();

            if (!Util.GetSelectedElementsOrAll(
                    walls, uidoc, typeof(Wall)))
            {
                Selection sel = uidoc.Selection;
                message = (0 < sel.GetElementIds().Count)
          ? "Please select some wall elements."
          : "No wall elements found.";
                return(Result.Failed);
            }

            int    i, n;
            string desc, s = null;
            //List<Element> neighbours;
            ElementArray neighbours;

            foreach (Wall wall in walls)
            {
                desc = Util.ElementDescription(wall);

                LocationCurve c
                    = wall.Location as LocationCurve;

                if (null == c)
                {
                    s = desc + ": No wall curve found.";
                }
                else
                {
                    s = string.Empty;

                    for (i = 0; i < 2; ++i)
                    {
                        neighbours = c.get_ElementsAtJoin(i);
                        n          = neighbours.Size;

                        s += string.Format(
                            "\n\n{0} {1} point has {2} neighbour{3}{4}",
                            desc,
                            (0 == i ? "start" : "end"),
                            n,
                            Util.PluralSuffix(n),
                            Util.DotOrColon(n));

                        foreach (Wall nb in neighbours)
                        {
                            s += "\n  " +
                                 Util.ElementDescription(nb);
                        }
                    }
                }
                Util.InfoMsg(s);
            }
            return(Result.Failed);
        }
        public Result ExecuteObsolete(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            BindingMap bindings = doc.ParameterBindings;
            //Dictionary<string, Guid> guids = new Dictionary<string, Guid>();
            Dictionary <Definition, object> mapDefToGuid = new Dictionary <Definition, object>();

            int n = bindings.Size;

            Debug.Print("{0} shared parementer{1} defined{2}",
                        n, Util.PluralSuffix(n), Util.DotOrColon(n));

            if (0 < n)
            {
                DefinitionBindingMapIterator it
                    = bindings.ForwardIterator();

                while (it.MoveNext())
                {
                    Definition d = it.Key as Definition;
                    Binding    b = it.Current as Binding;
                    if (d is ExternalDefinition)
                    {
                        Guid g = ((ExternalDefinition)d).GUID;
                        Debug.Print(d.Name + ": " + g.ToString());
                        mapDefToGuid.Add(d, g);
                    }
                    else
                    {
                        Debug.Assert(d is InternalDefinition);

                        // this built-in parameter is INVALID:

                        BuiltInParameter bip = ((InternalDefinition)d).BuiltInParameter;
                        Debug.Print(d.Name + ": " + bip.ToString());

                        // if have a definition file and group name, we can still determine the GUID:

                        //Guid g = SharedParamGuid( app, "Identity data", d.Name );

                        mapDefToGuid.Add(d, null);
                    }
                }
            }

            List <Element> walls = new List <Element>();

            if (!Util.GetSelectedElementsOrAll(
                    walls, uidoc, typeof(Wall)))
            {
                Selection sel = uidoc.Selection;
                message = (0 < sel.GetElementIds().Count)
        ? "Please select some wall elements."
        : "No wall elements found.";
            }
            else
            {
                //List<string> keys = new List<string>( mapDefToGuid.Keys );
                //keys.Sort();

                foreach (Wall wall in walls)
                {
                    Debug.Print(Util.ElementDescription(wall));

                    foreach (Definition d in mapDefToGuid.Keys)
                    {
                        object o = mapDefToGuid[d];

                        Parameter p = (null == o)
            ? wall.get_Parameter(d)
            : wall.get_Parameter((Guid)o);

                        string s = (null == p)
            ? "<null>"
            : p.AsValueString();

                        Debug.Print(d.Name + ": " + s);
                    }
                }
            }
            return(Result.Failed);
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            // Retrieve selected multistory stairs, or all
            // such elements, if nothing is pre-selected:

            List <Element> msss = new List <Element>();

            if (!Util.GetSelectedElementsOrAll(
                    msss, uidoc, typeof(MultistoryStairs)))
            {
                Selection sel = uidoc.Selection;
                message = (0 < sel.GetElementIds().Count)
          ? "Please select some floor elements."
          : "No floor elements found.";
                return(Result.Failed);
            }

            int n = msss.Count;

            Debug.Print("{0} multi story stair{1} selected{2}",
                        n, Util.PluralSuffix(n), Util.DotOrColon(n));

            foreach (MultistoryStairs mss in msss)
            {
                // Get the stairs by `GetAllStairsIds`, then
                // call `Element.GetSubelements` to get the
                // subelements of each stair.

                ISet <ElementId> ids = mss.GetAllStairsIds();

                n = ids.Count;

                Debug.Print(
                    "Multi story stair '{0}' has {1} stair instance{2}{3}",
                    Util.ElementDescription(mss),
                    n, Util.PluralSuffix(n), Util.DotOrColon(n));

                foreach (ElementId id in ids)
                {
                    Element e = doc.GetElement(id);

                    Stairs stair = e as Stairs;

                    Debug.Assert(null != stair,
                                 "expected a stair element");

                    IList <Subelement> ses = e.GetSubelements();

                    n = ses.Count;

                    Debug.Print(
                        "Multi story stair instance '{0}' has {1} subelement{2}{3}",
                        Util.ElementDescription(e),
                        n, Util.PluralSuffix(n), Util.DotOrColon(n));

                    foreach (Subelement se in ses)
                    {
                        Debug.Print(
                            "Subelement {0} of type {1}",
                            se.UniqueId, se.TypeId.IntegerValue);

                        Element           e2  = doc.GetElement(se.UniqueId); // null
                        Element           e2t = doc.GetElement(se.TypeId);   // StairsType
                        IList <ElementId> ps  = se.GetAllParameters();       // 24 parameters
                        GeometryObject    geo = se.GetGeometryObject(null);
                    }
                }
            }
            return(Result.Succeeded);
        }