.NET

Reply
Member
sidshares
Posts: 4
Registered: ‎03-22-2006
Message 1 of 4 (183 Views)

Autocad Databases and Transaction

183 Views, 3 Replies
03-22-2006 07:30 AM
First posting

Hi

Hoping to get some help, I am trying to run Autocad and get details of blocks from the Database using Transaction method.

The problem I am having seems to be converting AcadDatabase to Database, I keep receiving

"Invalid Cast" errors

even after trying various methods. Is there a solution to this?

I have trimmed the code down to the bare bones to try and find the problem.

Using Autocad 2006 and Visual Basic.Net 2003

Code:

Imports System.io
Imports System
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Imports DBtransMan = Autodesk.AutoCAD.DatabaseServices.TransactionManager

Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

** I have tried creating a new Autocad session and using an existing one
'Dim acadApp As Autodesk.AutoCAD.Interop.AcadApplication
'acadApp = New Autodesk.AutoCAD.Interop.AcadApplication
'acadApp.Visible = True
**
Dim acadApp As Autodesk.AutoCAD.Interop.AcadApplication = CType(GetObject(, "autocad.application.16"), Autodesk.AutoCAD.Interop.AcadApplication)
Dim acadDoc As AcadDocument = acadApp.ActiveDocument
Dim acadDB As AcadDatabase = acadApp.ActiveDocument.Database
Dim WDB As Database = HostApplicationServices.WorkingDatabase.FromAcadDatabase(acadDB)
Dim tm As DBtransMan = WDB.TransactionManager

Dim myT As Transaction = tm.StartTransaction()

End Sub



End Class
Active Contributor
jimmie_fulton
Posts: 44
Registered: ‎04-06-2005
Message 2 of 4 (183 Views)

Re: Autocad Databases and Transaction

03-22-2006 10:13 AM in reply to: sidshares
Perhaps try:

Dim WDB As Database = Database.FromAcadDatabase(acadDB)

It appears that you are mixing in COM with the Managed API. This is fine, except that you are connecting to AutoCAD through COM and then trying to use the Managed API. I haven't tried that myself, so I can't say some parts would not work, but generally if you are going to use COM in an external application, I'd use that model completely thoughout your project. Mixing COM interop with Managed API makes more sense when your application is hosted by AutoCAD (loaded as a DLL with "netload"), and then use COM interop if needed for something that isn't exposed to the Managed API yet.

Make sense? Hope this helps.
*Tony Tanzillo
Message 3 of 4 (183 Views)

Re: Autocad Databases and Transaction

03-22-2006 11:02 AM in reply to: sidshares
External applications can't use the Managed
API at all, so either he builds his app as a
NETLOADable DLL, or uses ActiveX entirely.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

wrote in message news:5118331@discussion.autodesk.com...
Perhaps try:

Dim WDB As Database = Database.FromAcadDatabase(acadDB)

It appears that you are mixing in COM with the Managed API. This is fine, except that you are connecting to AutoCAD through COM and then trying to use the Managed API. I haven't tried that myself, so I can't say some parts would not work, but generally if you are going to use COM in an external application, I'd use that model completely thoughout your project. Mixing COM interop with Managed API makes more sense when your application is hosted by AutoCAD (loaded as a DLL with "netload"), and then use COM interop if needed for something that isn't exposed to the Managed API yet.

Make sense? Hope this helps.
Member
sidshares
Posts: 4
Registered: ‎03-22-2006
Message 4 of 4 (183 Views)

Re: Autocad Databases and Transaction

03-22-2006 11:59 PM in reply to: sidshares
thanks for both of your replies.

Yes, I wanted to start Acad using COM and then access Block details and I found Transactions were touted as the way to go as I wanted the insert point (and more) and couldn't find a COM way to do that.

I did try your suggestion and stil received errors.

It does say in the ObjectArx help that it is possible to "get the .NET object from a COM object" but that does seem to cause problems in this respect.

Thanks for the help, I think loading as a DLL seems to be the path to go down.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.