/// <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); }
/// <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); }
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> /// <returns></returns> public List <Wall> CreateWalls() { // hard coding the size of the house for simplicity double width = ElementModification.mmToFeet(10000.0); double depth = ElementModification.mmToFeet(5000.0); // get the levels we want to work on. // Note: hard coding for simplicity. Modify here you use // a different template. Level level1 = (Level)ElementFiltering.FindElement(m_rvtDoc, typeof(Level), "Level 1", null); if (level1 == null) { TaskDialog.Show("Revit Intro Lab", "Cannot find (Level 1). Maybe you use a different template? Try with DefaultMetric.rte."); return(null); } Level level2 = (Level)ElementFiltering.FindElement(m_rvtDoc, typeof(Level), "Level 2", null); if (level2 == null) { TaskDialog.Show("Revit Intro Lab", "Cannot find (Level 2). Maybe you use a different template? Try with DefaultMetric.rte."); return(null); } // set four corner of walls. // 5th point is for combenience to loop through. double dx = width / 2.0; double dy = depth / 2.0; List <XYZ> pts = new List <XYZ>() { new XYZ(-dx, -dy, 0.0), new XYZ(dx, -dy, 0.0), new XYZ(dx, dy, 0.0), new XYZ(-dx, dy, 0.0) }; pts.Add(pts[0]); // flag for structural wall or not. bool isStructural = false; // save walls we create. List <Wall> walls = new List <Wall>(4); // loop through list of points and define four walls. for (int i = 0; i <= 3; i++) { // define a base curve from two points. Line baseCurve = Line.CreateBound(pts[i], pts[i + 1]); // create a wall using the one of overloaded methods. Wall aWall = Wall.Create(m_rvtDoc, baseCurve, level1.Id, isStructural); // set the Top Constraint to Level 2 aWall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).Set(level2.Id); // save the wall. walls.Add(aWall); } // This is important. we need these lines to have shrinkwrap working. m_rvtDoc.Regenerate(); m_rvtDoc.AutoJoinElements(); return(walls); }