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;
        }
    }---------------------------------------------------------------------------------------------
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