ObjectDBX.AxDbDocument.17

ObjectDBX.AxDbDocument.17

Anonymous
Not applicable
5,131 Views
8 Replies
Message 1 of 9

ObjectDBX.AxDbDocument.17

Anonymous
Not applicable
Hi all,

I have seen posts on here relating to loading the ObjectDBX libraries. I
have tried similar for "AutoCAD/ObjectDBX Common 17.0 Type Library", but am
having no luck. The ones I have seen are similar to this

Dim DbxDoc As AXDB16Lib.AxDbDocument
Set DbxDoc = GetInterfaceObject("ObjectDBX.AxDbDocument.16")

however, when I replace the 16 with 17

Dim DbxDoc As AxDbDocument
Set DbxDoc = GetInterfaceObject_("ObjectDBX.AxDbDocument.17")

it does not work and returns an error "User-defined type not defined"

Can anybody point me in the right direction?

Thanks in advance

Brent
0 Likes
5,132 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable
Hi Brent,

I think you either have to use a separate program version for each dbx
version (if you need to use early binding), or use late binding. I got
close to tricking it in the thread
http://discussion.autodesk.com/thread.jspa?messageID=5167190 but ended up
just using late binding as follows:

[code]
Dim DbxDoc As Object
Dim Version As String

Version = Mid(ThisDrawing.GetVariable("acadver"), 1, 2)
If CInt(Version) < 16 Then
Set GetDbxDoc =
AcadApplication.GetInterfaceObject("ObjectDBX.AxDbDocument")
Else
Set GetDbxDoc =
AcadApplication.GetInterfaceObject("ObjectDBX.AxDbDocument." & Version)
End If
[/code]

--
James Allen
Malicoat-Winslow Engineers, P.C.
Columbia, MO


wrote in message news:5451344@discussion.autodesk.com...
Hi all,

I have seen posts on here relating to loading the ObjectDBX libraries. I
have tried similar for "AutoCAD/ObjectDBX Common 17.0 Type Library", but am
having no luck. The ones I have seen are similar to this

Dim DbxDoc As AXDB16Lib.AxDbDocument
Set DbxDoc = GetInterfaceObject("ObjectDBX.AxDbDocument.16")

however, when I replace the 16 with 17

Dim DbxDoc As AxDbDocument
Set DbxDoc = GetInterfaceObject_("ObjectDBX.AxDbDocument.17")

it does not work and returns an error "User-defined type not defined"

Can anybody point me in the right direction?

Thanks in advance

Brent
0 Likes
Message 3 of 9

Anonymous
Not applicable
You must add the reference to "AutoCAD/ObjectDBX Common 17.0 Type Library"
under Tools/References

Then this works

Dim DbxDoc As AxDbDocument
Set DbxDoc = GetInterfaceObject_("ObjectDBX.AxDbDocument.17")

wrote in message news:5451344@discussion.autodesk.com...
Hi all,

I have seen posts on here relating to loading the ObjectDBX libraries. I
have tried similar for "AutoCAD/ObjectDBX Common 17.0 Type Library", but am
having no luck. The ones I have seen are similar to this
0 Likes
Message 4 of 9

Anonymous
Not applicable
Not any more. Version 22.0 doesn’t work with getinterfaceobject.
0 Likes
Message 5 of 9

norman.yuan
Mentor
Mentor

Judging from you discussion appended to the other lengthy thread, I am not sure why you jumped to yet another very old discussion thread and claim ObjectDBX "not work any more" with AutoCAD2018 (ObjectDBX.AxdbDocument.22).

 

The fact is that it still works with AutoCAD 2018 and works well with AutoCAD VBA, or from external application that automates AutoCAD via COM API (because I saw your code from the other thread, and it seemed you are automating AutoCAD from other application, maybe Excel's VBA?).

 

Here is the code that runs good as expected in AutoCAD2018's VBA:

 

Option Explicit

Public Sub DbxTest()

    Dim doc As AXDBLib.AxDbDocument
    Dim ent As AcadEntity
    Dim count As Integer
    
    Set doc = Application.GetInterfaceObject("ObjectDBX.AxDbDocument.22")
    
    doc.Open "C:\Temp\Test.dwt"
    For Each ent In doc.ModelSpace
        count = count + 1
    Next
    
    MsgBox "Entities in modelspace: " & count

End Sub

I also created an external app (console EXE, written in Visual Studio 2017 C#), just to prove ObjectDBX can also be driven from external app via COM. There is no difference in this regard of the external app being and EXE or Excel VBA... Here is the code:

 

using System;
using AutoCAD;
using AXDBLib;

namespace Acad2018DbxComTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to continue...");
            Console.ReadLine();

            AcadApplication cadApp = null;
            try
            {
                cadApp = StartAutoCAD();

                Console.WriteLine("AutoCAD started. Press any key to continue...");
                Console.ReadLine();

                DoDbxWork(cadApp);
            }
            catch(System.Exception ex)
            {
                Console.Write("Error:");
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (cadApp!=null)
                {
                    cadApp.Quit();
                }
            }

            Console.WriteLine("Press any key to exit...");
            Console.ReadLine();
        }

        private static AcadApplication StartAutoCAD()
        {
            var app = new AcadApplication();
            app.Visible = true;
            return app;
        }

        private static void DoDbxWork(AcadApplication cadApp)
        {
            var dbxDoc = (AXDBLib.AxDbDocument)cadApp.GetInterfaceObject("ObjectDBX.AxDbDocument.22");
            dbxDoc.Open(@"C:\Temp\Test.dwg");
            int count = 0;
            foreach (AXDBLib.AcadEntity ent in dbxDoc.ModelSpace)
            {
                count++;
            }

            Console.WriteLine("Entitiy count in ModelSpace: {0}", count);
        }
    }
}

The external also works as expected.

 

Note, contrarily to what Ed said in the other thread, AxdbDocument CAN open *.DWT file, as open *.DWG file (but not *.DXF file).

 

So, you'd better provide more details on what/how you have tried to lead to declare some "not working", in spite that thing does work as long as you do it right.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 6 of 9

Anonymous
Not applicable

Wow...  Ouch.  Well, to answer your question, yes I am driving Cad with Microsoft Access.  I am using the following code:

 

 

Private Sub Create_Dwg_Click()
Dim strProj As String
Dim strClient As String
Dim strDwgsfx As String
Dim Fs As Object
Dim Frst As String
Dim Lst As String
Dim ServID As String


strProj = Forms!ExistingProjectsForm.ProjectName
strClient = Forms!ExistingProjectsForm.CustomerID
Frst = Left(strProj, 2)
Lst = Right(strProj, 2)

Dim Response
Dim Suff As String
ServID = Me.ServiceID

Suff = DLookup("dwg_Suffix", "Services", "ServiceID =" & ServID & "")


