Thứ Bảy, 25 tháng 5, 2024

Lấy thông tin đối tượng Entity nhanh | Directly ObjectId Clone | AutoCAD dotnet

Ứng dụng được phát triển bởi đội ngũ AutoLISP Thật là đơn giản
   

Thông tin thêm: 👉👉👉
Khi Có ObjectId mà cần Truy suất nhanh thông tin đối tượng thì làm ntn?


1 Thêm MyCommands.cs

(Copy nội dung sau)
Code:
    internal class MyCommands
    {
        [CommandMethod("CloneEntity")]
        public void cmdd_CloneEntity()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            if (doc == null) return;

            Editor ed = doc.Editor;

            var sf = new SelectionFilter(new TypedValue[] { new TypedValue(0, "*TEXT") });
            var psr = ed.GetSelection(sf);
            if (psr.Status != PromptStatus.OK) return;

            var id0 = psr.Value.GetObjectIds().FirstOrDefault();

            var txt0 = id0.Clone<Entity>();
            if (txt0.Bounds.HasValue)
            {
                var p0 = txt0.Bounds.Value.MinPoint + 0.5 * txt0.Bounds.Value.MinPoint.GetVectorTo(txt0.Bounds.Value.MaxPoint);

                ed.WriteMessage("\n" + p0);
            }
        }
    }


2 Thêm class ObjectIdCloneExtensions.cs

(Copy nội dung sau)
Code:
    internal static class ObjectIdCloneExtensions
    {
        public static T Clone<T>(this ObjectId id) where T : Entity
        {
            T d = null;
            using (Transaction tr = id.Database.TransactionManager.StartTransaction())
            {
                DBObject db = tr.GetObject(id, OpenMode.ForRead);
                d = db.Clone() as T;
                tr.Commit();
            }
            return d;
        }
    }



---------------------------------------------------------------------------------------------
Ứng dụng được phát triển bởi đội ngũ AutoLISP Thật là đơn giản - Tác giả ứng dụng in D2P

    

Mọi thông tin xin liên hệ Fanpage AutoLISP Thật là đơn giản!
Cảm ơn bạn đã theo dõi!

Không có nhận xét nào:

Đăng nhận xét

Quy hoạch Giao thông | Quy hoạch LDT 3D năm 2025

Ứng dụng được phát triển bởi đội ngũ AutoLISP Thật là đơn giản       Thông tin thêm: 👉👉👉