コード例 #1
0
        public static ViewFamilyType ViewTypeSetup(Document currentDoc)
        {
            ViewFamilyType vf1 = new FilteredElementCollector(currentDoc)
                                 .OfClass(typeof(ViewFamilyType))
                                 .Cast <ViewFamilyType>()
                                 .FirstOrDefault <ViewFamilyType>(x => ViewFamily.Elevation == x.ViewFamily);

            ViewFamilyType vft;

            FilteredElementCollector vftfilter = new FilteredElementCollector(currentDoc).OfClass(typeof(ViewFamilyType));
            ViewFamilyType           vcheck    = vftfilter.FirstOrDefault <Element>(q => q.Name.Equals("Generated Interior Elevation")) as ViewFamilyType;

            if (vcheck == null)
            {
                vft = vf1.Duplicate("Generated Interior Elevation") as ViewFamilyType;
            }
            else
            {
                if (vcheck.Name != "Generated Interior Elevation")
                {
                    vft = vf1.Duplicate("Generated Interior Elevation") as ViewFamilyType;
                }
                else
                {
                    vft = vcheck;
                }
            }
            return(vft);
        }
コード例 #2
0
        public FloorType GetFloorType(Document doc, FloorSlab floor)
        {
            FloorType f = new FilteredElementCollector(doc).OfClass(typeof(FloorType))
                                                            .Where(ft => ft is FloorType)
                                                            .FirstOrDefault(e =>
                                                            {
                                                                CompoundStructure comp = (e as FloorType).GetCompoundStructure();
                                                                if (comp.GetLayerWidth(0) == Util.MmToFoot(floor.Depth))
                                                                {
                                                                    return true;
                                                                }
                                                                return false;

                                                            }) as FloorType;
            if (f != null) return f;
            f = new FilteredElementCollector(doc).OfClass(typeof(FloorType)).FirstOrDefault(e => e.Name == "Generic - 12\"") as FloorType;
            f = f.Duplicate(String.Format("Floor {0} CM", floor.Depth / 10)) as FloorType;
            CompoundStructure compound = f.GetCompoundStructure();
            compound.SetLayerWidth(0, Util.MmToFoot(floor.Depth));
            f.SetCompoundStructure(compound);

            return f;


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

            try
            {
                Reference   reff          = selection.PickObject(ObjectType.Element, new MySelectionFilter <Room>(), "select a room");
                Room        room          = doc.GetElement(reff) as Room;
                ElementType wallSweepType = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Cornices).WhereElementIsElementType().Cast <ElementType>().FirstOrDefault();

                if (wallSweepType != null)
                {
                    using (Transaction ts = new Transaction(doc, "创建踢脚线"))
                    {
                        ts.Start();
                        ElementType type = wallSweepType.Duplicate("踢脚线2");
                        SpatialElementBoundaryOptions opts = new SpatialElementBoundaryOptions();
                        opts.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish;
                        IList <IList <Autodesk.Revit.DB.BoundarySegment> > boundList = room.GetBoundarySegments(opts);
                        foreach (IList <BoundarySegment> bs in boundList)
                        {
                            foreach (BoundarySegment bs1 in bs)
                            {
                                Wall wall = doc.GetElement(bs1.ElementId) as Wall;
                                if (wall != null)
                                {
                                    WallSweepInfo info = new WallSweepInfo(WallSweepType.Sweep, false);
                                    // 墙的正反或者里面
                                    info.WallSide = WallSide.Exterior;
                                    // 距离墙底的高度
                                    info.Distance = 10 / 304.8;
                                    // 偏移距离
                                    info.WallOffset = 0;
                                    WallSweep.Create(wall, type.Id, info);
                                }
                            }
                        }
                        ts.Commit();
                    }
                }
            }
            catch (Exception ex)
            {
                TaskDialog.Show("Error", ex.Message);
            }



            return(Result.Succeeded);
        }
コード例 #4
0
        public FamilySymbol GetIShapeBeamFamilySymbol(Document doc, BeamSt Beam, string familyName, BuiltInCategory category)
        {
            FamilySymbol fs = new FilteredElementCollector(doc).OfCategory(category)
                                                        .WhereElementIsElementType()
                                                        .Cast<FamilySymbol>()
                                                        .Where(f => f.FamilyName == familyName)
                                                        .FirstOrDefault(f =>
                                                        {
                                                            if (f.LookupParameter("Width").AsDouble() == Util.MmToFoot(Beam.Width) &&
                                                                f.LookupParameter("Height").AsDouble() == Util.MmToFoot(Beam.Depth) &&
                                                                f.LookupParameter("Flange Thickness").AsDouble() == Util.MmToFoot(Beam.FlangeTh) &&
                                                                f.LookupParameter("Web Thickness").AsDouble() == Util.MmToFoot(Beam.WebTh)
                                                                )
                                                            {
                                                                return true;
                                                            }
                                                            return false;
                                                        });

            if (fs != null) return fs;

            Family family = default;
            try
            {
                fs = new FilteredElementCollector(doc).OfCategory(category)
                                                        .WhereElementIsElementType()
                                                        .Cast<FamilySymbol>()
                                                        .First(f => f.FamilyName == familyName);
            }
            catch (Exception)
            {
                string directory = $"C:/ProgramData/Autodesk/RVT {revitVersion}/Libraries/US Imperial/Structural Framing/Steel/AISC 14.1/";
                family = OpenFamily(doc, directory, familyName);
                fs = doc.GetElement(family.GetFamilySymbolIds().FirstOrDefault()) as FamilySymbol;
            }

            ElementType fs1 = fs.Duplicate(String.Format("I-Beam Custom {0:0}x{1:0}", Beam.Width / 10, Beam.Depth / 10));
            fs1.LookupParameter("Width").Set(Util.MmToFoot(Beam.Width));
            fs1.LookupParameter("Height").Set(Util.MmToFoot(Beam.Depth));
            fs1.LookupParameter("Flange Thickness").Set(Util.MmToFoot(Beam.FlangeTh));
            fs1.LookupParameter("Web Thickness").Set(Util.MmToFoot(Beam.WebTh));
            fs1.LookupParameter("Web Fillet").Set(Util.MmToFoot(0.85 * (Beam.WebTh)));

            return fs1 as FamilySymbol;
        }
コード例 #5
0
        public FamilySymbol GetLShapeBraceFamilySymbol(Document doc, Brace Brace, string familyName, BuiltInCategory category)
        {
            FamilySymbol fs = new FilteredElementCollector(doc).OfCategory(category)
                                                        .WhereElementIsElementType()
                                                        .Cast<FamilySymbol>()
                                                        .Where(f => f.FamilyName == familyName)
                                                        .Where(f =>
                                                        {
                                                            if (f.LookupParameter("d").AsDouble() == Util.MmToFoot(Brace.Depth) &&
                                                                f.LookupParameter("b").AsDouble() == Util.MmToFoot(Brace.Width) &&
                                                                f.LookupParameter("t").AsDouble() == Util.MmToFoot(Brace.Thickness)
                                                                ) return true;

                                                            return false;
                                                        }).FirstOrDefault();

            if (fs != null) return fs;

            Family family = default;
            try
            {
                fs = new FilteredElementCollector(doc).OfCategory(category)
                                                        .WhereElementIsElementType()
                                                        .Cast<FamilySymbol>()
                                                        .First(f => f.FamilyName == familyName);
            }
            catch (Exception)
            {
                string directory = $"C:/ProgramData/Autodesk/RVT {revitVersion}/Libraries/US Imperial/Structural Columns/Steel/";
                family = OpenFamily(doc, directory, familyName);
                fs = doc.GetElement(family.GetFamilySymbolIds().FirstOrDefault()) as FamilySymbol;
            }

            ElementType fs1 = fs.Duplicate(String.Format($"L-Angle Custom {0:0}x{1:0}", Brace.Width / 10, Brace.Depth / 10));
            fs1.LookupParameter("b").Set(Util.MmToFoot(Brace.Width));
            fs1.LookupParameter("d").Set(Util.MmToFoot(Brace.Depth));
            fs1.LookupParameter("t").Set(Util.MmToFoot(Brace.Thickness));
            fs1.LookupParameter("k").Set(Util.MmToFoot(Brace.Thickness));
            fs1.LookupParameter("x").Set(Util.MmToFoot(0.28 * (Brace.Thickness)));
            fs1.LookupParameter("y").Set(Util.MmToFoot(0.28 * (Brace.Thickness)));

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

            WallType firstWallType = new FilteredElementCollector(doc).OfClass(typeof(WallType)).WhereElementIsElementType().ToElements().Cast <WallType>().First();
            // set new wall type to null
            WallType newWallType = null;

            using (Transaction ts = new Transaction(doc, "create new wall type"))
            {
                ts.Start();
                // duplicate wwalltype
                newWallType = firstWallType.Duplicate("New Wall") as WallType;


                // grab material of wall
                ElementId oldLayerMaterialId = firstWallType.GetCompoundStructure().GetLayers()[0].MaterialId;


                // dimentions


                // set wall strcutre

                // middle


                // interior

                // exterior



                ts.Commit();
            }


            return(Result.Succeeded);
        }
コード例 #7
0
        public FamilySymbol GetColumnFamilySymbol(Document doc, Column col, string familyName, BuiltInCategory category)
        {
            string b = category == BuiltInCategory.OST_StructuralColumns ? "b" : "Width";
            string h = category == BuiltInCategory.OST_StructuralColumns ? "h" : "Depth";

            FamilySymbol fs = new FilteredElementCollector(doc).OfCategory(category)
                                                        .WhereElementIsElementType()
                                                        .Cast<FamilySymbol>()
                                                        .Where(f => f.FamilyName == familyName)
                                                        .FirstOrDefault(f =>
                                                        {
                                                            if (f.LookupParameter(h).AsDouble() == Util.MmToFoot(col.Depth) &&
                                                                    f.LookupParameter(b).AsDouble() == Util.MmToFoot(col.Width))
                                                            {
                                                                return true;
                                                            }
                                                            return false;
                                                        });

            if (fs != null) return fs;

            Family family = default;
            try
            {
                fs = new FilteredElementCollector(doc).OfCategory(category)
                                                        .WhereElementIsElementType()
                                                        .Cast<FamilySymbol>()
                                                        .First(f => f.FamilyName == familyName);
            }
            catch (Exception)
            {
                string directory = $"C:/ProgramData/Autodesk/RVT {revitVersion}/Libraries/US Imperial/Structural Columns/Concrete/";
                family = OpenFamily(doc, directory, familyName);
                fs = doc.GetElement(family.GetFamilySymbolIds().FirstOrDefault()) as FamilySymbol;
            }

            ElementType fs1 = fs.Duplicate(String.Format("Column {0:0}x{1:0}", col.Width / 10, col.Depth / 10));
            fs1.LookupParameter(b).Set(Util.MmToFoot(col.Width));
            fs1.LookupParameter(h).Set(Util.MmToFoot(col.Depth));
            return fs1 as FamilySymbol;
        }
コード例 #8
0
        public FamilySymbol GetBeamFamilySymbol(Document doc, Beam beam, string familyName, BuiltInCategory category)
        {
            FamilySymbol fs = new FilteredElementCollector(doc).OfCategory(category)
                                                        .WhereElementIsElementType()
                                                        .Cast<FamilySymbol>()
                                                        .Where(f => f.FamilyName == familyName)
                                                        .FirstOrDefault(f =>
                                                        {
                                                            if (Math.Abs(f.LookupParameter("h").AsDouble() - Util.MmToFoot(beam.H)) < Util.MmToFoot(0.001) &&
                                                                Math.Abs(f.LookupParameter("b").AsDouble() - Util.MmToFoot(beam.B)) < Util.MmToFoot(0.001))

                                                                return true;
                                                            return false;
                                                        });

            if (fs != null) return fs;
            Family family = default;

            try
            {
                fs = new FilteredElementCollector(doc).OfCategory(category)
                                                        .WhereElementIsElementType()
                                                        .Cast<FamilySymbol>()
                                                        .First(f => f.FamilyName == familyName);

            }
            catch (Exception)
            {
                string directory = $"C:/ProgramData/Autodesk/RVT {revitVersion}/Libraries/US Imperial/Structural Framing/Concrete/";
                family = OpenFamily(doc, directory, familyName);
                fs = doc.GetElement(family.GetFamilySymbolIds().FirstOrDefault()) as FamilySymbol;

            }
            ElementType fs1 = fs.Duplicate(String.Format("Beam {0:0}x{1:0}", beam.B / 10, beam.H / 10));
            fs1.LookupParameter("h").Set(Util.MmToFoot(beam.H));
            fs1.LookupParameter("b").Set(Util.MmToFoot(beam.B));
            return fs1 as FamilySymbol;
        }
コード例 #9
0
        View GetLegend(Document doc)
        {
            var legend = new FilteredElementCollector(doc).OfClass(typeof(View)).Cast <View>().FirstOrDefault(x => x.ViewType == ViewType.Legend);

            return(doc.GetElement(legend.Duplicate(ViewDuplicateOption.Duplicate)) as View);
        }