/// <summary> /// Добавление окна. /// </summary> /// <param name="hostWall"></param> public void AddWindow(Wall hostWall) { // hard coding the window type we will use. // e.g., "M_Fixed: 0915 x 1830mm const string windowFamilyName = "Фиксированные"; // "M_Fixed" const string windowTypeName = "0915 x 1830 мм"; // "0915 x 1830mm" const string windowFamilyAndTypeName = windowFamilyName + ": " + windowTypeName; double sillHeight = ElementModification.mmToFeet(915); // get the door type to use. FamilySymbol windowType = (FamilySymbol)ElementFiltering.FindFamilyType( m_rvtDoc, typeof(FamilySymbol), windowFamilyName, windowTypeName, BuiltInCategory.OST_Windows); if (windowType == null) { TaskDialog.Show("Revit Intro Lab", "Cannot find (" + windowFamilyAndTypeName + "). Try with DefaultMetric.rte."); } // get the start and end points of the wall. LocationCurve locCurve = (LocationCurve)hostWall.Location; XYZ pt1 = locCurve.Curve.GetEndPoint(0); XYZ pt2 = locCurve.Curve.GetEndPoint(1); // calculate the mid point. XYZ pt = (pt1 + pt2) / 2.0; // we want to set the reference as a bottom of the wall or level1. ElementId idLevel1 = hostWall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId(); Level level1 = (Level)m_rvtDoc.GetElement(idLevel1); // finally create a window. FamilyInstance aWindow = m_rvtDoc.Create.NewFamilyInstance(pt, windowType, hostWall, level1, StructuralType.NonStructural); // set the sill height aWindow.get_Parameter(BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM).Set(sillHeight); }
private void ModifyElement(Document doc, Element element) { using (Transaction transaction = new Transaction(doc, nameof(this.ModifyElement))) { transaction.Start(); Element newWallType = ElementFiltering.FindFamilyType( m_rvtDoc, typeof(WallType), "Базовая стена", "CW 102-50-100p", null); Wall aWall = (Wall)element; aWall.WallType = (WallType)newWallType; aWall.get_Parameter(BuiltInParameter.WALL_TOP_OFFSET).Set(mmToFeet(1000)); /*------------------------------------------------------------------------------*/ LocationCurve wallLocation = (LocationCurve)aWall.Location; // create a new line bound. XYZ pt1 = wallLocation.Curve.GetEndPoint(0); XYZ pt2 = wallLocation.Curve.GetEndPoint(1); double dt = mmToFeet(2000.0); XYZ newPt1 = new XYZ(pt1.X - dt, pt1.Y - dt, pt1.Z); XYZ newPt2 = new XYZ(pt2.X - dt, pt2.Y - dt, pt2.Z); Line newWallLine = Line.CreateBound(newPt1, newPt2); // finally change the curve. wallLocation.Curve = newWallLine; transaction.Commit(); } }
/// <summary> /// СОздать вдери /// </summary> /// <param name="hostWall"></param> public void AddDoor(Wall hostWall) { // hard coding the door type we will use. // e.g., "M_Single-Flush: 0915 x 2134mm const string doorFamilyName = "Одиночные-Щитовые"; // "M_Single-Flush" const string doorTypeName = "0915 x 2134 мм"; // "0915 x 2134mm" const string doorFamilyAndTypeName = doorFamilyName + ": " + doorTypeName; // get the door type to use. FamilySymbol doorType = (FamilySymbol)ElementFiltering.FindFamilyType( m_rvtDoc, typeof(FamilySymbol), doorFamilyName, doorTypeName, BuiltInCategory.OST_Doors); if (doorType == null) { TaskDialog.Show($"Revit Intro Lab", "Cannot find (" + doorFamilyAndTypeName + "). " + "Maybe you use a different template? Try with DefaultMetric.rte."); } // get the start and end points of the wall. LocationCurve locCurve = (LocationCurve)hostWall.Location; XYZ pt1 = locCurve.Curve.GetEndPoint(0); XYZ pt2 = locCurve.Curve.GetEndPoint(1); // calculate the mid point. XYZ pt = (pt1 + pt2) / 2.0; // we want to set the reference as a bottom of the wall or level1. ElementId idLevel1 = hostWall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId(); Level level1 = (Level)m_rvtDoc.GetElement(idLevel1); // finally, create a door. FamilyInstance aDoor = m_rvtDoc.Create.NewFamilyInstance(pt, doorType, hostWall, level1, StructuralType.NonStructural); }
public void ModifyElementPropertiesWall(Element elem) { // Constant to this function. // this is for wall. e.g., "Basic Wall: Exterior - Brick on CMU" // you can modify this to fit your need. const string wallFamilyName = "Basic Wall"; const string wallTypeName = "Exterior - Brick on CMU"; const string wallFamilyAndTypeName = wallFamilyName + ": " + wallTypeName; // for simplicity, we assume we can only modify a wall if (!(elem is Wall)) { TaskDialog.Show( "Revit Intro Lab", "Sorry, I only know how to modify a wall. Please select a wall."); return; } Wall aWall = (Wall)elem; // keep the message to the user. string msg = "Wall changed: " + "\n" + "\n"; // (1) change its family type to a different one. // (You can enhance this to import symbol if you want.) Element newWallType = ElementFiltering.FindFamilyType( m_rvtDoc, typeof(WallType), wallFamilyName, wallTypeName, null); if (newWallType != null) { aWall.WallType = (WallType)newWallType; msg = msg + "Wall type to: " + wallFamilyAndTypeName + "\n"; } }
/// <summary> /// Добавление крышы. /// </summary> /// <param name="walls"></param> public void addRoof(List <Wall> walls) { // hard coding the roof type we will use. // e.g., "Basic Roof: Generic - 400mm" const string roofFamilyName = "Базовая крыша"; const string roofTypeName = "Типовой - 125мм"; // "Generic - 400mm" const string roofFamilyAndTypeName = roofFamilyName + ": " + roofTypeName; // find the roof type RoofType roofType = (RoofType)ElementFiltering.FindFamilyType( m_rvtDoc, typeof(RoofType), roofFamilyName, roofTypeName, null); if (roofType == null) { TaskDialog.Show("Revit Intro Lab", "Cannot find (" + roofFamilyAndTypeName + "). " + "Maybe you use a different template? Try with DefaultMetric.rte.");; } // wall thickness to adjust the footprint of the walls // to the outer most lines. // Note: this may not be the best way. // but we will live with this for this exercise. double wallThickness = walls[0].Width; double dt = wallThickness / 2.0; List <XYZ> dts = new List <XYZ>(5) { new XYZ(-dt, -dt, 0.0), new XYZ(dt, -dt, 0.0), new XYZ(dt, dt, 0.0), new XYZ(-dt, dt, 0.0) }; dts.Add(dts[0]); // set the profile from four walls CurveArray footPrint = new CurveArray(); for (int i = 0; i < 4; i++) { LocationCurve locCurve = (LocationCurve)walls[i].Location; XYZ pt1 = locCurve.Curve.GetEndPoint(0) + dts[i]; XYZ pt2 = locCurve.Curve.GetEndPoint(1) + dts[i + 1]; Line line = Line.CreateBound(pt1, pt2); footPrint.Append(line); } // get the level2 from the wall ElementId idLevel2 = walls[0].get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).AsElementId(); Level level2 = (Level)m_rvtDoc.GetElement(idLevel2); // footprint to morel curve mapping ModelCurveArray mapping = new ModelCurveArray(); // create a roof. FootPrintRoof aRoof = m_rvtDoc.Create.NewFootPrintRoof(footPrint, level2, roofType, out mapping); // setting the slope foreach (ModelCurve modelCurve in mapping) { aRoof.set_DefinesSlope(modelCurve, true); aRoof.set_SlopeAngle(modelCurve, 0.5); } }