Untitled

 avatar
unknown
plain_text
a year ago
2.8 kB
7
Indexable
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.Civil;
using Autodesk.Civil.DatabaseServices;
using Autodesk.Civil.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;

public class Principal
{
    [CommandMethod("C_Pr_View")]
    public void C_Pr_View()
    {
        // Iniciar o documento ativo
        Document DocCad = Application.DocumentManager.MdiActiveDocument;
        Database DocData = DocCad.Database;
        Editor DocEditor = DocCad.Editor;

        // Obter a base de dados do Civil 3D
        CivilDocument CivilDocumento = CivilApplication.ActiveDocument;

        using (Transaction tr = DocData.TransactionManager.StartTransaction())
        {
            // Selecionar o alinhamento
            PromptEntityOptions peo = new PromptEntityOptions("\nSelecione um alinhamento: ");
            peo.SetRejectMessage("\nIsso não é um alinhamento.");
            peo.AddAllowedClass(typeof(Alignment), false);
            PromptEntityResult per = DocEditor.GetEntity(peo);
            if (per.Status != PromptStatus.OK) return;

            Alignment alignment = tr.GetObject(per.ObjectId, OpenMode.ForRead) as Alignment;

            // Verificar se o alinhamento tem perfis
            ObjectIdCollection profileIds = alignment.GetProfileIds();
            if (profileIds.Count == 0)
            {
                DocEditor.WriteMessage("\nO alinhamento não possui perfis.");
                return;
            }

            // Obter o espaço do modelo
            BlockTable bt = tr.GetObject(DocData.BlockTableId, OpenMode.ForRead) as BlockTable;
            BlockTableRecord modelSpace = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

            // Configurar a posição inicial para o primeiro ProfileView
            double xPosition = 0.0;
            double yPosition = 0.0;
            double xOffset = 200.0; // Distância entre ProfileViews

            foreach (ObjectId profileId in profileIds)
            {
                Profile profile = tr.GetObject(profileId, OpenMode.ForRead) as Profile;

                // Criar o ProfileView
                ProfileView profileView = ProfileView.Create(modelSpace, profileId, new Point3d(xPosition, yPosition, 0));

                // Configurar o ProfileView conforme necessário
                profileView.StyleId = CivilDocumento.Styles.ProfileViewStyles[0]; // Estilo padrão
                profileView.Layer = "0"; // Camada para ProfileViews

                // Atualizar a posição para o próximo ProfileView
                xPosition += xOffset;
            }

            tr.Commit();
        }
    }
}
Editor is loading...
Leave a Comment