Hi.
I think there are two text classes: the MText class and the DBText class, right? I want to select the Lines and DBTexts, I don't want to select MText. How to exclude others. Here is what I have now:
public bool select()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
try
{
//How to define a Filter to select Line and DBText only?
TypedValue[] tv = new TypedValue[] { new TypedValue((int)DxfCode.Start, "LINE") };
SelectionFilter flt = new SelectionFilter(tv);
PromptSelectionOptions optSel = new PromptSelectionOptions();
optSel.MessageForAdding = "Drag the cursor to select";
PromptSelectionResult resSel = ed.GetSelection(optSel, flt);
if (resSel.Status != PromptStatus.OK)
{
return false;
}
SelectionSet selSet = resSel.Value;
ObjectId[] ids = selSet.GetObjectIds();
//I want to collect the Strings of the DBTexts, so I define a List<> to do it
List<string> TextLst = new List<string>();
foreach (ObjectId sSetEntId in ids)
{
Entity ent = (Entity)trans.GetObject(sSetEntId, OpenMode.ForRead);
//How to tell the Lines and DBTexts apart?
if (ent.GetType().Name == "Line")
{
//This means the loop entity is a line?
}
else if (ent.GetType().Name == "DBText")
{
//This means the loop entity is a single line Text?
DBText myText = (DBText)trans.GetObject(sSetEntId, OpenMode.ForRead);
string textStr = myText.TextString; //get the String
TextLst.Add(textStr); //collect teh string
}
}
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.Message + "\n" + ex.StackTrace);
return false;
}
trans.Commit();
return true;
}
}
How to fix the filter? Is my solution good? If not, are there any better solutions?