|
我对已有的一个块添加相应一个块参照,插入点由提示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
Dim obid As ObjectId
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
'以读的方式打开blockName表示的块
'Dim block As BlockTableRecord = trans.GetObject(bt(blockname), OpenMode.ForRead)
'创建一个块参照并设置插入点
Dim mt As Matrix3d = ed.CurrentUserCoordinateSystem
Dim p3 As Point3d = resPoint.Value.TransformBy(mt)
Dim blockref As BlockReference = New BlockReference(p3, bt(blockname))
'Dim blockref As BlockReference = New BlockReference(resPoint.Value, bt(blockname))
'blockref.ScaleFactors = New Scale3d(1) '设置块参照的缩放比例
'blockref.Rotation = 0.5 * Math.PI
'以写的方式打开当前空间(模型空间或图纸空间)
Dim btr As BlockTableRecord = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)
obid = btr.AppendEntity(blockref) '在当前空间加入创建的块参照
'通知事务处理加入创建的块参照
trans.AddNewlyCreatedDBObject(blockref, True)
trans.Commit() '提交事务处理以实现块参照的真实加入
End Using
Return obid
|
|