CAD/CAM discussion forum > CAD Tutorial & Tips > [CAD Source Codes] ZWCAD, how to test anonymous block

[CAD Source Codes] ZWCAD, how to test anonymous block

  Subscribe Topic

Rank: 5Rank: 5


posts: 10

Registered: 2013-7-12

Message 1 of 1

 [CAD Source Codes] ZWCAD, how to test anonymous block
30-07-2013 01:48 . pm   |   View his/her posts only
ZWCAD+ sample code: how to test a block to see if it is anonymous block, how to check if it is a block with no name?
Here we go, sample code:

Imports ZwSoft.ZwCAD.Runtime

Imports ZwSoft.ZwCAD.ApplicationServices

Imports ZwSoft.ZwCAD.DatabaseServices

Imports ZwSoft.ZwCAD.EditorInput

Public Class ZwcadApps


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


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


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.")


ZcEd.WriteMessage(vbLf & "The object is not an Anonymous block.")

End If


End Using

End Sub
End Class

Try ZWCAD+ free for 30 days:
See also