コード例 #1
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Document      doc   = uidoc.Document;
            Selection     sel   = uidoc.Selection;

            ISelectionFilter f
                = new JtElementsOfClassSelectionFilter <Dimension>();

            Reference elemRef = sel.PickObject(
                ObjectType.Element, f, "Pick a dimension");

            Dimension dim = doc.GetElement(elemRef) as Dimension;

            XYZ        p   = GetDimensionStartPoint(dim);
            List <XYZ> pts = GetDimensionPoints(dim, p);

            int n = pts.Count;

            Debug.Print("Dimension origin at {0} followed "
                        + "by {1} further point{2}{3} {4}",
                        Util.PointString(p), n,
                        Util.PluralSuffix(n), Util.DotOrColon(n),
                        string.Join(", ", pts.Select(
                                        q => Util.PointString(q))));

            List <double> d  = new List <double>(n);
            XYZ           q0 = p;

            foreach (XYZ q in pts)
            {
                d.Add(q.X - q0.X);
                q0 = q;
            }

            Debug.Print(
                "Horizontal distances in metres: "
                + string.Join(", ", d.Select(x =>
                                             Util.RealString(Util.FootToMetre(x)))));

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Draw Point Markers");

                SketchPlane sketchPlane = dim.View.SketchPlane;

                double size = 0.3;
                DrawMarker(p, size, sketchPlane);
                pts.ForEach(q => DrawMarker(q, size, sketchPlane));

                tx.Commit();
            }

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

            BindingMap bindings = doc.ParameterBindings;

            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;

                    Debug.Assert(b is ElementBinding,
                                 "all Binding instances are ElementBinding instances");

                    Debug.Assert(b is InstanceBinding ||
                                 b is TypeBinding,
                                 "all bindings are either instance or type");

                    // All definitions obtained in this manner
                    // are InternalDefinition instances, even
                    // if they are actually associated with
                    // shared parameters, i.e. external.

                    Debug.Assert(d is InternalDefinition,
                                 "all definitions obtained from BindingMap are internal");

                    string sbinding = (b is InstanceBinding)
          ? "instance"
          : "type";

                    Debug.Print("{0}: {1}", d.Name, sbinding);
                }
            }
            return(Result.Succeeded);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            if (null == doc)
            {
                message = "Please run this command in a valid document.";
                return(Result.Failed);
            }

            View3D view = doc.ActiveView as View3D;

            if (null == view)
            {
                message = "Please run this command in a 3D view.";
                return(Result.Failed);
            }

            Element e = Util.SelectSingleElementOfType(
                uidoc, typeof(Wall), "wall", true);

            List <WallOpening2d> openings = GetWallOpenings(
                e as Wall, view);

            int n = openings.Count;

            string msg = string.Format(
                "{0} opening{1} found{2}",
                n, Util.PluralSuffix(n),
                Util.DotOrColon(n));

            Util.InfoMsg2(msg, string.Join(
                              "\r\n", openings));

            return(Result.Succeeded);
        }
