Check blocknames against database

Check blocknames against database

Anonymous
Not applicable
304 Views
4 Replies
Message 1 of 5

Check blocknames against database

Anonymous
Not applicable
Hello
I have a database of blocknames. Is there a way to check if the blocks in a drawing exist in my database?

Thanks
0 Likes
305 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
Hi,

Yes

Look at the ADO tools.

Also, clarify in your mind whether you want to check if "Blocks" are in the
drawing database or "BlockReferences" are in the drawing.

--


Regards

Laurie Comerford
wrote in message news:5824653@discussion.autodesk.com...
Hello
I have a database of blocknames. Is there a way to check if the blocks in a
drawing exist in my database?

Thanks
0 Likes
Message 3 of 5

Anonymous
Not applicable
since the blockrefs are merely "copies" of the block definition what
difference would it make?


"Laurie Comerford" wrote in message
news:5824849@discussion.autodesk.com...
Hi,

Yes

Look at the ADO tools.

Also, clarify in your mind whether you want to check if "Blocks" are in the
drawing database or "BlockReferences" are in the drawing.

--


Regards

Laurie Comerford
wrote in message news:5824653@discussion.autodesk.com...
Hello
I have a database of blocknames. Is there a way to check if the blocks in a
drawing exist in my database?

Thanks
0 Likes
Message 4 of 5

Anonymous
Not applicable
Here is a quick example how to connect
to database and match block names
if you have the array of these blocks

' request reference to: Microsoft ActiveX Data Object 2.X Library
Sub CompBlockNames()
On Error GoTo ErrorHandler

' connection and recordset variables
Dim conn As ADODB.connection
Dim rst As ADODB.Recordset
Dim sqlStr As String

' open connection
Set conn = New ADODB.connection
With conn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Data Source") = "C:\Temp\Test.mdb" '<--full path to database file
.Open
End With

' open recordset
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseClient
' change the table name to your suit (I use MyTable)
sqlStr = "SELECT MyTable.blockname FROM MyTable" '<-- blockname is field name in this table
rst.Open sqlStr, conn, adOpenStatic, adLockReadOnly, adCmdText

Dim ar As Variant
'say here is a list of block names:
ar = Array("a", "b", "c", "d", "e", "f", "g", "h")

Dim i As Integer
Dim col As New Collection

For i = 0 To UBound(ar)
rst.MoveFirst
Do While Not rst.EOF
If rst!blockname = ar(i) Then '<-- if the match have found then collect it
col.Add ar(i)
End If
rst.MoveNext
Loop
Next
Dim vr As Variant
For Each vr In col
Debug.Print vr
Next
' clean up
rst.Close
conn.Close
Set rst = Nothing
Set conn = Nothing
Exit Sub

ErrorHandler:

If Err <> 0 Then
MsgBox Err.Source & " --> " & Err.Description, , "Error"
End If

End Sub

~'J'~
0 Likes
Message 5 of 5

Anonymous
Not applicable
"Steve" wrote:

>> since the blockrefs are merely "copies" of the block definition

blockrefs are not 'merely copies' of a block definition.

BlockReferences often represent real-world things that
exist in a design. The presence of a block definition alone
doesn't mean that what it represence exists in a design,
which is only the case if there are references.

Which the OP is actually looking for depends on what
he's doing.
--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com
0 Likes