第一个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;
}
}
} 再用LISP写一个就更好了。{:1_12:} 看不懂,有点复杂!{:1_1:}{:1_8:} 本帖最后由 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)
)
看不懂,有点复杂! {:1_20:}{:1_20:}{:1_20:} BlockRecord 的包围盒和 BlockReference的 包围盒不是一回事
进入了撞到 谢谢分享{:1_12:}{:1_12:}{:1_12:}
页:
[1]