privatevoidGetinfo_Level(Document document) { StringBuilder levelInformation = new StringBuilder(); int levelNumber = 0; FilteredElementCollector collector = new FilteredElementCollector(document); ICollection collection = collector.OfClass(typeof(Level)).ToElements(); foreach (Element e in collection) { Level level = e as Level;
if (null != level) { // keep track of number of levels levelNumber++;
//get the name of the level levelInformation.Append("\nLevel Name: " + level.Name);
//get the elevation of the level levelInformation.Append("\n\tElevation: " + level.Elevation);
// get the project elevation of the level levelInformation.Append("\n\tProject Elevation: " + level.ProjectElevation); } }
//number of total levels in current document levelInformation.Append("\n\n There are " + levelNumber + " levels in the document!");
//show the level information in the messagebox TaskDialog.Show("Revit",levelInformation.ToString()); }
// Show IsCurved property message += "\nIf grid is Arc : " + grid.IsCurved;
// Show Curve information Autodesk.Revit.DB.Curve curve = grid.Curve; if (grid.IsCurved) { // if the curve is an arc, give center and radius information Autodesk.Revit.DB.Arc arc = curve as Autodesk.Revit.DB.Arc; message += "\nArc's radius: " + arc.Radius; message += "\nArc's center: (" + XYZToString(arc.Center); } else { // if the curve is a line, give length information Autodesk.Revit.DB.Line line = curve as Autodesk.Revit.DB.Line; message += "\nLine's Length: " + line.Length; } // Get curve start point message += "\nStart point: " + XYZToString(curve.GetEndPoint(0)); // Get curve end point message += "; End point: " + XYZToString(curve.GetEndPoint(0));
voidCreateGrid(Autodesk.Revit.DB.Document document) { // Create the geometry line which the grid locates XYZ start = new XYZ(0, 0, 0); XYZ end = new XYZ(30, 30, 0); Line geomLine = Line.CreateBound(start, end);
// Create a grid using the geometry line Grid lineGrid = Grid.Create(document, geomLine);
if (null == lineGrid) { thrownew Exception("Create a new straight grid failed."); }
// Modify the name of the created grid lineGrid.Name = "New Name1";
// Create the geometry arc which the grid locates XYZ end0 = new XYZ(0, 0, 0); XYZ end1 = new XYZ(10, 40, 0); XYZ pointOnCurve = new XYZ(5, 7, 0); Arc geomArc = Arc.Create(end0, end1, pointOnCurve);
// Create a grid using the geometry arc Grid arcGrid = Grid.Create(document, geomArc);
if (null == arcGrid) { thrownew Exception("Create a new curved grid failed."); }
// Modify the name of the created grid arcGrid.Name = "New Name2"; }
voidGetinfo_Phase(Document doc) { // Get the phase array which contains all the phases. PhaseArray phases = doc.Phases; // Format the string which identifies all supported phases in the current document. String prompt = null; if (0 != phases.Size) { prompt = "All the phases in current document list as follow:"; foreach (Phase ii in phases) { prompt += "\n\t" + ii.Name; } } else { prompt = "There are no phases in current document."; } // Give the user the information. TaskDialog.Show("Revit",prompt); }
voidGetinfo_DesignOption(Document document) { // Get the selected Elements in the Active Document UIDocument uidoc = new UIDocument(document); ICollection selectedIds = uidoc.Selection.GetElementIds();
foreach (ElementId id in selectedIds) { Element element = document.GetElement(id); //Use the DesignOption property of Element if (element.DesignOption != null) { TaskDialog.Show("Revit",element.DesignOption.Name.ToString()); } } }