Message 1 of 9
Searching for an instance of an existing block in a drawing

Not applicable
06-20-2002
09:32 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
If I have a VBA macro which creates and inserts blocks then before creating
the block I can search the drawing for an instance of the block using this
code;
Public Function BlockExists(blockName As String) As Boolean
Dim blkDef As AcadBlock
On Error Resume Next
Set blkDef = ThisDrawing.Blocks("Datum Level Marker")
BlockExists = (Err.Number = 0)
End Function
Private Sub cmdOK_Click()
Dim Block As AcadBlock
Dim exblockRefObj As AcadBlockReference
Dim insertpt As Variant
For Each Block In ThisDrawing.Blocks
If Block.Name = "Datum Level Marker" Then
MsgBox "Block Exists in Drawing!", vbOKOnly, "Datum Level Marker Block:
"
' Insert the block
frmDatumLevelAtt.Hide
insertpt = ThisDrawing.Utility.GetPoint(, "Insertion Point : ")
Set exblockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertpt, "Datum
Level Marker", 1#, 1#, 1#, 0)
End If
Next Block
If Not BlockExists("Datum Level Marker") Then
' Create the Datum Level block
This works ok if I know the name of the block beforehand, but say I create
and name blocks according to data entered into text boxes how can I search
for instances of the block not knowing what it will be called until those
text boxes have been filled?
My block name is acquired by concatenating 2 textboxes when defining the
block as follows;
Dim Name As String
Name = TextBox1.text & " x " & TextBox2.text & " mm RC COLUMN"
Any help would be gratefully appreciated
Chris Boyd
the block I can search the drawing for an instance of the block using this
code;
Public Function BlockExists(blockName As String) As Boolean
Dim blkDef As AcadBlock
On Error Resume Next
Set blkDef = ThisDrawing.Blocks("Datum Level Marker")
BlockExists = (Err.Number = 0)
End Function
Private Sub cmdOK_Click()
Dim Block As AcadBlock
Dim exblockRefObj As AcadBlockReference
Dim insertpt As Variant
For Each Block In ThisDrawing.Blocks
If Block.Name = "Datum Level Marker" Then
MsgBox "Block Exists in Drawing!", vbOKOnly, "Datum Level Marker Block:
"
' Insert the block
frmDatumLevelAtt.Hide
insertpt = ThisDrawing.Utility.GetPoint(, "Insertion Point : ")
Set exblockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertpt, "Datum
Level Marker", 1#, 1#, 1#, 0)
End If
Next Block
If Not BlockExists("Datum Level Marker") Then
' Create the Datum Level block
This works ok if I know the name of the block beforehand, but say I create
and name blocks according to data entered into text boxes how can I search
for instances of the block not knowing what it will be called until those
text boxes have been filled?
My block name is acquired by concatenating 2 textboxes when defining the
block as follows;
Dim Name As String
Name = TextBox1.text & " x " & TextBox2.text & " mm RC COLUMN"
Any help would be gratefully appreciated
Chris Boyd