コード例 #5
0
        /// <summary>
        /// Print categories, number of elements each and
        /// some sample data to the Visual Studio debug
        /// output window.
        /// </summary>
        public void DebugPrint()
        {
            List <string> keys = new List <string>(
                this.Keys);

            keys.Sort();

            foreach (string key in keys)
            {
                Dictionary <string, List <string> > els
                    = this[key];

                int n = els.Count;

                Debug.Print("{0} ({1} element{2}){3}",
                            key, n, Util.PluralSuffix(n),
                            Util.DotOrColon(n));

                if (0 < n)
                {
                    List <string> uids = new List <string>(els.Keys);
                    string        uid  = uids[0];

                    List <string> param_values = els[uid];
                    param_values.Sort();

                    n = param_values.Count;

                    Debug.Print("  first element {0} has {1} parameter{2}{3}",
                                uid, n, Util.PluralSuffix(n),
                                Util.DotOrColon(n));

                    param_values.ForEach(pv
                                         => Debug.Print("    " + pv));
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// List all import instances in all the given families.
        /// Retrieve nested families and recursively search in these as well.
        /// </summary>
        void ListImportsAndSearchForMore(
            int recursionLevel,
            Document doc,
            Dictionary <string, Family> families)
        {
            string indent
                = new string( ' ', 2 * recursionLevel );

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

            keys.Sort();

            foreach (string key in keys)
            {
                Family family = families[key];

                if (family.IsInPlace)
                {
                    Debug.Print(indent
                                + "Family '{0}' is in-place.",
                                key);
                }
                else
                {
                    Document fdoc = doc.EditFamily(family);

                    FilteredElementCollector c
                        = new FilteredElementCollector(doc);

                    c.OfClass(typeof(ImportInstance));

                    IList <Element> imports = c.ToElements();

                    int n = imports.Count;

                    Debug.Print(indent
                                + "Family '{0}' contains {1} import instance{2}{3}",
                                key, n, Util.PluralSuffix(n),
                                Util.DotOrColon(n));

                    if (0 < n)
                    {
                        foreach (ImportInstance i in imports)
                        {
                            string s = i.Pinned ? "" : "not ";

                            //string name = i.ObjectType.Name; // 2011
                            string name = doc.GetElement(i.GetTypeId()).Name; // 2012

                            Debug.Print(indent
                                        + "  '{0}' {1}pinned",
                                        name, s);

                            i.Pinned = !i.Pinned;
                        }
                    }

                    Dictionary <string, Family> nestedFamilies
                        = GetFamilies(fdoc);

                    ListImportsAndSearchForMore(
                        recursionLevel + 1, fdoc, nestedFamilies);
                }
            }
        }
コード例 #7
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);
        }
コード例 #8
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 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);
        }
コード例 #10
0
        void DetermineAdjacentElementLengthsAndWallAreas(
            Room room)
        {
            Document doc = room.Document;

            // 'Autodesk.Revit.DB.Architecture.Room.Boundary' is obsolete:
            // use GetBoundarySegments(SpatialElementBoundaryOptions) instead.

            //BoundarySegmentArrayArray boundaries = room.Boundary; // 2011

            IList <IList <BoundarySegment> > boundaries
                = room.GetBoundarySegments(
                      new SpatialElementBoundaryOptions()); // 2012

            // a room may have a null boundary property:

            int n = 0;

            if (null != boundaries)
            {
                //n = boundaries.Size; // 2011
                n = boundaries.Count; // 2012
            }

            Debug.Print(
                "{0} has {1} boundar{2}{3}",
                Util.ElementDescription(room),
                n, Util.PluralSuffixY(n),
                Util.DotOrColon(n));

            if (0 < n)
            {
                int iBoundary = 0, iSegment;

                //foreach( BoundarySegmentArray b in boundaries ) // 2011
                foreach (IList <BoundarySegment> b in boundaries) // 2012
                {
                    ++iBoundary;
                    iSegment = 0;
                    foreach (BoundarySegment s in b)
                    {
                        ++iSegment;

                        //Element neighbour = s.Element; // 2015
                        Element neighbour = doc.GetElement(s.ElementId); // 2016

                        //Curve curve = s.Curve; // 2015
                        Curve curve = s.GetCurve(); // 2016

                        double length = curve.Length;

                        Debug.Print(
                            "  Neighbour {0}:{1} {2} has {3}"
                            + " feet adjacent to room.",
                            iBoundary, iSegment,
                            Util.ElementDescription(neighbour),
                            Util.RealString(length));

                        if (neighbour is Wall)
                        {
                            Wall wall = neighbour as Wall;

                            Parameter p = wall.get_Parameter(
                                BuiltInParameter.HOST_AREA_COMPUTED);

                            double area = p.AsDouble();

                            LocationCurve lc
                                = wall.Location as LocationCurve;

                            double wallLength = lc.Curve.Length;

                            //Level bottomLevel = wall.Level; // 2013
                            Level  bottomLevel     = doc.GetElement(wall.LevelId) as Level; // 2014
                            double bottomElevation = bottomLevel.Elevation;
                            double topElevation    = bottomElevation;

                            p = wall.get_Parameter(
                                BuiltInParameter.WALL_HEIGHT_TYPE);

                            if (null != p)
                            {
                                ElementId id       = p.AsElementId();
                                Level     topLevel = doc.GetElement(id) as Level;
                                topElevation = topLevel.Elevation;
                            }

                            double height = topElevation - bottomElevation;

                            Debug.Print(
                                "    This wall has a total length,"
                                + " height and area of {0} feet,"
                                + " {1} feet and {2} square feet.",
                                Util.RealString(wallLength),
                                Util.RealString(height),
                                Util.RealString(area));
                        }
                    }
                }
            }
        }
