Untitled
unknown
csharp
a year ago
4.0 kB
10
Indexable
[CommandMethod("Cr_Proj_Prof")] public void Cr_Proj_Prof() { Document DocCad = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Editor DocEditor = DocCad.Editor; Database DocData = DocCad.Database; CivilDocument CivilDocumento = CivilApplication.ActiveDocument; 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()) { LayerTable TabelaLayers = tr.GetObject(DocData.LayerTableId, OpenMode.ForRead) as LayerTable; ObjectId IDLayer = TabelaLayers["0"]; try { ObjectIdCollection alignments = CivilDocumento.GetAlignmentIds(); foreach (ObjectId alignmentId in alignments) { Alignment alignment = tr.GetObject(alignmentId, OpenMode.ForRead) as Alignment; if (alignment == null) continue; string projectName = $"{prefix}_{alignment.Name}"; Profile profile = CreateProfile(tr, alignment, projectName, IDLayer); 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, ObjectId IDLayer) { ObjectIdCollection profileIds = alignment.GetProfileIds(); Profile newProfile = null; CivilDocument DocCivil = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument; ObjectId IDNovoEstilo = DocCivil.Styles.ProfileStyles.Add(profileName); ObjectId IDLabel = DocCivil.Styles.LabelSetStyles.ProfileLabelSetStyles[0]; ObjectId profileId = Profile.CreateByLayout(profileName, alignment.ObjectId, IDLayer ,IDNovoEstilo, IDLabel); newProfile = tr.GetObject(profileId, OpenMode.ForWrite) as Profile; return newProfile; } private void AdjustProfileElevations(Transaction tr, Profile profile, Alignment alignment) { 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") { terrainProfile = tempProfile; break; } } if (terrainProfile == null) { throw new System.Exception("Perfil de terreno não encontrado."); } double startStation = alignment.StartingStation; double endStation = alignment.EndingStation; double startElevation = terrainProfile.ElevationAt(startStation); double endElevation = terrainProfile.ElevationAt(endStation); 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