void OnSelectionAdded(object sender, SelectionAddedEventArgs e)
{
ObjectId[] addedIds = e.AddedObjects.GetObjectIds();
for (int i = 0; i < addedIds.Length; i++)
{
ObjectId oid = addedIds[i];
if (disObjectId.Contains(oid))
{
e.Remove(i);
}
}
}
static List
<ObjectId
> disObjectId
= new List
<ObjectId
>();
public void Initialize()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
if (doc == null)
return;
Editor ed = doc.Editor;
ed
.SelectionAdded += new SelectionAddedEventHandler
(OnSelectionAdded
); }
public void Terminate()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
if (doc == null)
return;
Editor ed = doc.Editor;
ed
.SelectionAdded -= new SelectionAddedEventHandler
(OnSelectionAdded
); }
[CommandMethod("DisEntity")]
public void SelectDisplayEntity()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
if (doc == null)
return;
SelectionSet selects = GetSelectionSet();
foreach (SelectedObject sel in selects)
{
disObjectId.Add(sel.ObjectId);
}
}
SelectionSet GetSelectionSet()
{
Editor ed = null;
if (Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument != null)
{
ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
PromptSelectionResult ents = ed.SelectImplied();
if (ents.Value != null && ents.Value.Count == 1)
return ents.Value;
else if (ents.Value == null)
{
PromptSelectionOptions pso
= new PromptSelectionOptions
(); pso.AllowDuplicates = false;
pso.SingleOnly = false;
return ed.GetSelection(pso).Value;
}
else
return ents.Value;
}
return null;
}