我必须使用一组预先选择的折线来运行命令。因此我使用UsePickSet。
在命令之后,我需要通过hilighting /选择一组较小的过滤折线来向用户指示。我在处理后将这些添加到选择集。
然而,看起来,如果我们在方法属性中提到CommandFlags.UsePickSet,那么,它会在命令结束时自动清除选择集,即使它已更改。
有什么方法可以解决这个问题吗?
如果有人想尝试,我做了一个POC。 SetACADHandleSelection1将保留选择,而SetACADHandleSelection2则不会。
[CommandMethod("GetACADHandle", CommandFlags.UsePickSet)]
public static void GetACADHandle()
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
PromptSelectionResult res = ed.SelectImplied();
if (res.Status != PromptStatus.Error)
{
var pline = res.Value[0].ObjectId;
ed.WriteMessage(pline.Handle.ToString());
// SetACADHandleSelection(pline.Handle.ToString());
}
}
[CommandMethod("SetACADHandleSelection1")]
public static void SetACADHandleSelection1(string handle)
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
if (string.IsNullOrWhiteSpace(handle))
{
PromptResult res = ed.GetString("Enter acad Handle");
if (res.Status != PromptStatus.Error)
{
handle = res.StringResult;
}
}
if (!string.IsNullOrWhiteSpace(handle))
{
using (Transaction Tx = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
{
Handle handlep = new Handle(Convert.ToInt64(handle, 16));
ObjectId objId = db.GetObjectId(false, handlep, 0);
ed.SetImpliedSelection(new ObjectId[] { objId });
}
}
}
[CommandMethod("SetACADHandleSelection2", CommandFlags.UsePickSet)]
public static void SetACADHandleSelection2(string handle)
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
if (string.IsNullOrWhiteSpace(handle))
{
PromptResult res = ed.GetString("Enter acad Handle");
if (res.Status != PromptStatus.Error)
{
handle = res.StringResult;
}
}
if (!string.IsNullOrWhiteSpace(handle))
{
using (Transaction Tx = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
{
Handle handlep = new Handle(Convert.ToInt64(handle, 16));
ObjectId objId = db.GetObjectId(false, handlep, 0);
ed.SetImpliedSelection(new ObjectId[] { objId });
}
}
}
答案 0 :(得分:0)