[Code]
public Wall CatKieuTuong(Autodesk.Revit.DB.Document doc)
{
try
{
// Chọn 1 đối tượng tường
Reference elem = uiApp.ActiveUIDocument.Selection.PickObject( ObjectType.Element, "Select a Wall");
Wall wall = (Wall)doc.GetElement(elem.ElementId);
// Chọn 1 điểm chỉ vị trí cần cắt
ObjectSnapTypes snapTypes = ObjectSnapTypes.Nearest;
XYZ DiemCat = uiApp.ActiveUIDocument.Selection. PickPoint(snapTypes, "Chọn điểm thứ hai");
//Tự đọc thông tin Level và Kiểu tường
ElementId level_Id = doc.ActiveView.GenLevel.Id;
ElementId wallType_Id = wall.WallType.Id;
// Đọc chiều cao đỉnh tường
double height = wall.LookupParameter( "Unconnected Height").AsDouble();
// Đọc chiều cao chân tường
double offset = wall.LookupParameter( "Base Offset").AsDouble();
// Đọc đường thẳng định vị tường
LocationCurve DuongChuanTuong = wall.Location as LocationCurve;
// Đọc điểm đầu và cuối tường
XYZ start = DuongChuanTuong.Curve.GetEndPoint(0);
XYZ end = DuongChuanTuong.Curve.GetEndPoint(1);
// Tạo đường thằng để nhận điểm chiếu
Line DoanThangTong = Line.CreateBound(start, end);
// tìm hình chiếu điểm chọn trên đường thẳng
IntersectionResult mid = DoanThangTong.Project(DiemCat);
// Bắt đàu tái tạo lại tường
// Tạo đoạn thẳng curver để tạo lại đoạn
Line DoanThangDau = Line.CreateBound(start, mid.XYZPoint);
Line DoanThangCuoi = Line.CreateBound(mid.XYZPoint, end);
// thay đồi đường chuẩn tường hiện hữu
DuongChuanTuong.Curve = DoanThangDau;
// Vẽ một tường mới cho đoạn còn lại
Wall.Create(doc, DoanThangCuoi, wallType_Id, level_Id, height, offset, true, false);
//Mở Form nhập dữ liệu
}
catch (Exception e)
{
TaskDialog.Show("Thông báo", e.Message);
}
//
return null;
}
[/Code]