Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: VBA fields and tables

  1. #1
    AUGI Addict MikeJarosz's Avatar
    Join Date
    2015-10
    Location
    New York NY
    Posts
    1,497
    Login to Give a bone
    0

    Default VBA fields and tables

    I have made a template sheet with an Acad table in paperspace. I want to populate the table with data from an Excel worksheet. All the documentation I've found about tables only show how to set an object variable by using the add method. What if the table is already created? How can I grab it? Code looks something like this:


    dim DwgTable as AcadTable
    set DwgTable = ???????

    From here I should be able to iterate through the rows and columns, setting the values.

  2. #2
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: VBA fields and tables

    See in Help AddTable & SetText methods

    ~'J'~

  3. #3
    AUGI Addict MikeJarosz's Avatar
    Join Date
    2015-10
    Location
    New York NY
    Posts
    1,497
    Login to Give a bone
    0

    Default Re: VBA fields and tables

    I found a way, maybe not the best but it works:


    Code:
     
    dim entity as object
    dim DwgIndex as AcadTable
    For Each entity In ThisDrawing.PaperSpace
    	If entity.EntityName = "AcDbTable" Then
    		Set DwgIndex = entity
    		Exit For
    	End If
    Next entity
    Unfortunately, it is ridiculously slow to populate the table. The documentation says the table is recalculated every time a value is changed, but there is a property:

    DwgIndex.RegenerateTableSuppressed = true/false

    However, to use it requires I use IAcadPaperSpace2 and IAcadTable2. These are new to me, and when I dim my objects with these values, other methods that work with plain paperspace and acadtable cause errors. I suspect I'm mixing VBA code with ObjectDbx.

    Anyone figured this out?

  4. #4
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: VBA fields and tables

    Here is not exactly what you want
    but maybe this will be lead you in
    right direction
    This was written to own needs as a flat table
    w/o title and headings
    Feel free to change it to you suit

    ~'J'~
    Attached Files Attached Files

  5. #5
    AUGI Addict MikeJarosz's Avatar
    Join Date
    2015-10
    Location
    New York NY
    Posts
    1,497
    Login to Give a bone
    0

    Default Re: VBA fields and tables

    I looked at your code and saw you used object.recomputetableblock false. I tried it and it didn't help much.

    Also, object.regeneratetablesuppressed = true, is apparently introduced with 2006. I am on 2005. Can anyone confirm this?

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

    Default Re: VBA fields and tables

    Quote Originally Posted by MikeJarosz
    I found a way, maybe not the best but it works:
    Is this all the code you have so far? Have you tried prompting the user to select the table? What if there is more than one table in the dwg? When your code finishes, only the last table found will be referenced.
    Last edited by Ed Jobe; 2006-11-15 at 11:31 PM.
    C:> ED WORKING....

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

    Default Re: VBA fields and tables

    Quote Originally Posted by MikeJarosz
    I looked at your code and saw you used object.recomputetableblock false. I tried it and it didn't help much.

    Also, object.regeneratetablesuppressed = true, is apparently introduced with 2006. I am on 2005. Can anyone confirm this?
    I don't have 6, just 5 and 7. 5 doesn't have it 7 does. Also, 7 includes this method in the AcadTable object and not a separate interface, as does 6. Also, you mentioned you got errors in your second post. If the type library you are referencing, i.e. 2005, doesn't have the object, dimensioning a variable to a non-existent object will create a compile error.
    C:> ED WORKING....

  8. #8
    AUGI Addict MikeJarosz's Avatar
    Join Date
    2015-10
    Location
    New York NY
    Posts
    1,497
    Login to Give a bone
    0

    Default Re: VBA fields and tables

    Quote Originally Posted by Ed Jobe
    Is this all the code you have so far? Have you tried prompting the user to select the table? What if there is more than one table in the dwg? When your code finishes, only the last table found will be referenced.
    I understand your question. The code snip I posted indeed exits after finding the first table. But I control the dwt file and there is only one table on it. I am exploring this approach because executing the table out of thin air was so painfully slow I know I could never sell it to my users. The template approach is only marginally faster in 2005, so now I am now going to try a cut and paste via the clipboard, then pro grammatically altering the table style to suit.

    FYI, this is my complete test program. I populate the test table by adding arbitrary text in a loop. It works. s l o w l y. Notice the timer. The annoying thing here is that I have discovered ObjectDBX, and the code to grab 600 drawings executes in 50 seconds! Then I have to dump it into the table slowpoke.

    Code:
     Sub PopulateTable() 
    Dim Start As Long
    Start = Timer
    Dim Finish As Long
    Dim Pspace As IAcadPaperSpace2
    Dim DwgIndex As AcadTable
    Dim i As Long
    Dim j As Long
    Dim entity As Object
    Set Pspace = ThisDrawing.PaperSpace
    For Each entity In ThisDrawing.PaperSpace
    	If entity.EntityName = "AcDbTable" Then
    		Debug.Print entity.EntityName
    		Set DwgIndex = entity
    		Exit For
    	End If
    Next entity
    DwgIndex.RecomputeTableBlock False
    'DwgIndex.RegenerateTableSuppressed = True
    ThisDrawing.StartUndoMark
    'note that table rows & cols are zero based
    With DwgIndex
    	j = 0
    	For i = 0 To 84
    		.SetText i, j, Str(i)
    		.SetText i, j + 1, "XXXXXXXXXXXXXXXX"
    	Next i
    End With
    ThisDrawing.EndUndoMark
    DwgIndex.RecomputeTableBlock True
    'DwgIndex.RegenerateTableSuppressed = False
    Set DwgIndex = Nothing
    Finish = Timer
    Debug.Print "DONE: " & (Finish - Start)
    End Sub
    The regeneratetablesuppressed doesn't work. See above.

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

    Default Re: VBA fields and tables

    It looks like your sub is taking so long just because it has 84 rows. Here's a snippet from the 2007 help.
    Recomputing large tables consumes a lot of time and memory because the Table object is reconstructed from scratch.
    Now you know why they added the RegenerateTableSuppressed property.

    I ran it in 2005 and 2007. Both took 15-16 seconds. I reduced the row count to 10 and it took 3 seconds. I added the property changes for RegenerateTableSuppressed and it took less than 1 second. With 84 rows, I don't think there's much you can do until you get 2007. I made some other changes too.

    Code:
    Sub PopulateTable()
    Dim Start As Long
    Start = Timer
    Dim Finish As Long
    Dim Pspace As AcadPaperSpace
    Dim DwgIndex As AcadTable
    Dim i As Long
    Dim j As Long
    Dim entity As AcadEntity
    Set Pspace = ThisDrawing.PaperSpace
    For Each entity In ThisDrawing.PaperSpace
        If TypeOf entity Is AcadTable Then
            Debug.Print entity.EntityName
            Set DwgIndex = entity
            Exit For
        End If
    Next entity
    DwgIndex.RegenerateTableSuppressed = True
    ThisDrawing.StartUndoMark
    'note that table rows & cols are zero based
    With DwgIndex
        j = 0
        For i = 0 To 10
            .SetText i, j, str(i)
            .SetText i, j + 1, "XXXXXXXXXXXXXXXX"
            DwgIndex.RecomputeTableBlock False
        Next i
    End With
    ThisDrawing.EndUndoMark
    DwgIndex.RegenerateTableSuppressed = False
    Set DwgIndex = Nothing
    Finish = Timer
    Debug.Print "DONE: " & (Finish - Start)
    End Sub
    C:> ED WORKING....

  10. #10
    AUGI Addict MikeJarosz's Avatar
    Join Date
    2015-10
    Location
    New York NY
    Posts
    1,497
    Login to Give a bone
    0

    Default Re: VBA fields and tables

    I am developing this program for use on very large projects with drawing sets between 500 - 1000 sheets, not counting engineering. The project at hand is a 400 meter tower and has nearly 600 architectural sheets. I have divided the sheet into five vertical columns of 85 rows each. That is where the 85 comes from. There will be about 515 more!!! That's why I'm concerned about speed.

    I tried your enhancements. The early binding improvements did shave 3 seconds of my 85 line sample. The regeneratetablesupressed caused an "object doesn't support this property or method" error. So I guess you're right: wait for 2007.

    I need to finish the i & j loops to fill out the other 4 columns. Ouch!!!!...........

Page 1 of 2 12 LastLast

Similar Threads

  1. Help with Tables, Excell and Fields.
    By ed.pryce874985 in forum AutoCAD General
    Replies: 2
    Last Post: 2012-05-01, 02:56 PM
  2. Fields within Tables
    By roundbox52 in forum ACA General
    Replies: 0
    Last Post: 2009-11-04, 03:53 PM
  3. Tables Fields & the SSM
    By KGC in forum AutoCAD Tables
    Replies: 22
    Last Post: 2007-08-24, 02:07 PM
  4. Linking Fields between tables
    By cadmancando in forum AutoCAD Fields
    Replies: 3
    Last Post: 2007-05-09, 08:22 PM

Posting Permissions

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