|
下面的代码
Public Shared Sub Crotate()
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
ed = Application.DocumentManager.MdiActiveDocument.Editor
ed.WriteMessage(vbLf & "选择实体: ")
Dim res As PromptSelectionResult = ed.GetSelection()
Dim SS As SelectionSet = res.Value
For Each theid As ObjectId In SS.GetObjectIds
Dim ent As Entity = CType(theid.GetObject(OpenMode.ForWrite), Entity)
ed.WriteMessage(ent.GetType.ToString)
Next
End Sub
会在Dim ent As Entity = CType(theid.GetObject(OpenMode.ForWrite), Entity) 这里出致命错误,只有用
Dim db As Database
Dim tm As Transaction
db = HostApplicationServices.WorkingDatabase
tm = db.TransactionManager.StartTransaction()
' Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
'构建用于移动实体的矩阵
Dim vector As Vector3d = sourcePt.GetVectorTo(targetPt)
Dim mt As Matrix3d = Matrix3d.Displacement(vector)
'以写的方式打开id表示的实体对象
Try
Dim acadEntity As Entity = CType(tm.GetObject(id, OpenMode.ForWrite), Entity)
' ed.WriteMessage(vbCrLf & acadEntity.IsWriteEnabled.ToString)
acadEntity.TransformBy(mt)
tm.Commit()
Finally
tm.Dispose()
End Try
这样的语法才不会出错,这是什么原因呢?
查询objectid是有这个GetObject接口的。
|
|