コード例 #11
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            #region Obsolete inline code
#if NEED_ALL_THE_INLINE_CODE
            // Parameter names are not guaranteed to be
            // unique! Therefore, it may be impossible to
            // include all parameter values in a dictionary
            // using the parameter name as a key.

#if PARAMETER_NAMES_ARE_UNIQUE
            Dictionary <string,
                        Dictionary <string,
                                    Dictionary <string, string> > >
            map_cat_to_uid_to_param_values;
#else // unfortunately, parameter names are not unique:
            Dictionary <string,
                        Dictionary <string,
                                    List <string> > >
            map_cat_to_uid_to_param_values;
#endif // PARAMETER_NAMES_ARE_UNIQUE

            map_cat_to_uid_to_param_values
                = GetParamValuesForCats(doc, _cats);

#if DEBUG
            List <string> keys = new List <string>(
                map_cat_to_uid_to_param_values.Keys);
            keys.Sort();

            foreach (string key in keys)
            {
                Dictionary <string, List <string> > els
                    = map_cat_to_uid_to_param_values[key];

                int n = els.Count;

                Debug.Print("{0} ({1} element{2}){3}",
                            key, n, Util.PluralSuffix(n),
                            Util.DotOrColon(n));

                if (0 < n)
                {
                    List <string> uids = new List <string>(els.Keys);
                    string        uid  = uids[0];

                    List <string> param_values = els[uid];
                    param_values.Sort();

                    n = param_values.Count;

                    Debug.Print("  first element {0} has {1} parameter{2}{3}",
                                uid, n, Util.PluralSuffix(n),
                                Util.DotOrColon(n));

                    param_values.ForEach(pv
                                         => Debug.Print("    " + pv));
                }
            }
#endif // DEBUG
#endif
            #endregion // Obsolete inline code

            JtParamValuesForCats data
                = new JtParamValuesForCats(doc, _categories);

#if DEBUG
            data.DebugPrint();
#endif // DEBUG

            return(Result.Succeeded);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        /// <summary>
        /// Cumulate the compound wall layer volumes for the given wall.
        /// </summary>
        void GetWallLayerVolumes(
            Wall wall,
            ref MapLayerToVolume totalVolumes)
        {
            WallType wt = wall.WallType;

            //CompoundStructure structure= wt.CompoundStructure; // 2011
            CompoundStructure structure = wt.GetCompoundStructure(); // 2012

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

            //int i, n = layers.Size; // 2011
            int i, n = layers.Count; // 2012

            double area      = GetWallParameter(wall, _bipArea);
            double volume    = GetWallParameter(wall, _bipVolume);
            double thickness = wt.Width;

            string desc = Util.ElementDescription(wall);

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

            // volume for entire wall:

            string key = wall.WallType.Name;

            totalVolumes.Cumulate(key, volume);

            // volume for compound wall layers:

            if (0 < n)
            {
                i = 0;
                double total = 0.0;
                double layerVolume;
                foreach (CompoundStructureLayer
                         layer in layers)
                {
                    key = wall.WallType.Name + " : "
                          + layer.Function;

                    //layerVolume = area * layer.Thickness; // 2011
                    layerVolume = area * layer.Width; // 2012

                    totalVolumes.Cumulate(key, layerVolume);
                    total += layerVolume;

                    Debug.Print(
                        "  Layer {0}: function {1}, "
                        + "thickness {2}, volume {3}",
                        ++i, layer.Function,
                        Util.MmString(layer.Width),
                        Util.RealString(layerVolume));
                }

                Debug.Print("Wall volume = {0},"
                            + " total layer volume = {1}",
                            Util.RealString(volume),
                            Util.RealString(total));

                if (!Util.IsEqual(volume, total))
                {
                    Debug.Print("Wall host volume parameter"
                                + " value differs from sum of all layer"
                                + " volumes: {0}",
                                volume - total);
                }
            }
        }
