/// <summary> /// Finds all the views in the active document. /// </summary> /// <param name="doc">the active document</param> private void GetAllViews(Document doc) { FilteredElementCollector collector = new FilteredElementCollector(doc); FilteredElementIterator itor = collector.OfClass(typeof(Autodesk.Revit.DB.View)).GetElementIterator(); itor.Reset(); while (itor.MoveNext()) { Autodesk.Revit.DB.View view = itor.Current as Autodesk.Revit.DB.View; // skip view templates because they're invisible in project browser if (null == view || view.IsTemplate) { continue; } else { ElementType objType = doc.get_Element(view.GetTypeId()) as ElementType; if (null == objType || objType.Name.Equals("Schedule") || objType.Name.Equals("Drawing Sheet")) { continue; } else { m_allViews.Insert(view); AssortViews(view.Name, objType.Name); } } } }
/// <summary> /// Get the room property value according the parameter name /// </summary> /// <param name="activeDoc">Current active document.</param> /// <param name="room">an instance of room class</param> /// <param name="paraEnum">the parameter used to get parameter value</param> /// <param name="useValue">convert parameter to value type or not. /// if true, the value of parameter will be with unit. /// if false, the value of parameter will be without unit.</param> /// <returns>the string value of property specified by shared parameter</returns> public static String GetProperty(Document activeDoc, Room room, BuiltInParameter paraEnum, bool useValue) { String propertyValue = null; //the value of parameter // Assuming the build in parameter is legal for room. // if the room is not placed, some properties are not available, i.g. Level name, Area ... // trying to retrieve them will throw exception; // however some parameters are available, e.g.: name, number Parameter param; try { param = room.get_Parameter(paraEnum); } catch (Exception) { // throwing exception for this parameter is acceptable if it's a unplaced room if (null == room.Location) { propertyValue = "Not Placed"; return propertyValue; } else { throw new Exception("Illegal built in parameter."); } } // get the parameter via the built in parameter if (null == param) { return ""; } // get the parameter's storage type and convert parameter to string StorageType storageType = param.StorageType; switch (storageType) { case StorageType.Integer: int iVal = param.AsInteger(); propertyValue = iVal.ToString(); break; case StorageType.String: propertyValue = param.AsString(); break; case StorageType.Double: // AsValueString will make the return string with unit, it's appreciated. if (useValue) { propertyValue = param.AsValueString(); } else { propertyValue = param.AsDouble().ToString(); } break; case StorageType.ElementId: Autodesk.Revit.DB.ElementId elemId = param.AsElementId(); Element elem = activeDoc.get_Element(elemId); propertyValue = elem.Name; break; default: propertyValue = param.AsString(); break; } return propertyValue; }
/// <summary> /// create a column instance and place it on the wall line. /// </summary> /// <param name="rvtApp">revit application</param> /// <param name="rvtDoc">revit document</param> /// <param name="point2">location for placing column</param> /// <param name="angle">column angle</param> /// <param name="columnType">column type placed in Wall</param> /// <param name="baseLevelId">level id for base level where column is placed</param> /// <param name="topLevelId">level id for top level where column is placed</param> private void PlaceColumn(Autodesk.Revit.ApplicationServices.Application rvtApp, Document rvtDoc, Autodesk.Revit.DB.XYZ point2, double angle, FamilySymbol columnType, Autodesk.Revit.DB.ElementId baseLevelId, Autodesk.Revit.DB.ElementId topLevelId) { Autodesk.Revit.DB.XYZ point = point2; // Note: Must use level-hosted NewFamilyInstance! Level instLevel = (Level)rvtDoc.get_Element(baseLevelId); Autodesk.Revit.DB.FamilyInstance column = rvtDoc.Create.NewFamilyInstance(point, columnType, instLevel, Autodesk.Revit.DB.Structure.StructuralType.Column); if (column == null) { MessageBox.Show("failed to create an instance of a column."); return; } // rotate column to place it to right location Autodesk.Revit.DB.XYZ zVec = new Autodesk.Revit.DB.XYZ (0, 0, 1); Autodesk.Revit.DB.Line axis = rvtApp.Create.NewLineUnbound(point, zVec); column.Location.Rotate(axis, angle); // Set the level Ids Parameter baseLevelParameter = column.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.FAMILY_BASE_LEVEL_PARAM); Parameter topLevelParameter = column.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.FAMILY_TOP_LEVEL_PARAM); ; baseLevelParameter.Set(baseLevelId); topLevelParameter.Set(topLevelId); }