MemberInfo查询DBObject的属性和方法


using System.Reflection;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Exception = System.Exception;

[assembly: CommandClass(typeof(AutoCAD_CSharp_plug_in35.MyCommands))]

namespace AutoCAD_CSharp_plug_in35
{
    public class MyCommands
    {
        [LispFunction("test", "MyLispFunctionLocal")]
        public void MyLispFunction(ResultBuffer args) // This method can have any name
        {
            if (args != null)
            {
                TypedValue[] values = args.AsArray();
                if (values .Length == 1 && values[0].TypeCode == (int)LispDataType .ObjectId )
                {
                    Document doc = Application.DocumentManager.MdiActiveDocument;
                    Editor ed = doc.Editor;
                    Database db = doc.Database;
                    Transaction tr = db.TransactionManager.StartTransaction();
                    using (tr)
                    {
                        try
                        {
                            var id =(ObjectId ) values[0].Value;
                            var obj = (DBObject) id.GetObject(OpenMode.ForRead);
                            foreach (MemberInfo objMemberInfo in obj.GetType().GetMembers())
                            {
                                ed.WriteMessage("\n" + objMemberInfo.Name.ToString());
                            }
                            tr.Commit();
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                }
            }
        }
    }
}

http://bbs.xdcad.net/thread-679007-1-1.html


    <CommandMethod("Tctype1", CommandFlags.Modal)> _
    Public Sub MyLispFunction()
        ' This method can have any name
        Dim dwg As Document = Application.DocumentManager.MdiActiveDocument
        Dim result As PromptEntityResult = dwg.Editor.GetEntity(vbLf & "Select entity: ")

        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = doc.Editor
        Dim db As Database = doc.Database
        Dim tr As Transaction = db.TransactionManager.StartTransaction()
        Using tr
            Try
                Dim id As ObjectId = CType(result.ObjectId, ObjectId)
                Dim obj As DBObject = CType(id.GetObject(OpenMode.ForRead), DBObject)
                For Each objMemberInfo As MemberInfo In obj.[GetType]().GetMembers()
                    ed.WriteMessage(vbLf + objMemberInfo.Name.ToString())
                Next
                tr.Commit()
            Catch generatedExceptionName As Exception
                Throw
            End Try
        End Using
    End Sub



预应力混凝土内扣式内螺纹抗拔管桩.苏GT27-2015.pdf

一种将Region转为Polyline的方法

欢迎关注微信公众账号ByCAD