I am trying to interrogate AutoCAD objects with C #. I am interested in the ability to capture all the properties of this object and display them. For example, in the code snippet below, I look through all the elements on the screen and simply reflect their properties of the first class. The objects I care about often have the first-class AcadObject property, which seems to store the data that I follow. The problem is that it is a __ComObject and that many of its nested proposition objects do not provide properties through reflection. For example, obj.AcadObject.Connectors seems to be a collection of connector objects that I am very interested in. I can reflect this depth using the debugger, but from there I left an assumption about the properties of the Connectors collection and its objects (the .Net debugger shows the Count property that repelled me). Using the C # keyword and DLR / COM binders built into .Net 4 I can examine these objects. For example, I can use a dynamic expression to capture obj.AcadObject.Connectors [0] .Name, assuming it has a name attribute. I am ready to use dynamic expressions to capture these properties, but I need to know which properties in the first place. I have researched quite a lot and do not seem to see a link to how these objects look. There are several more objects that depend on AcadObject, as well as what I would like to export.
var currentDocument = Application.DocumentManager.MdiActiveDocument; var editor = currentDocument.Editor; var database = editor.Document.Database; var result = editor.SelectAll(); using (var transaction = database.TransactionManager.StartTransaction()) { foreach (var id in result.Value.GetObjectIds()) { var obj = transaction.GetObject(id, OpenMode.ForRead); var properties = TypeDescriptor.GetProperties(obj.AcadObject).Cast<PropertyDescriptor>().OrderBy(prop => prop.Name); writer.WriteLine("{0} ID:{1}", obj.GetType().Name, obj.Id); writer.WriteLine("\r\n\r\n"); foreach (var property in properties) { var propertyObject = property.GetValue(obj.AcadObject); writer.WriteLine(" {0} = {1}", property.Name, propertyObject); } writer.Write("\r\n\r\n\r\n"); } }
source share