Response = MsgBox("Create File S:\CADD PROJECTS" & strClient & "\" & strProj & "\dwg\" & Frst & Lst & Suff & ".dwg", vbYesNo)

If Response = vbNo Then GoTo Noe Else

DoCmd.Hourglass (True)

Create:

Set Fs = CreateObject("scripting.filesystemobject")

If Dir("S:\CADD PROJECTS\" & strClient & "\" & strProj & "\dwg\" & Frst & Lst & Suff & ".dwg") <> "" Then GoTo Already

Shell "cmd /c start """" /max ""S:\CADD PROJECTS\" & strClient & "\" & strProj & "\dwg\", vbHide

On Error GoTo NotThere

Fs.copyfile "S:\LDDT-DATA\Template\$$EBI-Civil3d.dwt", "S:\CADD PROJECTS\" & strClient & "\" & strProj & "\dwg\" & Frst & Lst & Suff & ".dwg"

Refresh
Dim DB1 As Database
Set DB1 = CurrentDb


Dim SectorLot As String
Dim SuborRange As String
Dim Subdiv As String

If Forms!ExistingProjectsForm.SubdivisionName.Value Like "*N/A*" Then
Else: GoTo Lot
End If

SectorLot = "Section " & Forms!ExistingProjectsForm.Section_Frm.Value
SuborRange = ("Township " & Forms!ExistingProjectsForm.Township.Value & " South, Range " & Forms!ExistingProjectsForm.Range.Value & " East")
GoTo Cont
Lot:
SectorLot = "Lot " & Forms!ExistingProjectsForm.Lot.Value
SuborRange = Forms!ExistingProjectsForm.SubdivisionName.Value

Cont:

Dim Fn As String
Dim oDBX As Object
Dim acadApp As Object

Fn = "S:\CADD PROJECTS\" & strClient & "\" & strProj & "\dwg\" & Frst & Lst & Suff & ".dwg"

Set acadApp = CreateObject("AutoCAD.Application")

Set oDBX = acadApp.GetInterfaceObject("ObjectDBX.AxDbDocument.22")

oDBX.Open Fn

Dim sInfo As Object
Dim Dwg_Title As String

Dwg_Title = DLookup("dwg_Title", "Services", "ServiceID =" & ServID & "")

Set sInfo = oDBX.SummaryInfo
sInfo.Title = Dwg_Title
sInfo.AddcustomInfo "Project_ID", Forms!ExistingProjectsForm.ProjectName
sInfo.AddcustomInfo "Street_Address", Forms!ExistingProjectsForm.StreetName
sInfo.AddcustomInfo "Lot_Sect", SectorLot
sInfo.AddcustomInfo "Sub_Twn_Rge", SuborRange
sInfo.AddcustomInfo "County", Forms!ExistingProjectsForm.County
sInfo.AddcustomInfo "State", "Florida"
sInfo.AddcustomInfo "Flood_Zone", Forms!ExistingProjectsForm.Flood_Zone
sInfo.AddcustomInfo "Community", Forms!ExistingProjectsForm.Comm_Num
sInfo.AddcustomInfo "Panel", Forms!ExistingProjectsForm.Pan_Num
sInfo.AddcustomInfo "Suffix", Forms!ExistingProjectsForm.Suff
sInfo.AddcustomInfo "Eff_Rev", Forms!ExistingProjectsForm.Eff_Rev
sInfo.AddcustomInfo "Eff_Rev_Date", Forms!ExistingProjectsForm.Eff_Rev_Date
sInfo.AddcustomInfo "FZ_Municipality", Forms!ExistingProjectsForm.Cty_Cnty

If Dwg_Title Like "ALTA*" Then
sInfo.AddcustomInfo "Table_A", Me.Table_A.Value
Else
End If

oDBX.SaveAs Fn

DoCmd.Hourglass (False)

MsgBox "Drawing file has been created"

Set oDBX = Nothing
acadApp.Quit
Set acadApp = Nothing

Shell "cmd /c start """" /max ""S:\CADD PROJECTS\" & strClient & "\" & strProj & "\dwg\", vbHide
  

GoTo Noe

Already:

MsgBox "File Already Exists"

Shell "cmd /c start """" /max ""S:\CADD PROJECTS\" & strClient & "\" & strProj & "\dwg\", vbHide

GoTo Noe

NotThere:

MsgBox "Cad Project Does not Exist"


Noe:


Reset
End Sub

 

 

I think the code is slow, however, because I am opening a hidden instance of CAD.  I'll try the code you have posted. 

Remember, the difficulty in textual communication is the lack of 80% of communication.  I, in no way, am intending to insult.  I am a huge fan of Civil 3d, and I love to write code in VBA through a database I created in MS Access.  My sincere apologies for offending you.

0 Likes
Message 7 of 9

Anonymous
Not applicable

O.k.  I'll be more clear with my response this time...  With a rather derogatory tone you indicated that you recognized I was running the code from an alternate program (you guessed Excel, I am using Access).  You then provided your quick VBA code that only works within AutoCAD (I assume).  Then provided language in "COM" vs. Visual basic (which was the request).  As you can see, I have posted the VBA code that works to create a .dwg file, change the properties and should there be missing directories or if the file already exists, there are algorithms for those events.

 

I tried your VBA code in Access, and as stated in my previous post "it doesn't work"...  The error occurs on "GetInterfaceObject" (Compile Error: Method or data member not found), because that must be an inherent command for AutoCAD.  If I am wrong on this point, please let me know.  The code that DOES NOT WORK in MS Access VBA is below:

 

Option Explicit

Public Sub Command7_Click()

On Error GoTo Err

Dim Fn As String
Dim oDBX As AXDBLib.AxDbDocument

Fn = "C:\Temp\Temp.dwt"

Set oDBX = Application.GetInterfaceObject("ObjectDBX.AxDbDocument.22")

oDBX.Open Fn

Dim sInfo As Object

Set sInfo = oDBX.SummaryInfo
sInfo.Title = "My Test Title"

sInfo.AddCustomInfo "Project_ID", "Project ID Time"
sInfo.AddCustomInfo "Street_Address", "Address"
sInfo.AddCustomInfo "Lot_Sect", "Lot or Section"
sInfo.AddCustomInfo "Sub_Twn_Rge", "Subdivision or Township Range"
sInfo.AddCustomInfo "County", "County"
sInfo.AddCustomInfo "State", "Florida"

oDBX.SaveAs Fn

Set oDBX = Nothing

MsgBox "Done"
   
End Sub

 

 

  The VBA code that I posted was to open a hidden instance of AutoCAD to run that particular command.  I would prefer to modify these properties without the necessity of opening and closing an AutoCAD Object.  But until the properties are made readily available outside of AutoCAD, I am at a loss, other than to wait the 20 seconds it takes to open the instance, run the commands, and close the instance.

 

As you can see from the posts, I was diligently asking for specific help, and was given a few answers, but they didn't achieve the goal.  The answer I was given was to see the previous posts.  I had already tried the code in the previous posts, over and over and over again to be sure what I was posting was not already answered.  Hopefully the code I posted that works with Microsoft Access 2007-2013 to modify .dwg file properties will help someone avoid the accusatory post I now have endured.

 

Eric Blackburn, President

EBI Surveying

0 Likes
Message 8 of 9

norman.yuan
Mentor
Mentor

Well, the code in your first respond to my reply should have been worked (at least the portion of code related to starting AutoCAD session and then obtain the AxdbDocument object. And it is obviously the code in your second respond SHOULD NOT work, because of this line of code:

 

Set oDBX = Application.GetInterfaceObject("ObjectDBX.AxDbDocument.22")

because "Application" in this code context refers to MS Access Application, which does not have a method GetInterfaceObject(). What I said in my previous reply stays:

 

AcadAPplication.GetInterfaceObject("ObjectDBX.AxDbDocument.xx") 

 

works for all later AutoCAD releases. In order to back up my claim, I specifically tried following code in MS Access' VBA Mudule:

 

Option Compare Database
Option Explicit

Public Sub DbxTest()

    Dim cadApp As AcadApplication
    Dim doc As AXDBLib.AxDbDocument
    Dim ent As AcadEntity
    Dim count As Integer
    
    On Error Resume Next
    Set cadApp = CreateObject("AutoCAD.Application")
    If Err Then
        MsgBox "Cannot start AutoCAD session!"
    Else
    
        cadApp.Visible = True
        Set doc = cadApp.GetInterfaceObject("ObjectDBX.AxDbDocument.22")
        If Err Then
            MsgBox "Cannot create AxdbDocument!"
        Else
            doc.Open "C:\Temp\Test.dwg"
            For Each ent In doc.ModelSpace
                count = count + 1
            Next
    
            MsgBox "Entities in modelspace: " & count
        End If
        
    End If
    
End Sub

I tried this code with 2 different computers:

 

Win7 + MS Access 2013 + AutoCAD 2017 (of course in that case, the ProgId is "ObjectDBX.AcDbDocument.21")

Win10 + MS Access 2016 + AutoCAD 2018.

 

One possible reason that 

 

cadApp.GetInterfaceObject("ObjectDBX.AxDbDocument.22")

does not work is that when you set reference to AutoCAD Commom ObjectDBX type library, in the library list of "References" dialog box you may see 2 items list there, one locateed in "C:\Program Files\Common files\Autodesk Shared\" folder, the other located in "C:\Program Files (x86)\Common Files\Autodesk Shared\". Depending on your AutoCAD being 32bit or 64bit, you should select the one in "Program Files (x86)\..." folder for 32bit AutoCAD, and choose the other for 64bit AutoCAD,

 

Again, 

 

AcadApplication.GetInterfaceObject("ObjectDBX.AcDbDocument.22") 

 

works as expected, and as all older version of AutoCAD, be it called inside AutoCAD VBA, or from external application via COM (in your case MS Access application)!

Norman Yuan

Drive CAD With Code

EESignature

Message 9 of 9

Anonymous
Not applicable
Now we’re getting somewhere. When I type dim CadApp as Acadapplication is not an option which means I might have the wrong library. I’ll check that.
0 Likes