Trying to read drawings without opening them.

Discussion in 'AutoCAD' started by treyball3, Jul 3, 2003.

  1. treyball3

    treyball3 Guest

    I wrote a program in VBA (using some samples from Autodesk) that can retrieve certain information from drawings without opening them. It works beautifully in VBA, but since I can't pass a drawing name to VBA when calling it, I need to write it in plain ol' VB. When I do this, I get a nice error that reads as follows...

    "The instruction at "0x654dd6bc" referenced memory at "0x00000000". The memory could not be "read". Click on OK to terminate the program."

    This error occurs on this line of code...

    Set mDoc = New AXDB15Lib.AxDbDocument.

    I'm guessing that I need to establish some kind of connection to AutoCAD, I've tried some things, but still get this error. Anybody know anything?

    Thanks
    Todd
     
    treyball3, Jul 3, 2003
    #1
  2. treyball3

    treyball3 Guest

    nevermind. I got it figured out. Thanks
    Todd
     
    treyball3, Jul 3, 2003
    #2
  3. treyball3

    Mark Propst Guest

    curious, what was the solution? change to Set mdoc =
    GetInterfaceObject("ObjectDBX.AxDbDocument") ???

    nevermind. I got it figured out. Thanks
    Todd
     
    Mark Propst, Jul 4, 2003
    #3
  4. treyball3

    Soe Guest

    hey man,



        it's great u hv solved the problem.



        however, i am also very much interested in how to read block information from .dwg files without opening AutoCad application.



        any chance to share how u hv done?



        thanx.



     



    rgds,



    soe



    "treyball3" <> wrote in message news:...

    nevermind. I got it figured out. Thanks
    Todd
     
    Soe, Jul 4, 2003
    #4
  5. treyball3

    Mark Propst Guest

    i'm no expert but i think the general idea is:



    (just pseudocode, not exact syntax)



    this assumes you mean you want attribs in block references, not attdefs in block definitions...



     



    make sure objectdbx is referenced



    make sure objectdbx is registered



    get objdbx object



    open document with objdbx obj



    get ms of doc eg



    set ms = oDoc.ModelSpace



    foreach obj in ms



        if type obj = blockreference



              atts = obj.GetAttributes



            foreach att atts



               ...do whatever



            next att



    next obj



    etc



    "Soe" <> wrote in message news:...



    how d'u read the block attribute information, can u share?



    thanx.



     
     
    Mark Propst, Jul 4, 2003
    #5
  6. treyball3

    Soe Guest

    any chance to have coding.



    thanx.



    "Mark Propst" <nonentityatplanetkcdotcom> wrote in message news:...



    i'm no expert but i think the general idea is:



    (just pseudocode, not exact syntax)



    this assumes you mean you want attribs in block references, not attdefs in block definitions...



     



    make sure objectdbx is referenced



    make sure objectdbx is registered



    get objdbx object



    open document with objdbx obj



    get ms of doc eg



    set ms = oDoc.ModelSpace



    foreach obj in ms



        if type obj = blockreference



              atts = obj.GetAttributes



            foreach att atts



               ...do whatever



            next att



    next obj



    etc



    "Soe" <> wrote in message news:...



    how d'u read the block attribute information, can u share?



    thanx.



     
     
    Soe, Jul 7, 2003
    #6
  7. treyball3

    Mark Propst Guest

    sorry, I don't have anything that works yet



    here is my first try but it doesn't work yet



    maybe you can get to work



    i modified a sample from tony that did something else, but don't have it working yet, apologies Tony...



    i thought this would be the general idea of a way to go but ???



     



    'apologies to original author whose code
    'I have mangled below to try to show you a sample.
    'original code
    'From: Tony Tanzillo ()
    'posted to ng the other day
    'Remember that you must check "ObjectDBX 1.0 Type Library"
    'from the Tools|References dialog.



     



    Public Sub Test()
        Dim Dwg As String
        Dwg = "C:\0\test\test.dwg"
        Dim BlockName As String
        BlockName = "Test2"
        Dim blkcol As Collection
        blkcol = GetBlocks(Dwg, BlockName)
        Dim blkref As AXDB15Lib.AcadBlockReference
        Dim i As Integer
        For Each blkref In blkcol
          If blkref.HasAttributes Then
            For i = LBound(BlkAtts) To UBound(BlkAtts)
            MsgBox BlkAtts(i).TextString
            Next i
          End If
        Next blkref
         
    End Sub



     



    Public Function GetBlocks(DwgName As String, _
                        BlkName As String _
                        ) As Collection
        On Error GoTo Failed
        Dim DbxDoc As AxDbDocument
        Set DbxDoc = GetInterfaceObject("ObjectDBX.AxDbDocument")
        DbxDoc.Open DwgName
        Dim aobj As AXDB15Lib.AcadObject
        Dim bObj As AXDB15Lib.AcadBlockReference
        Dim blkcol As Collection
       
        For Each aobj In DbxDoc.ModelSpace
          MsgBox TypeName(aobj)
         
          If TypeName(aobj) = "IAcadBlockReference" Then
            Set bObj = aobj
            If bObj.Name = BlkName Then
             blkcol.Add bObj
             End If
            End If
        Next aobj
      GetBlocks = blkcol
    Failed:
    End Function



     



    "Soe" <> wrote in message news:...



    any chance to have coding.



    thanx.
     
    Mark Propst, Jul 7, 2003
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.