.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Autocad Databases and Transaction

3 REPLIES 3
Reply
Message 1 of 4
sidshares
917 Views, 3 Replies

Autocad Databases and Transaction

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
3 REPLIES 3
Message 2 of 4
jimmie_fulton
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.
Message 3 of 4
Anonymous
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.
Message 4 of 4
sidshares
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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost