Untitled
unknown
plain_text
a year ago
4.3 kB
6
Indexable
[CommandMethod("Cr_Proj_Prof")] public void Cr_Proj_Prof() { Document DocCad = Application.DocumentManager.MdiActiveDocument; Editor DocEditor = DocCad.Editor; Database DocData = DocCad.Database; CivilDocument CivilDocumento = CivilApplication.ActiveDocument; // Pedir prefixo ao usuário PromptStringOptions prefixOptions = new PromptStringOptions("\nInsira o prefixo para os perfis de projeto: "); PromptResult prefixResult = DocEditor.GetString(prefixOptions); if (prefixResult.Status != PromptStatus.OK) return; string prefix = prefixResult.StringResult; using (Transaction tr = DocData.TransactionManager.StartTransaction()) { try { // Obter todos os alinhamentos ObjectIdCollection alignments = CivilDocumento.GetAlignmentIds(); foreach (ObjectId alignmentId in alignments) { Alignment alignment = tr.GetObject(alignmentId, OpenMode.ForRead) as Alignment; if (alignment == null) continue; // Nome do novo perfil de projeto string projectName = $"{prefix}_{alignment.Name}"; // Criar um novo perfil de projeto Profile profile = CreateProfile(tr, alignment, projectName); // Ajustar as elevações inicial e final com base no perfil de terreno AdjustProfileElevations(tr, profile, alignment); DocEditor.WriteMessage($"\nPerfil de projeto '{projectName}' criado para o alinhamento '{alignment.Name}'."); } tr.Commit(); } catch (System.Exception ex) { DocEditor.WriteMessage($"\nErro: {ex.Message}"); } } } private Profile CreateProfile(Transaction tr, Alignment alignment, string profileName) { // Criar uma coleção de IDs de perfil ObjectIdCollection profileIds = alignment.GetProfileIds(); // Criar um novo perfil de projeto Profile newProfile = null; using (ProfileStyle style = new ProfileStyle()) { style.Name = profileName; ObjectId profileId = Profile.CreateByLayout(profileName, alignment.ObjectId, style.ObjectId, true); newProfile = tr.GetObject(profileId, OpenMode.ForWrite) as Profile; } return newProfile; } private void AdjustProfileElevations(Transaction tr, Profile profile, Alignment alignment) { // Obter o perfil de terreno existente ObjectIdCollection existingProfiles = alignment.GetProfileIds(); Profile terrainProfile = null; foreach (ObjectId profileId in existingProfiles) { Profile tempProfile = tr.GetObject(profileId, OpenMode.ForRead) as Profile; if (tempProfile != null && tempProfile.StyleName == "Terreno") // Supondo que o perfil do terreno seja identificado pelo estilo "Terreno" { terrainProfile = tempProfile; break; } } if (terrainProfile == null) { throw new System.Exception("Perfil de terreno não encontrado."); } // Ajustar as elevações inicial e final double startStation = alignment.StartingStation; double endStation = alignment.EndingStation; double startElevation = terrainProfile.GetElevationAt(startStation); double endElevation = terrainProfile.GetElevationAt(endStation); // Criar ou modificar o perfil de projeto com essas elevações profile.UpgradeOpen(); ProfilePVICollection pviCollection = profile.PVIs; if (pviCollection.Count > 0) { pviCollection[0].Elevation = startElevation; pviCollection[pviCollection.Count - 1].Elevation = endElevation; } else { profile.PVIs.AddPVI(startStation, startElevation); profile.PVIs.AddPVI(endStation, endElevation); } profile.DowngradeOpen(); } }
Editor is loading...
Leave a Comment