坐标问题
各位大侠:环境(vs2010+cad2010)
我从SQL数据中能读出DWG文件中一个块参照的坐标,怎么根据坐标这个坐标找到具体的块,也就是说,我想根据这个坐标删除这个块,怎么做啊,小妹很为难,谢谢。
Dim PtFormSQL As New Autodesk.AutoCAD.Geometry.Point3d(0, 0, 0) '这是你从SQL中读取的坐标值
Using Trans As Transaction = doc.TransactionManager.StartTransaction
Dim BlkTab As BlockTable = Trans.GetObject(doc.Database.BlockTableId, OpenMode.ForRead)
For Each ID As ObjectId In BlkTab
Dim Ent As Entity = Trans.GetObject(ID, OpenMode.ForRead)
If TypeOf Ent Is BlockReference Then
Dim Blk As BlockReference = Ent
Dim Pt As Autodesk.AutoCAD.Geometry.Point3d = Blk.Position
If Blk.Name = "xxxx" AndAlso Pt.DistanceTo(PtFormSQL) <= 0.1 Then '距离根据实际情况确定
'如果小于容差,就认为这个块你你想要的
'要不要判断名称,看着办
End If
End If
Next
End Using guohq 发表于 2015-6-11 11:00 static/image/common/back.gif
谢谢,谢谢大侠,我试试,非常感谢。 guohq 发表于 2015-6-11 11:00 static/image/common/back.gif
大侠:这句话If TypeOf Ent Is BlockReference Then,翻译成C#怎么写啊,我很菜,对不起
guohq 发表于 2015-6-11 11:00 static/image/common/back.gif
我按照你的做的为什么我的Ent一直返回是空啊,而ID是有值的。
private void getBlkForPt(Point3d dataBasePt)
{
Document doc = app.DocumentManager.MdiActiveDocument;
BlockReference Blk = null;
using (Transaction trans = doc.TransactionManager.StartTransaction())
{
BlockTable BlkTab = (BlockTable)trans.GetObject(doc.Database.BlockTableId, OpenMode.ForRead,true) as BlockTable;
foreach (ObjectId ID in BlkTab)
{
Entity Ent = trans.GetObject(ID,OpenMode.ForRead,true) as Entity;
if (Ent != null)
{
if (Ent is BlockReference)
{
Blk = (BlockReference)Ent;
Point3d pt = Blk.Position;
if (pt.DistanceTo(dataBasePt) <= 1)
{
Blk.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(255, 0, 0);
}
}
}
}
}
} if (Ent is BlockReference) 可能是这里有问题 Ent as BlockReference!= null 用选择集 我在另一个帖子回了
页:
[1]