用PromptPointOptions提示采得点插入块参照后,插入的点和显示图形不在一个位置,且,在插入点位置有一个奇怪的方形框与显示图形对应(无论移动哪一个,另外一个也随之移动),如图
右上角是显示的三个图形,左下角是实际插入时候点击的位置,这三个方框随右上角的图形的运动而运动,见鬼了,望高手指教原因,代码如下:
Dim ed As Editor = AcadApp.DocumentManager.MdiActiveDocument.Editor Dim db As Database = AcadApp.DocumentManager.MdiActiveDocument.Database ' 普通的点交互操作. Dim optPoint As New PromptPointOptions(vbCrLf & "请指定放置点:") Dim resPoint As PromptPointResult = ed.GetPoint(optPoint) If resPoint.Status <> PromptStatus.OK Then Return ObjectId.Null Using trans As Transaction = db.TransactionManager.StartTransaction() Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead) '如果没有blockName表示的块,则程序返回 If (bt.Has(blockname) = False) Then Return ObjectId.Null End If '创建一个块参照并设置插入点 Dim mt As Matrix3d = ed.CurrentUserCoordinateSystem Dim p3 As Point3d = resPoint.Value.TransformBy(mt) Dim block As BlockTableRecord = trans.GetObject(bt(blockname), OpenMode.ForRead) Dim blockref As BlockReference = New BlockReference(p3, bt(blockname)) '以写的方式打开当前空间(模型空间或图纸空间) Dim btr As BlockTableRecord = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) obid = btr.AppendEntity(blockref) '在当前空间加入创建的块参照 '通知事务处理加入创建的块参照 trans.AddNewlyCreatedDBObject(blockref, True) trans.Commit() '提交事务处理以实现块参照的真实加入 End Using
|