Page 3 of 6 FirstFirst 123456 LastLast
Results 21 to 30 of 54

Thread: VBA and ObjectDbx - AutoCAD to Excel Attribute Extraction Tool

  1. #21
    Member
    Join Date
    2009-04
    Posts
    9
    Login to Give a bone
    0

    Default Re: VBA and ObjectDbx - AutoCAD to Excel Attribute Extraction Tool

    Wow... the only thing I get when I search this forum for acadblockref is this thread... lol... gues it's time to google it.

  2. #22
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,396
    Login to Give a bone
    0

    Default Re: VBA and ObjectDbx - AutoCAD to Excel Attribute Extraction Tool

    Try using "BlockRef"
    C:> ED WORKING....

  3. #23
    Member
    Join Date
    2009-04
    Posts
    9
    Login to Give a bone
    0

    Default Re: VBA and ObjectDbx - AutoCAD to Excel Attribute Extraction Tool

    Ok... I think I'm getting a little closer... I hope... but it's not returning anything. When I step through the code, it never goes inside the loop that says:

    If TypeOf objEnt is AutoCAD.AcadBlockReference Then.....

    I also tried:

    If TypeName(objEnt) = "IAcadBlockReference" Then...

    And:

    If TypeName(objEnt) = "AcDbBlockReference" Then...


    Code:
                Dim strBlkName As String
                Dim strAttTag As String
                Dim objEnt As AutoCAD.AcadEntity
                Dim objBlkRef As AutoCAD.AcadBlockReference
                Dim varAtts As Object
                Dim objAtt As AutoCAD.AcadAttributeReference
                Dim objLayout As AutoCAD.AcadLayout
                Dim objBlock As AutoCAD.AcadBlock
                Dim I As Long
     
                strBlkName = "START"
                strAttTag = "FILENAME"
                For Each objLayout In V_AutoCad.ActiveDocument.Layouts
                    If UCase(objLayout.Name) <> "MODEL" Then
                        objBlock = objLayout.Block
                        For Each objEnt In objBlock
                            If TypeOf objEnt Is AutoCAD.AcadBlockReference Then
                               
                                objBlkRef = objEnt
                                If objBlkRef.Name = strBlkName Then
                                    varAtts = objBlkRef.GetAttributes
                                    For I = 0 To UBound(varAtts)
                                        objAtt = (varAtts(I))
                                        If objAtt.TagString = strAttTag Then
                                            MsgBox(objAtt.TextString)
                                        End If
                                    Next I
                                End If
                            End If
                        Next
                    End If
                Next
    Last edited by Ed Jobe; 2009-04-10 at 02:07 PM.

  4. #24
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,396
    Login to Give a bone
    0

    Default Re: VBA and ObjectDbx - AutoCAD to Excel Attribute Extraction Tool

    The Block property returns a BlockRef, which is not a collection, but a Block definition. It has an Item method you use to access ents. Try this, put your cursor on the Block method of the layout object and hit F1. Then find the item method, and look at its code example.
    C:> ED WORKING....

  5. #25
    Member
    Join Date
    2009-04
    Posts
    9
    Login to Give a bone
    0

    Default Re: VBA and ObjectDbx - AutoCAD to Excel Attribute Extraction Tool

    I'm not doing VBA... I'm in Visual Studio... so the F1 trick doesn't work. I searched the help file, and I found the item method.. I think.. It's making a collection of the objects, and then getting out layer "0"

    I'm not sure how to apply this to reading out block attributes though... I know... I'm hopeless... I really am trying to understand it though.

    Am I even heading down the right path for what I'm trying to do?? I need to look through the drawing, find several blocks by name... and in those blocks I need to read stardard information (x insertion point, x scale, etc...) as well as custom information (Sheet Number, Customer, etc..). Is what I'm trying to do even the way to do that??

  6. #26
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,396
    Login to Give a bone
    0

    Default Re: VBA and ObjectDbx - AutoCAD to Excel Attribute Extraction Tool

    Yes, you're on the right path, although you could use the .Net lib as well. Anyway, you can find the help on the ActiveX object model in acad_dev.chm in the acad Help folder or in 2008+ there's a link in Help>Additional Resources. Here's the code sample.
    Code:
    Sub Example_Item()
        ' This example shows two uses of the Item method.
        ' The first uses Item with an index counter to return an item in a collection.
        ' The second uses Item with a string to return an item in a collection.
        
        ' Iterate thru the model space collection,
        ' get all the items in the collection
        ' and store them in an array called newObjs
        Dim count As Integer
        count = ThisDrawing.ModelSpace.count
        
        ReDim newObjs(count) As AcadEntity
        Dim index As Integer
        For index = 0 To count - 1
            Set newObjs(index) = ThisDrawing.ModelSpace.Item(index)
        Next
        
        ' Get a particular item, in this case a layer, based on name "0"
        Dim layerObj As AcadLayer
        Set layerObj = ThisDrawing.Layers.Item("0")
        
    End Sub
    C:> ED WORKING....

  7. #27
    Member
    Join Date
    2009-04
    Posts
    9
    Login to Give a bone
    0

    Default Re: VBA and ObjectDbx - AutoCAD to Excel Attribute Extraction Tool

    Ok... I've finally made some progress... to a point... When I use the code below... it works just like I want it to.. but only if I actually open the drawing in AutoCAD... so apparently something is wrong with how I'm connecting to the objectdbx... or this method just does not work with it or something... so here's my code for the objectdbx as well as my code for getting the blocks.

    Code:
     V_AutoCad = StartAutoCAD() 'Use the function located in PublicFunctions.vb to initialize AutoCAD
    
            Dim V_AutoCadInterfaceObject As AxDbDocument
            V_AutoCadInterfaceObject = V_AutoCad.GetInterfaceObject("ObjectDBX.AxDbDocument")
    
    V_AutoCadInterfaceObject.Open(V_FilePathAutoCad)
    
    ' ********************************************************************
        Public Function StartAutoCAD() As Object
    
            On Error Resume Next
    
            V_AutoCad = GetObject(, "AutoCad.Application.15")
            If Err.Number <> 0 Then 'If they don't have AutoCAD open.. then open it
                Err.Clear()
                Shell("C:\Program Files\Acad2002\acad.exe", AppWinStyle.NormalFocus)
                System.Threading.Thread.Sleep(3000)
                ' Create a new session of AutoCAD using late binding
                V_AutoCad = GetObject(, "AutoCad.Application.15")
            End If
            Return V_AutoCad
    
        End Function
    
    ' ********************************************************************
    Code for getting the block info:
    
                Dim strBlkName As String
                Dim strAttTag As String
                Dim objEnt As AutoCAD.AcadEntity
                Dim objBlkRef As AutoCAD.AcadBlockReference
                Dim varAtts As Object
                Dim objAtt As AutoCAD.AcadAttributeReference
                Dim I As Long
    
                strBlkName = "START"
                strAttTag = "FILENAME"
                For Each objEnt In V_AutoCad.ActiveDocument.ModelSpace
    
                    If objEnt.ObjectName.ToString = "AcDbBlockReference" Then
    
                        objBlkRef = objEnt
    
                        If objBlkRef.Name = strBlkName Then
                            varAtts = objBlkRef.GetAttributes
                            For I = 0 To UBound(varAtts)
                                objAtt = (varAtts(I))
                                If objAtt.TagString = strAttTag Then
                                    MsgBox(objAtt.TextString)
                                End If
                            Next I
                        End If
                    End If
    
                Next
            Next
    Last edited by Ed Jobe; 2009-04-12 at 11:11 PM.

  8. #28
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,396
    Login to Give a bone
    0

    Default Re: VBA and ObjectDbx - AutoCAD to Excel Attribute Extraction Tool

    I'm a little short on time today. Search this forum for "ObjectDbx" or "oDbx.cls". Also, your StartAutocad sub has an error. The err section should be a call to CreateObject, not GetObject.
    C:> ED WORKING....

  9. #29
    Member
    Join Date
    2009-04
    Posts
    9
    Login to Give a bone
    0

    Default Re: VBA and ObjectDbx - AutoCAD to Excel Attribute Extraction Tool

    Ok... I'll see what I can find searching for those.

    I changed that to CreateObject, I don't think that's causing my problem since I've been running this with AutoCAD aready open, so it's not going into that section of code... or shouldn't be anyway.

    Thank-you again for helping me figure this out.

  10. #30
    Member
    Join Date
    2007-04
    Posts
    2
    Login to Give a bone
    0

    Default Re: VBA and ObjectDbx - AutoCAD to Excel Attribute Extraction Tool

    Quote Originally Posted by katrinanjim View Post
    I have created a visual basic program in microsoft Excel using ObjectDbx that will currently do the following:
    - Generate a list of AutoCAD dwgs in the current directory (where excel file is saved) and display the list in Excel
    - Search the drawings in the list for a specified block and display the attributes of the block in Excel
    - You can then change the attributes shown in Excel and send them back to the listed AutoCAD dwgs
    - Search the drawings in the list and display all external references in Excel

    This program works fine with the following exceptions:
    Issue #1: When attributes are updated with this program, they will appear left justified until the block is refreshed (known issue)
    Issue #2: The program will only find a single instance of the specified block in each drawing. This issue occurs if you have multiple Paperspace tabs with the specified block inserted in each tab.

    QUESTIONS:
    Has anyone out there been able to resolve Issue #2 using ObjectDbx?
    or
    Will I need to go through the AutoCAD interface and generate selection sets somehow?

    ATTACHMENT:
    I attached my Excel file to this posting for reference. It is a very useful tool given the above issues. I am sure that it could have been a little cleaner but at least I have some commenting. Feel free to post questions or comments regarding the program and I will do my best to answer them.

    Notes:
    - In Excel VBA, need to reference: Microsoft Scripting Runtime, AutoCAD 2008 type Library, AutoCAD/ObjectDbx Common 17.0 Type Library
    - Compatibility: AutoCAD 2008, Excel 2003+
    Hi, I use this tool a lot and it's very effecient but recently I upgraded to AutoCAD2010 and its now not working. Do you have a version of this tool to work on AutoCAD 2010 or any idea on how to tweak it to work on the 2010? much appreciated.

Page 3 of 6 FirstFirst 123456 LastLast

Similar Threads

  1. CP214-3: All Things Extraction: From AutoCAD to Databases, Excel, and XML Using .NET
    By Autodesk University in forum Customization and Programming
    Replies: 0
    Last Post: 2014-12-01, 02:08 AM
  2. Help needed with Attribute extraction and import into MS Excel
    By Lee Buckmaster in forum Productstream - General
    Replies: 0
    Last Post: 2012-04-30, 08:23 PM
  3. Attribute extraction to Word or Excel
    By KristiS in forum CAD Management - General
    Replies: 6
    Last Post: 2009-01-06, 09:16 PM
  4. attribute extraction to excel
    By jbortoli in forum VBA/COM Interop
    Replies: 5
    Last Post: 2008-02-07, 01:58 PM
  5. Block attribute extraction to an AutoCAD Table
    By DFlynn in forum AutoCAD Tables
    Replies: 2
    Last Post: 2006-02-13, 01:41 AM

Posting Permissions

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