Пример #1
0
        static IList <Element> SelectInterferingElems(UIDocument uidoc, Document doc)
        {
            Autodesk.Revit.UI.Selection.Selection selection = uidoc.Selection;
            IList <Reference> references =
                selection.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Element,
                                      new HorizontalElementsSelectionFilter(), "Select splitting elements");

            // Detect whether the selected elements intersect the main element

            IList <Element> selectedElems = references.Select <Reference, Element>
                                                (r => (doc.GetElement(r))).ToList <Element>();

            return(selectedElems.OrderBy(e =>
            {
                return ((Level)doc
                        .GetElement(e.LevelId)).Elevation;
            }).ToList());
        }
Пример #2
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication app = commandData.Application;

            doc             = app.ActiveUIDocument.Document;
            massdoc         = app.Application.NewFamilyDocument(@"C:\ProgramData\Autodesk\RVT 2016\Family Templates\Chinese\概念体量\公制体量.rft");
            m_familyCreator = massdoc.FamilyCreate;

            //选择并初始化工井实例
            Autodesk.Revit.UI.Selection.Selection sel = app.ActiveUIDocument.Selection;
            IList <Reference> familylist = sel.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Element, "请选择工井");
            FamilyInstance    well1      = doc.GetElement(familylist[0]) as FamilyInstance;
            FamilyInstance    well2      = doc.GetElement(familylist[1]) as FamilyInstance;

            //初始化welldoc
            FilteredElementCollector collector = new FilteredElementCollector(doc);

            if (collector != null)
            {
                collector.OfClass(typeof(Family));
            }
            IList <Element> list = collector.ToElements();

            foreach (Element f in list)
            {
                Family family = f as Family;
                if (family.Name == "直通工井")
                {
                    welldoc = doc.EditFamily(family);
                    break;
                }
            }

            //创建电缆族文件并保存
            Transaction trans = new Transaction(massdoc);

            trans.Start("创建新曲线");
            MakeNewCurve(well1, well2);
            trans.Commit();

            int fileNum = 0;

            string path;

            while (true)
            {
                path = "C:\\Users\\DELL\\Documents\\test" + fileNum.ToString() + ".rft";
                if (!File.Exists(path))
                {
                    massdoc.SaveAs(path);
                    break;
                }
                fileNum++;
            }

            string filename = "test" + fileNum.ToString();

            //将电缆插入项目文件中
            trans = new Transaction(doc);
            trans.Start("将曲线插入项目文件");
            doc.LoadFamily(path);
            FamilySymbol fs = getSymbolType(doc, filename);

            fs.Activate();
            FamilyInstance fi = doc.Create.NewFamilyInstance(XYZ.Zero, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);

            fi.Category.Material = getMaterial(doc, "混凝土");
            trans.Commit();

            return(Result.Succeeded);
        }