Untitled
unknown
plain_text
a year ago
3.9 kB
14
Indexable
[CommandMethod("CR_Grade")]
public void CR_Grade()
{
// Selecionar ProfileViews existentes no desenho
TypedValue[] filtro = new TypedValue[] { new TypedValue((int)DxfCode.Start, "AECC_PROFILE_VIEW") };
SelectionFilter selFiltro = new SelectionFilter(filtro);
PromptSelectionResult selRes = Manager.DocEditor.GetSelection(selFiltro);
if (selRes.Status != PromptStatus.OK)
{
Manager.DocEditor.WriteMessage("\nNenhum ProfileView selecionado.");
return;
}
F_CR_Grade janela = new F_CR_Grade();
janela.ShowDialog();
if (!janela.Fazer)
{
return;
}
ObjectId idEstilo = Manager.DocCivil.Styles.ProfileStyles[janela.NomeEstiloPerfil];
ObjectId idLabel = Manager.DocCivil.Styles.LabelSetStyles.ProfileLabelSetStyles[janela.NomeLabelPerfil];
using (DocumentLock docLock = Manager.DocCad.LockDocument())
using (Transaction trCad = Manager.DocCad.TransactionManager.StartTransaction())
{
LayerTable tabelaLayers = (LayerTable)trCad.GetObject(Manager.DocData.LayerTableId, OpenMode.ForRead);
ObjectId idLayer = tabelaLayers[janela.NomeLayerPerfil];
try
{
ObjectIdCollection alignments = Manager.DocCivil.GetAlignmentIds();
foreach (ObjectId alignmentId in alignments)
{
Alignment alignment = trCad.GetObject(alignmentId, OpenMode.ForRead) as Alignment;
if (alignment == null) continue;
string projectName = $"{janela.PrefixoPerfil}{alignment.Name}";
Profile profile = CreateProfile(trCad, alignment, projectName, idLayer, idEstilo, idLabel);
AdjustProfileElevations(trCad, profile, alignment);
Manager.DocEditor.WriteMessage($"\nPerfil de projeto '{projectName}' criado para o alinhamento '{alignment.Name}'.");
}
trCad.Commit();
}
catch (System.Exception ex)
{
Manager.DocEditor.WriteMessage($"\nErro: {ex.Message}");
}
}
}
private Profile CreateProfile(Transaction trCad, Alignment alignment, string profileName, ObjectId idLayer, ObjectId idEstilo, ObjectId idLabel)
{
ObjectId profileId = Profile.CreateByLayout(profileName, alignment.ObjectId, idLayer, idEstilo, idLabel);
Profile newProfile = trCad.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