+ Reply to Thread
Results 1 to 10 of 10
  1. #1
    Forum Newbie
    Using
    AutoCAD 2008
    Join Date
    Jun 2007
    Posts
    2

    Default Autocad and Access

    Registered forum members do not see this ad.

    I'm trying to use automation of Autocad through MSAccess to get attributes out of a cad drawing. The code worked fine when I typed it up in Autocad, but when I moved it over to MSAccess it keeps crashing Access. Yes, I included the reference file.
    Here's what it looks like in Autocad:
    Code:
        Dim blkTitle As AcadBlockReference
        
        For Each oEnt In ThisDrawing.ModelSpace
            If oEnt.EntityType = acBlockReference Then
                If oEnt.HasAttributes Then
                    If oEnt.Name = "TITLE" Then
                        Set blkTitle = oEnt
                        If blkTitle.HasAttributes Then
                            aryAttributes = blkTitle.GetAttributes
                            MsgBox aryAttributes(0).TextString
                        End If
                    End If
                End If
            End If
        Next oEnt
    Here it is in Access:
    Code:
        Dim oACAD As AutoCAD.AcadApplication
        Dim oDoc As AutoCAD.AcadDocument
    
        Set oACAD = New AutoCAD.AcadApplication  'Start automation of Acad
        Set oDoc = oACAD.Documents.Open(FilepathInput, False)
    
        Dim blkTitle As AcadBlockReference
        For Each oEnt In oDoc.ModelSpace
            If oEnt.EntityType = acBlockReference Then
                If oEnt.HasAttributes Then
                    If oEnt.Name = "TITLE" Then
                        Set blkTitle = oEnt
                        If blkTitle.HasAttributes Then
                            aryAttributes = blkTitle.GetAttributes
                            MsgBox aryAttributes(0).TextString 'Crashes HERE
                        End If
                    End If
                End If
            End If
        Next oEnt
    I was wondering if anyone might have any insight into why it would be crashing? I don't get any error messages or anything, just a Send Error Report dialog. Could it have to do with the fact the objects in the Array are typed AcadAttributeReference? Thanks for any help you can provide.

    Ps. Running Autocad 2008
    Last edited by AKing; 15th Jun 2007 at 12:51 pm. Reason: Ps.

  2. #2
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Thanks God, I'm far enough from Hitleropa
    Posts
    1,697

    Default

    You can do it with late or early binding
    Here is an quick example of early binding
    to AutoCAD application almost not tested
    You can see more about late binding on
    http://www.excelguru.ca/node/10
    and use the same method for AuitoCAD
    Make sure that in Acces is set reference
    to your current AutoCAD version
    Add this code in Access module
    Hope this will be works in A2008 also

    ~'J'~

    Code:
    Option Compare Text
    Option Explicit
    Public fullName As String
    
    '//==================//'
    Public Sub TitleToAccess()
    
    Dim acApp As AcadApplication
    Dim aDoc As AcadDocument
    Dim oEnt As AcadEntity
    Dim blkTitle As AcadBlockReference
    Dim oAttRef As AcadAttributeReference
    Dim bnameStr As String
    Dim aryAttributes As Variant
    Dim ftype(0) As Integer
    Dim fdata(0) As Variant
    Dim fcode As Variant
    Dim fvalue As Variant
    Dim i As Integer, j As Integer
    Dim info() As String
    MsgBox "Be patience...AutoCAD will be" & vbCr & _
            "closed automatically"
    fullName = "C:\MyAccess\MyBlocks.dwg" '<-- change the drawing name here
    Set acApp = CreateObject("AutoCAD.Application")
    Set aDoc = acApp.Documents.Open(fullName)
    acApp.Visible = True
    
        For Each oEnt In aDoc.ModelSpace
            If TypeOf oEnt Is AcadBlockReference Then
            Set blkTitle = oEnt
                If blkTitle.Name = "TITLE" And blkTitle.HasAttributes Then
                            aryAttributes = blkTitle.GetAttributes
                            For i = LBound(aryAttributes) To UBound(aryAttributes)
                            Set oAttRef = aryAttributes(i)
                            ReDim Preserve info(j)
                            info(j) = "Tag: " & oAttRef.TagString & vbCr & "Value: " & oAttRef.TextString
                            j = j + 1
                            Next i
                        End If
                    End If
        Next oEnt
        
    aDoc.Close 'close w/o changes
    acApp.Quit
    
    Set aDoc = Nothing
    Set acApp = Nothing
    For i = LBound(info) To UBound(info)
    MsgBox info(i)
    Next
    
    End Sub

  3. #3
    Forum Newbie
    Using
    AutoCAD 2008
    Join Date
    Jun 2007
    Posts
    2

    Default

    HAHA! It Worked. THANKS A BUNCH

  4. #4
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Thanks God, I'm far enough from Hitleropa
    Posts
    1,697

    Default

    Quote Originally Posted by AKing View Post
    HAHA! It Worked. THANKS A BUNCH
    Glad if that helps

    ~'J'~

  5. #5
    Forum Newbie
    Using
    AutoCAD 2008
    Join Date
    Mar 2012
    Posts
    4

    Default

    Can you help me with this code to write data from access form to autocad block attributes. Sorry but i have no programing skills.

  6. #6
    Super Member irneb's Avatar
    Computer Details
    irneb's Computer Details
    Operating System:
    Win7 Pro 64bit
    Computer:
    Antec One Hundred
    Motherboard:
    ASUS P8P67-Pro P67
    CPU:
    Intel i7 2600 @ 3.4GHz
    RAM:
    16GB-1600MHz
    Graphics:
    GeForce GT 430 (1GB)
    Primary Storage:
    Seagate1TB SATA2 - 7200rpm
    Monitor:
    Samsung 2333TN 23" 1920 x 1080 Full HD LCD Monitor2GW
    Discipline
    Architectural
    irneb's Discipline Details
    Occupation
    Architectural Technician and Programmer
    Discipline
    Architectural
    Using
    AutoCAD 2013
    Join Date
    Sep 2010
    Location
    Jo'burg SA
    Posts
    1,739

    Default

    Welcome to CT. Firstly, we need to know a few stuff: Which version of Access (some newer versions don't come standard with VBA as per below, so it might need to be translated to VB.Net)? Are you sure you want to do it from the Access side, or would you be willing to have AutoCAD drive the data inside the MDB file (this is a lot simpler to do and might even work faster)?

    Will both ACad and Access always be on the same PC? Do you want to modify DWG files without ACad? Or do you want to modify data inside MDB without Access?
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  7. #7
    Forum Newbie
    Using
    AutoCAD 2008
    Join Date
    Mar 2012
    Posts
    4

    Default

    I am using autocad 2008 and access 2007, they will always be on on the same pc , i do not intend to modify, if it's easier i wold prefer to brig data from one access form to dwg custom properties or SSM properties then link that data via fields used in title block.
    I found a code that works in access and sends data to a word template....http://www.techrepublic.com/blog/mso...ccess-data/164......i want to send data to autocad fields or block attributes.

  8. #8
    Forum Newbie
    Using
    AutoCAD 2008
    Join Date
    Mar 2012
    Posts
    4

    Default

    i am using autocad 2008 and access 2007...i am using them on same computer...

  9. #9
    Forum Newbie
    Using
    AutoCAD 2008
    Join Date
    Mar 2012
    Posts
    4

    Default

    i dont intend to modify data without these softwares.....sorry for my english. I want to bring data from one access form to autocad block attributes or dwg's custom properties or ssm properties.

  10. #10
    Super Member irneb's Avatar
    Computer Details
    irneb's Computer Details
    Operating System:
    Win7 Pro 64bit
    Computer:
    Antec One Hundred
    Motherboard:
    ASUS P8P67-Pro P67
    CPU:
    Intel i7 2600 @ 3.4GHz
    RAM:
    16GB-1600MHz
    Graphics:
    GeForce GT 430 (1GB)
    Primary Storage:
    Seagate1TB SATA2 - 7200rpm
    Monitor:
    Samsung 2333TN 23" 1920 x 1080 Full HD LCD Monitor2GW
    Discipline
    Architectural
    irneb's Discipline Details
    Occupation
    Architectural Technician and Programmer
    Discipline
    Architectural
    Using
    AutoCAD 2013
    Join Date
    Sep 2010
    Location
    Jo'burg SA
    Posts
    1,739

    Default

    Registered forum members do not see this ad.

    Not too sure that Access 2007 has VBA, I know I had huge issues with getting a VBA tool I wrote for Outlook 2003 to run in 2007, even after installing MSO's VBA addon-pack.

    I've not done any programming in DotNet for Access, so I'm not too clued up about that. I have done something similar to the OP's stuff in Access 2003 (though I have to tell you it ran sloooooowwwwwwlyyyy). I ended up rather doing it from AutoCAD using ADOLisp to link to the MDB file - worked 10's of times faster. There are quite a few threads about linking to databases using Lisp, ADOLisp's actually got sample code for linking to MDB files, though it can link to any DB which can be connected to through ADO/ODBC.

    You might want to look at this thread: http://www.theswamp.org/index.php?topic=42014.0
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

Similar Threads

  1. Access Denied
    By Brunello19 in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 13th Feb 2007, 09:43 pm
  2. Looking for AutoCAD tutor in Seattle or remote access
    By iCANDi in forum AutoCAD Beginners' Area
    Replies: 14
    Last Post: 24th Jan 2007, 06:36 am
  3. how do I view an AutoCAD drawing in Microsoft Access?
    By tusopeta in forum AutoCAD General
    Replies: 1
    Last Post: 4th Apr 2006, 02:46 pm
  4. =>Access Free CAD Projects
    By CAD Ground in forum AutoCAD Drawing Management & Output
    Replies: 12
    Last Post: 4th Apr 2005, 10:25 pm
  5. Access 'render' command from VBA
    By Socrates in forum AutoCAD 3D Modelling & Rendering
    Replies: 0
    Last Post: 14th Oct 2002, 02:20 am

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts