判斷一個外部參照是overlay還是attachment。

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


Public Class ZwcadApp
    <CommandMethod("blockORxref")> _
    Public Sub blockORxref()
        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 reference or an external reference:")
                peo.SetRejectMessage(vbLf & "Must be a block reference or an external reference.")
                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.IsFromExternalReference Then

                    objId = br.BlockTableRecord

if ZcBTR.IsFromOverlayReference then

  ZcEd.WriteMessage(vbLf & "The object is an overlay reference.")
            else

  ZcEd.WriteMessage(vbLf & "The object is an attacment reference.")

end if
         

                End If
            Loop While ZcBTR Is Nothing  '(or) Loop Until Not ZcBTR Is Nothing


            If objId <> ObjectId.Null Then
                ZcEd.WriteMessage(vbLf & "The object is an external reference.")
            Else
                ZcEd.WriteMessage(vbLf & "The object is a block reference.")
            End If
            ZcTran.Commit()
        End Using


    End Sub
End Class
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章