Then the Code
.. and a file attachment for members ..
Comments, Improvements, ideas appreciated ..
//CodeHimBelongaKdub © May2009
public class MoveEndOfLine
{
///-------------------------------------------------------------------
///
[CommandMethod("SOL")]
public void SelectLine_1()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
Point3d pickPoint;
ObjectId pickedID = SelectObject(
"\nSelect Line entity near end to Relocate : ",
typeof(Line), out pickPoint
);
if (pickedID.IsNull)
{
WinForms.MessageBox.Show(
"ooops !! \nCancelling Routine.", "F.U.B.B.",
WinForms.MessageBoxButtons.OK,
WinForms.MessageBoxIcon.Hand
);
return;
}
Line pickedLine;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
pickedLine = tr.GetObject(pickedID, OpenMode.ForRead) as Line;
}
Debug.WriteLine("\nSelectLine_1 : -------------------------------");
Debug.WriteLine("\nEntity.GetType() : " + pickedLine.GetType().Name);
Debug.WriteLine("\npickedPoint() : " + pickPoint);
Debug.WriteLine("\nstartPoint() : " + pickedLine.StartPoint);
Debug.WriteLine("\nendPoint() : " + pickedLine.EndPoint);
Point3d vertexPoint;
Point3d basePoint;
bool startPoint_IS_vertex = (
pickPoint.DistanceTo(pickedLine.StartPoint)
<=
pickPoint.DistanceTo(pickedLine.EndPoint)
);
if (startPoint_IS_vertex)
{
Debug.WriteLine("\nStartPoint to PickPoint : "
+ pickPoint.DistanceTo(pickedLine.StartPoint));
vertexPoint = pickedLine.StartPoint;
basePoint = pickedLine.EndPoint;
}
else
{
Debug.WriteLine("\nEndPoint to PickPoint : "
+ pickPoint.DistanceTo(pickedLine.EndPoint));
vertexPoint = pickedLine.EndPoint;
basePoint = pickedLine.StartPoint;
}
//-----------------------------------------------------------------
PromptPointOptions ppo = new PromptPointOptions("\nGet New EndPoint: ");
ppo.UseBasePoint = true;
ppo.UseDashedLine = true;
ppo.BasePoint = basePoint;
PromptPointResult ppr = ed.GetPoint(ppo);
if (ppr.Status != PromptStatus.OK)
{
ed.WriteMessage("\nSelection is null ... Cancelling Routine.");
return;
}
Point3d p = ppr.Value;
Debug.WriteLine("\nNew Vertex Location : " + p);
// Change property of appropriate Line End to be the selected Point.
using (Transaction tr = db.TransactionManager.StartTransaction())
{
pickedLine = tr.GetObject(pickedID, OpenMode.ForWrite) as Line;
if (startPoint_IS_vertex)
{
pickedLine.StartPoint = p;
}
else
{
pickedLine.EndPoint = p;
}
tr.Commit();
}
}
//CodeHimBelongaKdub © May2009
static ObjectId SelectObject(string prompt,
System.Type objectClass,
out Point3d pickPoint)
{
Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
using (Transaction tr = ed.Document.Database.TransactionManager.StartTransaction())
{
while (true)
{
PromptEntityResult res = ed.GetEntity(prompt);
if (res.Status != PromptStatus.OK)
return ObjectId.Null;
DBObject dbObj = tr.GetObject(res.ObjectId, OpenMode.ForRead);
if (objectClass.IsAssignableFrom(dbObj.GetType()))
{
pickPoint = res.PickedPoint;
return res.ObjectId;
}
ed.WriteMessage("\nInvalid selection, {0} entity expected",
RXClass.GetClass(objectClass).DxfName);
}
}
}