455383153 发表于 2020-2-18 10:00:16

第一个c#练习的程序,遍历块获取块内图元的外框

本帖最后由 455383153 于 2020-2-18 10:02 编辑

         
         public void PickDemo()
         {
             Database db = HostApplicationServices.WorkingDatabase;
             Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
             PromptEntityResult per = ed.GetEntity("选择块");
             if (per.Status == PromptStatus.OK)
             {
               using (Transaction trans = db.TransactionManager.StartTransaction())
               {
                     ResultBuffer result = new ResultBuffer();
                     BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
                     BlockReference br = (BlockReference)per.ObjectId.GetObject(OpenMode.ForRead);
                     string blkname = br.Name;
                     ed.WriteMessage("\nBlock Name: (" + blkname + ").");
                     ObjectId blockRecordId = bt;
                     BlockTableRecord blockRecord = (BlockTableRecord)blockRecordId.GetObject(OpenMode.ForRead);
                     Extents3d tmpExtents3D = new Extents3d();
                     foreach (ObjectId entID in blockRecord)
                     {
                         Entity entity = (Entity)trans.GetObject(entID, OpenMode.ForRead);
                         Extents3d tmp = entity.GeometricExtents;
                         tmpExtents3D.AddExtents(tmp);
                     
                     
                     }
                     Point3d maxpt = tmpExtents3D.MaxPoint;
                     Point3d minpt = tmpExtents3D.MinPoint;
                     result.Add(new TypedValue((int)LispDataType.Point3d, minpt));
                     result.Add(new TypedValue((int)LispDataType.Point3d, maxpt));
                     trans.Commit();
                  //return result;
               }
             }
         }

tzfcn 发表于 2020-2-18 10:36:22

再用LISP写一个就更好了。{:1_12:}

dfd1716 发表于 2020-2-18 10:53:21

看不懂,有点复杂!{:1_1:}{:1_8:}

455383153 发表于 2020-2-18 20:38:31

本帖最后由 455383153 于 2020-2-18 20:39 编辑

tzfcn 发表于 2020-2-18 10:36
再用LISP写一个就更好了。

lisp版本的修改块内颜色   c#才看了一天书,不熟,lisp熟悉一点写着方便,但对比了代码,遍历的方法是一样的。
(defun c:doit( / blkname activedocument obj e i)
(setq activedocument (vla-get-activedocument (vlax-get-Acad-Object)))
(vla-StartUndoMark activedocument)
(setq blkname (Vlax-Get (Vlax-Ename->Vla-Object (car (entsel))) 'EffectiveName ))
(setq obj(vla-item (vla-get-blocks activedocument) blkname))
(setq i 0)
(vlax-for e obj
(if (vlax-write-enabled-p e)
      (vl-catch-all-apply
      (function(lambda()
   (vla-put-color e 1)
)
         )
       )
   )
   (setq i (+ 1 i))
   (acet-ui-status (strcat "共修改了块内" (rtos i 2 0) "个对象")"修改状态")
    )
(vla-regen activedocument acallviewports)
(vla-EndUndoMark activedocument)
(vlax-release-object activedocument)
(princ)
)

木瓜_dP7jf 发表于 2020-2-25 11:30:09

看不懂,有点复杂!

xiongdi6k 发表于 2020-4-1 09:44:41

{:1_20:}{:1_20:}{:1_20:}

st788796 发表于 2020-4-1 15:42:55

BlockRecord 的包围盒和 BlockReference的 包围盒不是一回事

CAD56390 发表于 2021-11-3 09:29:56

进入了撞到

dnbc 发表于 2025-11-13 14:41:07

谢谢分享{:1_12:}{:1_12:}{:1_12:}
页: [1]
查看完整版本: 第一个c#练习的程序,遍历块获取块内图元的外框