AcadTableStyle

I confess to not fully understanding dictionaries in autocad VBA. They seem like a storage closet. A storage closet has no rules. Items in the dictionaries collection are not necessarily dictionaries. Dictionary objects do not always have names or pass all the tests for dictionary objects. Its not likely we have much reason to iterate through the dictionaries collection except for curiosity, mostly just need to reach in and get what we know is there. The dictionaries collection is a collection of dictionaries. Here is some orientation code to get the idea what is in the upper level dictionaries collection. This will print to the immediate window for information only.


Sub Listdictionary()
'very important statement
On Error Resume Next

Call connect_acad
Dim i As Integer, intcount As Integer
Dim acadobj As AcadObject
Dim dicts As AcadDictionaries
Dim dict As AcadDictionary
Set dicts = acadDoc.Database.dictionaries

For Each acadobj In dicts
    'everything in dicts is an acadobject
    Debug.Print acadobj.ObjectName
    'not everything has a name property
    Debug.Print acadobj.Name
    Debug.Print " "
Next acadobj

Debug.Print " "
'from this point no errors generated
On Error GoTo 0

For Each acadobj In dicts
    If TypeOf acadobj Is AcadDictionary Then
    Debug.Print acadobj.Name
    End If
Next acadobj

Debug.Print " "
'alternate loop method, same results
intcount = dicts.Count
For i = 0 To intcount - 1
Set acadobj = dicts.Item(i)
If TypeOf acadobj Is AcadDictionary Then
    Debug.Print acadobj.Name
    End If
Next i
Debug.Print " "

On Error Resume Next
'this does not work, generates error
'inexplicably only retrieves 2 dicts
For Each dict In dicts
    Debug.Print dict.ObjectName
    Debug.Print dict.Name
    Debug.Print " "
Next dict

End Sub

For instance the code above returns in an empty drawing (excising the duplicate results) –

AcDbXrecord
ACAD_CIP_PREVIOUS_PRODUCT_INFO

AcDbDictionary
ACAD_COLOR

AcDbDictionary
ACAD_DETAILVIEWSTYLE

AcDbDictionary

AcDbDictionary

AcDbDictionary

AcDbDictionary
ACAD_MLEADERSTYLE

AcDbDictionary
ACAD_MLINESTYLE

AcDbDictionary

AcDbDictionaryWithDefault
ACAD_PLOTSTYLENAME

AcDbRapidRTRenderSettings

AcDbDictionary
ACAD_RENDER_RAPIDRT_SETTINGS

AcDbDictionary
ACAD_SCALELIST

AcDbDictionary
ACAD_SECTIONVIEWSTYLE

AcDbDictionary
ACAD_TABLESTYLE

AcDbDictionary
ACAD_VISUALSTYLE

AcDbDictionary
AcDbVariableDictionary

ACAD_COLOR
ACAD_DETAILVIEWSTYLE
ACAD_MLEADERSTYLE
ACAD_MLINESTYLE
ACAD_PLOTSTYLENAME
ACAD_RENDER_RAPIDRT_SETTINGS
ACAD_SCALELIST
ACAD_SECTIONVIEWSTYLE
ACAD_TABLESTYLE
ACAD_VISUALSTYLE
AcDbVariableDictionary

The Dictionaries collection retrieved as a property of the document is composed of named dictionary items. The one we want is called “ACAD_TABLESTYLE”. This is a single dictionary but it is itself a collection. It contains instances of a class called “AcadTableStyle”. The only such named instance in a blank drawing is called “Standard”. We are going to add a new one to work on.


Sub make_tb_styl_1()
    
    Dim dictionaries As AcadDictionaries
    Set dictionaries = acadDoc.Database.dictionaries
  
    Dim dictObj As AcadDictionary
    Set dictObj = dictionaries.Item("acad_tablestyle")
  
    ' Create the custom TableStyle object in the dictionary
    Dim keyName As String
    Dim className As String
    Dim customObj As AcadTableStyle
    keyName = "Tb_Styl_1"
    className = "AcDbTableStyle"
    Set customObj = dictObj.AddObject(keyName, className)
       
    customObj.Name = "Tb_Styl_1"

now we have an object in the drawing of type AcadTableStyle with name “Tb_Styl_1” set to a VBA object named customobj and we can set its properties as we wish.

the autocad activex (VBA) help reference for AcadTableStyle
there are about 60 AcadTableStyle methods and 17 properties. Some of these have sample code. There is a compiled HTML file of the same information in
Program Files\Common Files\Autodesk Shared\acadauto.chm

The table object activex help
has more than 200 methods and properties.

The third component of linking tables with excel is the datalink object. However i do not see any activex reference. I believe that is beyond routine access. datalinks are very cool, i use them every day at work, though they tend to crash the drawing if you re-use them, their links get broken, there are more than one in a drawing, and you try to delete them. A lot of conditions but they do occur if nearly every drawing has a datalink. The advanatage – data is live, when it is changed in excel the acad table reflects it – make it worthwhile to carefully handle them. For our table application, we will write a program that makes a table of user selected excel data and formats it to user satisfaction. It wont be linked, but we will make the table creation so that it is easily remade. That has its own advantages of lightweight simplicity.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s