Imports ZwSoft.ZwCAD.Runtime
Imports ZwSoft.ZwCAD.ApplicationServices
Imports ZwSoft.ZwCAD.DatabaseServices
Imports ZwSoft.ZwCAD.EditorInput



Public Class ZwcadApps
    <CommandMethod("AnonymousBlock")> _
    Public Sub AnonymousBlock()
        Dim ZcDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim ZcDB As Database = ZcDoc.Database
        Dim ZcEd As Editor = ZcDoc.Editor


        Using ZcTran As Transaction = ZcDB.TransactionManager.StartTransaction()
            Dim ZcBTR As BlockTableRecord = Nothing
            Dim objId As ObjectId = ObjectId.Null


            Do
                Dim peo As New PromptEntityOptions(vbLf & "Select a block:")
                peo.SetRejectMessage(vbLf & "Must be a block.")
                peo.AddAllowedClass(GetType(BlockReference), True)


                Dim per As PromptEntityResult = ZcEd.GetEntity(peo)
                If per.Status <> PromptStatus.OK Then
                    Return
                End If


                Dim br As BlockReference = DirectCast(ZcTran.GetObject(per.ObjectId, OpenMode.ForRead), BlockReference)
                ZcBTR = DirectCast(ZcTran.GetObject(br.BlockTableRecord, OpenMode.ForRead), BlockTableRecord)




                If ZcBTR.IsAnonymous Then
                    objId = br.BlockTableRecord
                End If
            Loop While ZcBTR Is Nothing


            If objId <> ObjectId.Null Then
                ZcEd.WriteMessage(vbLf & "The object is an Anonymous block.")
            Else
                ZcEd.WriteMessage(vbLf & "The object is not an Anonymous block.")
            End If
            ZcTran.Commit()
        End Using
    End Sub
End Class
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