CAD software discussion forum > CAD Tutorial & Tips > ZW CAD vb.net sample code: how to test anonymous block

ZW CAD vb.net sample code: how to test anonymous block

Rank: 5Rank: 5

Viola

posts: 10

Registered: 2013-7-12

Message 1 of 1

 ZW CAD vb.net sample code: how to test anonymous block
30-07-2013 01:48 . pm | View his/her posts only
ZWCAD+ vb.net 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, vb.net 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


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





Try ZWCAD+ free for 30 days:
http://www.zwsoft.com/zwcad+/
See also