明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 664|回复: 1

id.getobject失效了吗? 出致命错误!?

[复制链接]
发表于 2016-1-8 13:13 | 显示全部楼层 |阅读模式
下面的代码
        <CommandMethod("ShowEntType")>
        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接口的。
 楼主| 发表于 2016-1-8 14:13 | 显示全部楼层
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-20 21:03 , Processed in 0.680395 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表