public async void CreateTankCrosshair()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
if (doc == null)
{
return;
}
Editor ed = doc.Editor;
Database db = doc.Database;
db.ObjectAppended += Db_ObjectAppended;
db.ObjectErased += Db_ObjectErased;
// Запускаем команду
try
{
doc.CommandCancelled += Cancelled;
await ed.CommandAsync("_.PLINE", Editor.PauseToken);
while (doc.CommandInProgress.ToUpper() == "PLINE")
{
await ed.CommandAsync(Editor.PauseToken); // Продолжаем команду
}
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
if (ex.ErrorStatus == ErrorStatus.UserBreak)
{
idPline = ObjectId.Null;
}
else
{
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.ToString());
}
}
catch (System.Exception sex)
{
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(sex.ToString());
}
// Здесь команда уже завершена
db.ObjectAppended -= Db_ObjectAppended;
db.ObjectErased -= Db_ObjectErased;
doc.CommandCancelled -= Cancelled;
ed.WriteMessage("\nPline завершилась. ObjectId = {0}\n", idPline);
ed.PostCommandPrompt();
if (!idPline.IsNull) // <-------
{
// Здесь уже можно обрабатывать полилинию.
Transaction tr = doc.TransactionManager.StartTransaction();
using (tr)
{
Polyline poly = (Polyline)tr.GetObject(idPline, OpenMode.ForWrite);
poly.Layer = BasicLayers.BulkheadsAndDecksThin;
poly.Linetype = ESKDValues.DashDotLine;
poly.LineWeight = LineWeight.ByLayer;
poly.Color = Color.FromColorIndex(ColorMethod.ByLayer, 256);
tr.Commit();
}
}
}
private void Db_ObjectAppended(object sender, ObjectEventArgs e)
{
if ( e.DBObject is Polyline )
{
idPline = e.DBObject.ObjectId;
}
}
private void Db_ObjectErased(object sender, ObjectErasedEventArgs e)
{
if ( e.DBObject.ObjectId == idPline )
{
idPline = ObjectId.Null;
}
}
private void Cancelled(object sender, CommandEventArgs e)
{
idPline = ObjectId.Null; // <-------------
}