コード例 #14
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
            Document      doc = app.ActiveUIDocument.Document;

            if (!doc.IsFamilyDocument)
            {
                message =
                    "Please run this command in a family document.";
            }
            else
            {
                FamilyManager mgr = doc.FamilyManager;

                int n = mgr.Parameters.Size;

                Debug.Print(
                    "\nFamily {0} has {1} parameter{2}.",
                    doc.Title, n, Util.PluralSuffix(n));

                Dictionary <string, FamilyParameter> fps
                    = new Dictionary <string, FamilyParameter>(n);

                foreach (FamilyParameter fp in mgr.Parameters)
                {
                    string name = fp.Definition.Name;
                    fps.Add(name, fp);

                    #region Look at associated parameters
#if LOOK_AT_ASSOCIATED_PARAMETERS
                    ParameterSet ps = fp.AssociatedParameters;
                    n = ps.Size;

                    string values = string.Empty;
                    foreach (Parameter p in ps)
                    {
                        if (0 == values.Length)
                        {
                            values = " ";
                        }
                        else
                        {
                            values += ", ";
                        }
                        values += p.AsValueString();
                    }

                    Debug.Print(
                        "Parameter {0} has {1} associated parameter{2}{3}{4}.",
                        name,
                        n,
                        PluralSuffix(n),
                        (0 < n ? ":" : ""),
                        values);
#endif // LOOK_AT_ASSOCIATED_PARAMETERS
                    #endregion // Look at associated parameters
                }
                List <string> keys = new List <string>(fps.Keys);
                keys.Sort();

                n = mgr.Types.Size;

                Debug.Print(
                    "Family {0} has {1} type{2}{3}",
                    doc.Title,
                    n,
                    Util.PluralSuffix(n),
                    Util.DotOrColon(n));

                foreach (FamilyType t in mgr.Types)
                {
                    string name = t.Name;
                    Debug.Print("  {0}:", name);
                    foreach (string key in keys)
                    {
                        FamilyParameter fp = fps[key];
                        if (t.HasValue(fp))
                        {
                            string value
                                = FamilyParamValueString(t, fp, doc);

                            Debug.Print("    {0} = {1}", key, value);
                        }
                    }
                }
            }

            #region Exercise ExtractPartAtomFromFamilyFile

            // by the way, here is a completely different way to
            // get at all the parameter values, and all the other
            // family information as well:

            bool exercise_this_method = false;

            if (doc.IsFamilyDocument && exercise_this_method)
            {
                string path = doc.PathName;
                if (0 < path.Length)
                {
                    app.Application.ExtractPartAtomFromFamilyFile(
                        path, path + ".xml");
                }
            }
            #endregion // Exercise ExtractPartAtomFromFamilyFile

            return(Result.Failed);
        }
コード例 #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;

            // 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);
        }
コード例 #16
0
        /// <summary>
        /// Non-recursively list all import instances
        /// in all families used in the current project document.
        /// </summary>
        public Result ExecuteWithoutRecursion(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
            Document      doc = app.ActiveUIDocument.Document;

            FilteredElementCollector instances
                = new FilteredElementCollector(doc);

            instances.OfClass(typeof(FamilyInstance));

            Dictionary <string, Family> families
                = new Dictionary <string, Family>();

            foreach (FamilyInstance i in instances)
            {
                Family family = i.Symbol.Family;
                if (!families.ContainsKey(family.Name))
                {
                    families[family.Name] = family;
                }
            }

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

            keys.Sort();

            foreach (string key in keys)
            {
                Family family = families[key];
                if (family.IsInPlace)
                {
                    Debug.Print("Family '{0}' is in-place.", key);
                }
                else
                {
                    Document fdoc = doc.EditFamily(family);

                    FilteredElementCollector c
                        = new FilteredElementCollector(doc);

                    c.OfClass(typeof(ImportInstance));

                    IList <Element> imports = c.ToElements();

                    int n = imports.Count;

                    Debug.Print(
                        "Family '{0}' contains {1} import instance{2}{3}",
                        key, n, Util.PluralSuffix(n),
                        Util.DotOrColon(n));

                    if (0 < n)
                    {
                        foreach (ImportInstance i in imports)
                        {
                            //string name = i.ObjectType.Name; // 2011
                            string name = doc.GetElement(i.GetTypeId()).Name; // 2012

                            Debug.Print("  '{0}'", name);
                        }
                    }
                }
            }
            return(Result.Failed);
        }
