using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using Autodesk.Civil.DatabaseServices;
namespace C3dTest
{
public static class EditCurvePipeTest
{
[CommandMethod("SetPipeNewEndPoint")]
public static void SetPipeNewEndPoint()
{
Document adoc = Application.DocumentManager.MdiActiveDocument;
Editor ed = adoc.Editor;
Database db = adoc.Database;
PromptEntityOptions pipeOps
= new PromptEntityOptions("\nSelect a pipe: ");
pipeOps.SetRejectMessage("It's not a pipe!");
pipeOps.AddAllowedClass(typeof(Pipe), true);
PromptEntityResult pipeRes = ed.GetEntity(pipeOps);
if (pipeRes.Status != PromptStatus.OK) return;
PromptPointResult ptRes = ed.GetPoint
("\nSelect a new endpoint for the pipe: ");
if (ptRes.Status != PromptStatus.OK) return;
Point3d selPoint = ptRes.Value
.TransformBy(ed.CurrentUserCoordinateSystem);
using (Transaction tr = db.TransactionManager.StartTransaction())
{
Pipe pipe = tr.GetObject(pipeRes.ObjectId, OpenMode.ForWrite) as Pipe;
pipe.EndPoint = new Point3d(selPoint.X, selPoint.Y, pipe.EndPoint.Z);
tr.Commit();
}
}
}
}