Wednesday, July 11, 2007

ObjectDBX sample using VBA and AutoCAD 2008

This VBA sample shows how to use ObjectDBX to get information from multiple drawings without opening them. You need to have an AutoCAD based application installed though. Here block names are listed but other things can be done with ObjectDBX like making changes to the drawings in different ways. ObjectDBX can also be used with AutoLISP, VB, VB.NET or C#.

Option Explicit Dim objDbx As AxDbDocument ' 2007-06-08 ' By Jimmy Bergmark ' Copyright (C) 2007 JTB World, All Rights Reserved ' Website: ' E-mail: ' Runs in AutoCAD 2008 with axdb17enu.tlb (must be referenced) AutoCAD/ObjectDBX Common 17.0 Type Library ' Example of batch for listing all block names on all drawings in a directory. Private Sub ListBlockNames() Set objDbx = GetInterfaceObject("ObjectDBX.AxDbDocument.17") Dim inDir As String Dim elem As Object Dim filenom As String Dim WholeFile As String Dim newHeight As Double inDir = "c:\program files\autocad 2008\sample" filenom = Dir$(inDir & "\*.dwg") Do While filenom <> "" ThisDrawing.Utility.Prompt vbCrLf & "File: " & filenom ThisDrawing.Utility.Prompt vbCrLf & "-----------------" WholeFile = inDir & "\" & filenom objDbx.Open WholeFile For Each elem In objDbx.Blocks If elem.IsXRef = False And Left(elem.Name, 1) <> "*" Then ThisDrawing.Utility.Prompt vbCrLf & elem.Name End If Next Set elem = Nothing filenom = Dir$ ThisDrawing.Utility.Prompt vbCrLf Loop Set objDbx = Nothing End Sub

If you read this using Google reader see the code here.

If you want to manipulate DWG files without having an Autodesk application installed there is the option to use RealDWG.


  1. Could you give an example on
    how to run a vba sub or a lisp
    routine while a dwg document is open with ObjectDBX?

    Is it by using 'sendcommand'?

  2. I'm not sure I understand your question. The sample in the post shows this with VBA unless I'm missing something.

  3. The question is simple.
    While a dwg is open via objectdbx,
    can a lisp or a vba routine be run
    on the dwg that was opened via objectdbx?

  4. I don't think so but I have not tried or confirmed it in any way.

  5. Jim_In_OregonNovember 17, 2010

    Trying to do something similiar (extract some attribute values) and have the VBA working fine but am now try to port to a console out-of-process app. and am having difficulties getting the resources working correctly...

    Dim objDbx As AxDbDocument ' Autodesk.AutoCAD.Interop.Common.AxDbDocument does not work either...
    objDbx = GetInterfaceObject("ObjectDBX.AxDbDocument.18") ' Not declaired???
    Dim inDir As String, elem As Object, filenom As String, WholeFile As String, newHeight As Double
    Dim objFnd As AcadEntity, indx As Integer ' Not defined???

    Autocad 2010 Type Lib. | Acad/ ObjectDBX Common 18.0 Common Type Lib. | Acad.Interop and Interop.Common| OLE Automation | AcMgd and AcdbMgd

    Any ideas?


Some of the latest blog posts

Subscribe to RSS headline updates from:
Powered by FeedBurner

Contact Us | About JTB World | Subscribe to this blog
JTB World's website | Website General Terms of Use | Privacy Policy
^ Top of page

© 2004- JTB World. All rights reserved.