Mẫu Code tạo Profile từ một tuyến đường với Csharp

NgoQuocViet November 30, 2012 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.Civil.DatabaseServices;
using Autodesk.Civil;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
namespace OffsetAlignmentDemo
    public class OffsetDemo
        public void CreateProfileNoSurface()
            var doc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument;
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            using (Transaction ts = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
                // Ask the user to select an alignment 
                PromptEntityOptions opt = new PromptEntityOptions("\nSelect an Alignment");
                opt.SetRejectMessage("\nObject must be an alignment.\n");
                opt.AddAllowedClass(typeof(Alignment), false);
                ObjectId alignID = ed.GetEntity(opt).ObjectId;
                Alignment oAlignment = ts.GetObject(alignID, OpenMode.ForRead) as Alignment;
                // use the same layer as the alignment
                ObjectId layerId = oAlignment.LayerId;
                // get the standard style and label set 
                // these calls will fail on templates without a style named "Standard"
                ObjectId styleId = doc.Styles.ProfileStyles["Basic"];
                ObjectId labelSetId = doc.Styles.LabelSetStyles.ProfileLabelSetStyles["_No Labels"];
                ObjectId oProfileId = Profile.CreateByLayout("My Profile", alignID, layerId, styleId, labelSetId);
                // Now add the entities that define the profile.
                // Create insertion point:
                Point3d ptInsert = new Point3d(100, 100, 0);
                // Get profile view band set style ID:
                ObjectId pfrVBSStyleId = doc.Styles.ProfileViewBandSetStyles["_No Bands"];
                // If this doesn’t exist, get the first style in the collection
                if (pfrVBSStyleId == null) pfrVBSStyleId = doc.Styles.ProfileViewBandSetStyles[0];
                ObjectId ProfileViewId = ProfileView.Create(doc, "New Profile View", pfrVBSStyleId, alignID, ptInsert);

Leave A Response »

You must be logged in to post a comment.