My work is insert a block (waiting for user input rotation) then delete a polyline. I used 'SendStringToExecute' method.
My solution:
public static ObjectId DgiongID;
public static event EventHandler eRainManhole;
[CommandMethod("RainManhole")]
public static void RainManhole()
{
if (eRainManhole != null)
{
eRainManhole(null, null);
}
}
[CommandMethod("Rman")]
public static void InsertRman()
{
......
Get one point form user
Offset from one center line to this point, this offset objectID store in DgiongID
User pick a point in offset object store in Pchen
Insert a block at that point and waiting for user input rotation, then delete object: DgiongID
......
string command = "(command " + '"' + "Insert" + '"' + " " + '"' + "$RSman$ ";
command = command + "'(" + Pchen.X + " " + Pchen.Y + ") ";
command = command + "1 1 pause " + '"' + "RainManhole" + '"' + ") ";
eRainManhole += new EventHandler(DeleteGiong);
acDoc.SendStringToExecute(command, false, false, false);
}
public static void DeleteGiong(object sender, EventArgs e)
{
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
Transaction acTrans = acCurDb.TransactionManager.StartTransaction();
using (acTrans)
{
DBObject Dgiong = (DBObject)acTrans.GetObject(DgiongID, OpenMode.ForWrite, true, true);
Dgiong.Erase();
acTrans.Commit();
}
}
With this solution everyhing is done. But the problem is if user hit the UP ARROW KEY in AutoCAD command history is not my defined command, they have to hit twice if want to get 'RMAN' command. It's not flexible for user when they want to do this function continuously. So I ask for a better solution.
thanks.