[CommandMethod("MSSTD")] public static void ListAlignments() { try { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; Database db = doc.Database; CivilDocument civDoc = CivilApplication.ActiveDocument; PromptKeywordOptions keywordOpts = new PromptKeywordOptions("\nÁp dụng cho ProfileView:"); keywordOpts.Keywords.Add("All"); keywordOpts.Keywords.Add("Select"); keywordOpts.Message = "\nChọn [All/Select]: "; keywordOpts.AllowNone = false; PromptResult keywordRes = ed.GetKeywords(keywordOpts); if (keywordRes.Status != PromptStatus.OK) return; bool applyToAll = (keywordRes.StringResult == "All"); // Nhập Elevation Min PromptDoubleOptions minOpts = new PromptDoubleOptions("\nNhập Elevation Min: "); minOpts.AllowNegative = true; PromptDoubleResult minRes = ed.GetDouble(minOpts); if (minRes.Status != PromptStatus.OK) return; // Nhập Elevation Max PromptDoubleOptions maxOpts = new PromptDoubleOptions("\nNhập Elevation Max: "); maxOpts.AllowNegative = true; PromptDoubleResult maxRes = ed.GetDouble(maxOpts); if (maxRes.Status != PromptStatus.OK) return; double userMin = minRes.Value; double userMax = maxRes.Value; if (userMin >= userMax) { ed.WriteMessage("\n⚠️ Lỗi: Elevation Min phải nhỏ hơn Elevation Max."); return; } using (Transaction tr = db.TransactionManager.StartTransaction()) { int count = 0; // Lấy toàn bộ Alignment ObjectIdCollection alignmentIds = civDoc.GetAlignmentIds(); // Mở ModelSpace để tìm các ProfileView BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable; BlockTableRecord ms = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; if (applyToAll) { foreach (ObjectId alignId in alignmentIds) { Alignment alignment = tr.GetObject(alignId, OpenMode.ForWrite) as Alignment; ed.WriteMessage($"\n Alignment: {alignment.Name}"); bool foundView = false; foreach (ObjectId objId in ms) { if (objId.ObjectClass.DxfName == "AECC_PROFILE_VIEW") { ProfileView pv = tr.GetObject(objId, OpenMode.ForWrite) as ProfileView; if (pv.AlignmentId == alignId) { pv.ElevationRangeMode = ElevationRangeType.UserSpecified; // Đặt chế độ khoảng cao độ cố định pv.ElevationMin = userMin; pv.ElevationMax = userMax; // Giả sử bạn muốn đặt giới hạn độ cao từ 0 đến 1000 foundView = true; ed.WriteMessage($"\n✔ ProfileView: {pv.Name} đã cập nhật."); } } } if (!foundView) { ed.WriteMessage("\n ⚠️ Không có ProfileView nào gắn với Alignment này."); } } tr.Commit(); } else { // Cho phép người dùng chọn nhiều ProfileView PromptSelectionOptions selOpts = new PromptSelectionOptions(); selOpts.MessageForAdding = "\nChọn các ProfileView cần chỉnh: "; SelectionFilter filter = new SelectionFilter(new TypedValue[] { new TypedValue((int)DxfCode.Start, "AECC_PROFILE_VIEW") }); PromptSelectionResult selRes = ed.GetSelection(selOpts, filter); if (selRes.Status != PromptStatus.OK) return; foreach (SelectedObject selObj in selRes.Value) { if (selObj != null) { ProfileView pv = tr.GetObject(selObj.ObjectId, OpenMode.ForWrite) as ProfileView; pv.ElevationRangeMode = ElevationRangeType.UserSpecified; pv.ElevationMin = userMin; pv.ElevationMax = userMax; ed.WriteMessage($"\n✔ ProfileView: {pv.Name} đã cập nhật."); count++; } } tr.Commit(); } } } catch { Application.ShowAlertDialog("Lỗi khi thực hiện lệnh. Vui lòng kiểm tra lại."); return; } }
0 Nhận xét