コード例 #17
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;

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

            FilteredElementCollector doors
                = Util.GetElementsOfType(doc,
                                         typeof(FamilyInstance),
                                         BuiltInCategory.OST_Doors);

            int n = doors.Count();

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

            if (0 < n)
            {
                Dictionary <string, List <Element> > marks
                    = new Dictionary <string, List <Element> >();

                foreach (FamilyInstance door in doors)
                {
                    string mark = door.get_Parameter(
                        BuiltInParameter.ALL_MODEL_MARK)
                                  .AsString();

                    if (!marks.ContainsKey(mark))
                    {
                        marks.Add(mark, new List <Element>());
                    }
                    marks[mark].Add(door);
                }

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

                keys.Sort();

                n = keys.Count;

                Debug.Print("{0} door mark{1} found{2}",
                            n, Util.PluralSuffix(n),
                            Util.DotOrColon(n));

                foreach (string mark in keys)
                {
                    n = marks[mark].Count;

                    Debug.Print("  {0}: {1} door{2}",
                                mark, n, Util.PluralSuffix(n));
                }
            }

            n = 0; // count how many elements are modified

            if (_modify_existing_marks)
            {
                using (Transaction tx = new Transaction(doc))
                {
                    tx.Start("Modify Existing Door Marks");

                    //ElementSet els = uidoc.Selection.Elements; // 2014

                    ICollection <ElementId> ids = uidoc.Selection
                                                  .GetElementIds(); // 2015

                    //foreach( Element e in els ) // 2014

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

                        if (e is FamilyInstance &&
                            null != e.Category &&
                            (int)BuiltInCategory.OST_Doors
                            == e.Category.Id.IntegerValue)
                        {
                            e.get_Parameter(
                                BuiltInParameter.ALL_MODEL_MARK)
                            .Set(_the_answer);

                            ++n;
                        }
                    }
                    tx.Commit();
                }
            }

            // return Succeeded only if we wish to commit
            // the transaction to modify the database:
            //
            //return 0 < n
            //  ? Result.Succeeded
            //  : Result.Failed;
            //
            // That was only useful before the introduction
            // of the manual and read-only transaction modes.

            return(Result.Succeeded);
        }
コード例 #18
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            // Interactively select elements of type Room,
            // either via pre-selection before launching the
            // command, or interactively via post-selection.

            JtSelectorMulti <Room> selector
                = new JtSelectorMulti <Room>(
                      uidoc, BuiltInCategory.OST_Rooms, "room",
                      e => e is Room);

            if (selector.IsEmpty)
            {
                return(selector.ShowResult());
            }

            IList <Room> rooms = selector.Selected;

            List <string> msg = new List <string>();

            int n = rooms.Count;

            msg.Add(string.Format(
                        "{0} room{1} selected{2}\r\n",
                        n, Util.PluralSuffix(n),
                        Util.DotOrColon(n)));

            SpatialElementBoundaryOptions opt
                = new SpatialElementBoundaryOptions();

            IList <IList <BoundarySegment> > loops;

            Room neighbour;
            int  i = 0, j, k;

            foreach (Room room in rooms)
            {
                ++i;

                loops = room.GetBoundarySegments(opt);

                n = loops.Count;

                msg.Add(string.Format(
                            "{0}. {1} has {2} loop{3}{4}",
                            i, Util.ElementDescription(room),
                            n, Util.PluralSuffix(n),
                            Util.DotOrColon(n)));

                j = 0;

                foreach (IList <BoundarySegment> loop in loops)
                {
                    ++j;

                    n = loop.Count;

                    msg.Add(string.Format(
                                "  {0}. Loop has {1} boundary segment{2}{3}",
                                j, n, Util.PluralSuffix(n),
                                Util.DotOrColon(n)));

                    k = 0;

                    foreach (BoundarySegment seg in loop)
                    {
                        ++k;

                        neighbour = GetRoomNeighbourAt(seg, room);

                        msg.Add(string.Format(
                                    "    {0}. Boundary segment has neighbour {1}",
                                    k,
                                    (null == neighbour
                ? "<nil>"
                : Util.ElementDescription(neighbour))));
                    }
                }
            }

            Util.InfoMsg2("Room Neighbours",
                          string.Join("\n", msg.ToArray()));

            return(Result.Succeeded);
        }