We have a nicer, quicker, and better version of the help method, which can find AutoCAD objects of any Good and Supported type from a specific Database.
public static IEnumerable<ObjectId> findObjects<T>(Database db) where T : DBObject
{
RXClass rxclass = RXClass.GetClass(typeof(T));
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead);
foreach (ObjectId id in btr)
if (id.ObjectClass == rxclass)
yield return id;
tr.Commit();
}
}
Here is the test code.
[CommandMethod("TestAcadFind")]
public static void TestAcadFind_Method()
{
Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
try
{
IEnumerable<ObjectId> ids = findObjects<Circle>(db);
ed.WriteMessage(string.Format("\n{0} circles were found", ids.Count()));
}
catch (System.Exception ex)
{
ed.WriteMessage(Environment.NewLine + ex.ToString());
}
}
So, more and better work has been done with less code!
The leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard) provides various project wizards, item wizards, coders and widgets to help program AutoCAD .NET addins.
readers this post needs to be read in conjunction with the below:
http://spiderinnet1.typepad.com/blog/2012/04/various-ways-to-check-object-types-in-autocad-net.html
Posted by: BKSpurgeon | 02/07/2017 at 07:46 PM