Author Topic: Compare block names against external list  (Read 1887 times)

0 Members and 1 Guest are viewing this topic.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Compare block names against external list
« on: October 22, 2008, 01:08:27 PM »
I've got a list of block names and need to compare them against an external list.  I was thinking of using a TXT file since it would be easy to update.  My current train of thought is to loop through the list of blocks (stored in a dictionary) and during each loop, open the TXT file, loop through that to see if the block name matches and if so, carry on with the rest of the program.  Any thoughts/suggestions on this process?  I'm open to different suggestions.
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Compare block names against external list
« Reply #1 on: October 22, 2008, 01:34:07 PM »
While searching through old programs I came across this.  It uses an Excel file as a database.  The original program looped through a selection set and searches for specific blocks with attributes.  It then compares the attribute text to a cell in the Excel file.  From there, other information from Excel is pulled and dumped into a table object in AutoCAD, creating a type of "dynamic" table.

Code: [Select]
    Dim x As Integer
    For x = 0 To UBound(objKeys)
        [color=red]GetLightInfo[/color] UCase(objKeys(x))
        objTable.InsertRows objTable.Rows, 0.59375, 1
        objTable.Update
        objTable.SetText objTable.Rows - 1, 0, objDict(objKeys(x))
        objTable.SetText objTable.Rows - 1, 1, UCase(objKeys(x))
        objTable.SetText objTable.Rows - 1, 2, strMfg
        objTable.SetText objTable.Rows - 1, 3, strDesc
        objTable.SetText objTable.Rows - 1, 4, strVolts
        objTable.SetText objTable.Rows - 1, 5, strLamps
    Next x

Code: [Select]
Option Explicit

Public cn As ADODB.Connection
Public rsT As ADODB.Recordset
Public rsC As ADODB.Recordset


Public Sub [color=red]GetLightInfo[/color](strID As String)
    Dim strQuery As String
    Dim rstQuery As New ADODB.Recordset
   
    OpenExcelDatabase
   
    strQuery = "SELECT * FROM [SCHEDULE_DATABASE$]"
    rstQuery.Open strQuery, cn, adOpenKeyset, adLockReadOnly
    rstQuery.Filter = "TYPE = '" & strID & "'"
   
    Do While Not rstQuery.EOF
        Debug.Print rstQuery!Type
        strDesc = rstQuery!Description
        strMfg = rstQuery("MFR & SERIES")
        strVolts = rstQuery!VOLTS
        strLamps = rstQuery!LAMPS
        rstQuery.MoveNext
    Loop
    rstQuery.Close
   
    CloseExcelDatabase
End Sub

Private Sub OpenExcelDatabase()
    Dim intTblCnt As Integer, intTblFlds As Integer
    Dim strTbl As String
    Dim intColCnt As Integer, intColFlds As Integer
    Dim strCol As String
    Dim t As Integer, c As Integer, f As Integer
   
    Set cn = New ADODB.Connection
   
    With cn
        .Provider = "Microsoft.Jet.OLEDB.4.0"
        .ConnectionString = "Data Source=" & _
        "E:\Luminaire.xls;Extended Properties=Excel 8.0;"
        .CursorLocation = adUseClient
        .Open
    End With
End Sub

Private Sub CloseExcelDatabase()
    On Error Resume Next
    rsT.Close
    rsC.Close
    cn.Close
End Sub
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io