删除对象的问题
各位大侠:环境(vs2010+cad2010);我是根据数据库中的坐标(100,200,0),找到一个类型为Blockreference的块参照,然后删除掉,为什么不行呢??
我用这个函数返回根据坐标获取的块对象:
BlockReference blk = getBlkForPt(new Point3d(float.Parse("290"), float.Parse("621.3606"), 0));
blk.Erase(true);
这样删除不对吗???恳请大侠们指点一二,小妹在此不胜感激
public void Test1()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var ed = doc.Editor;
var db = doc.Database;
var res =
ed.SelectAll(
new SelectionFilter(
new TypedValue[]
{
new TypedValue(0, "insert"),
new TypedValue(10, new Point3d(100, 200, 0))
}));
if(res.Status != PromptStatus.OK)
return;
using (var tr = db.TransactionManager.StartTransaction())
{
var id = res.Value.GetObjectIds();
var ent = tr.GetObject(id, OpenMode.ForWrite);
ent.Erase();
tr.Commit();
}
}
按点查找可能还是会出些问题 通常是在该点为中心的范围内查找 雪山飞狐_lzh 发表于 2015-6-15 09:37 static/image/common/back.gif
按点查找可能还是会出些问题 通常是在该点为中心的范围内查找
飞狐大哥:
我这个坐标点是固定的,而且这个坐标点肯定对应这个块参照,我是这么写的
private BlockReference getBlkForPt(Point3d dataBasePt)
{
Document doc = app.DocumentManager.MdiActiveDocument;
BlockReference resultBlk = null;
using (DocumentLock d = doc.LockDocument())
{
using (Transaction trans = doc.TransactionManager.StartTransaction())
{
BlockTable BlkTab = (BlockTable)trans.GetObject(doc.Database.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(BlkTab, OpenMode.ForRead);
foreach (ObjectId ID in btr)
{
Entity Ent = trans.GetObject(ID, OpenMode.ForWrite) as Entity;
if (Ent != null)
{
if (Ent is BlockReference)
{
BlockReference Blk = (BlockReference)Ent;
Blk.Unhighlight();
Point3d pt = Blk.Position;
Point3d p1 = new Point3d(pt.X, pt.Y, 0);
double a = p1.DistanceTo(dataBasePt);
if (p1.DistanceTo(dataBasePt) <= 0.1)
{
resultBlk = Blk;
Blk.Highlight();
}
}
}
}
}
}
return resultBlk;
}
我这么写就把坐标对应的块参照找到了,而且高亮显示,然后怎么删除呢
页:
[1]