.NET

.NET

Reply
Contributor
Amrit.shr
Posts: 13
Registered: ‎03-14-2011
Message 1 of 8 (2,507 Views)

how to access AutoCAD 2012 from Vb.net Standard Exe

2507 Views, 7 Replies
03-08-2012 07:09 AM

hi

 

is that possible to access AutoCAD 2012 from VB.net Standard Exe

i am using vb.net 2010

i try to load AcDbMgd.dll and AcMgd every time i compile it give error in "Imports

 

Autodesk.AutoCAD.ApplicationServices"

 

is there any example for read and write current open drawing in AutoCAD from .net Standard Exe.

 

Thanks in advance.

Amrit

*Expert Elite*
arcticad
Posts: 1,285
Registered: ‎06-21-2004
Message 2 of 8 (2,501 Views)

Re: how to access AutoCAD 2012 from Vb.net Standard Exe

03-08-2012 07:41 AM in reply to: Amrit.shr

http://through-the-interface.typepad.com/through_the_interface/2006/07/debugging_using.html

---------------------------



(defun botsbuildbots() (botsbuildbots))
Contributor
Amrit.shr
Posts: 13
Registered: ‎03-14-2011
Message 3 of 8 (2,497 Views)

Re: how to access AutoCAD 2012 from Vb.net Standard Exe

03-08-2012 07:59 AM in reply to: arcticad

i don't understand

 

*Expert Elite*
arcticad
Posts: 1,285
Registered: ‎06-21-2004
Message 4 of 8 (2,494 Views)

Re: how to access AutoCAD 2012 from Vb.net Standard Exe

03-08-2012 08:09 AM in reply to: Amrit.shr

Sorry I read your question wrong.

 

acDbMgd.dll and AcMgd are only for internal use within Autocad. They can't be used by an outside EXE.

 

Get a reference to COM Autocad 2012 Type Library

 

Imports System
Imports System.Runtime.InteropServices
Imports Autodesk.AutoCAD.Interop

Public Class ComCode

    Public Sub runme()

        Const progID As String = "AutoCAD.Application.18"
        Dim acApp As AcadApplication = Nothing
        Try
            acApp = DirectCast(Marshal.GetActiveObject(progID), AcadApplication)
        Catch ex As Exception
            Try
                Dim acType As Type = Type.GetTypeFromProgID(progID)
                acApp = DirectCast(Activator.CreateInstance(acType, True), AcadApplication)
            Catch ex2 As Exception
                MessageBox.Show("Cannot create object of type """ & progID & """")

            End Try
        End Try

        If acApp IsNot Nothing Then
            ' By the time this is reached AutoCAD is fully
            ' functional and can be interacted with through code
        End If
    End Sub

End Clas

 

---------------------------



(defun botsbuildbots() (botsbuildbots))
Contributor
Amrit.shr
Posts: 13
Registered: ‎03-14-2011
Message 5 of 8 (2,486 Views)

Re: how to access AutoCAD 2012 from Vb.net Standard Exe

03-08-2012 08:32 AM in reply to: arcticad

hi arcticad

thanks for reply

it look like it is connect with autocad. but how to draw object and how to select object on it. could you please give little  hints.

 

thnaks

 

 

 

*Expert Elite*
arcticad
Posts: 1,285
Registered: ‎06-21-2004
Message 6 of 8 (2,473 Views)

Re: how to access AutoCAD 2012 from Vb.net Standard Exe

03-08-2012 09:31 AM in reply to: Amrit.shr
   Sub dwgAddCircle(ByVal acadApp As Autodesk.AutoCAD.Interop.AcadApplication)

        Dim doc As AcadDocument = acadApp.ActiveDocument

        Dim pt(2) As Double
        pt(0) = 0
        pt(1) = 0
        pt(2) = 0

        doc.ModelSpace.AddCircle(pt, 10)

    End Sub

    Sub dwgReSave(ByVal acadApp As Autodesk.AutoCAD.Interop.AcadApplication, ByVal strFileName As String)
        Dim acadDBX As Object = acadApp.GetInterfaceObject("ObjectDBX.AxDbDocument.18")

        If FileExists(strFileName) Then
            If Not InUse(strFileName) Then
                Try
                    acadDBX.Open(strFileName)
                    acadDBX.saveas(strFileName)
                    acadDBX = Nothing
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(acadApp)

                    GC.Collect()
                    GC.WaitForPendingFinalizers()

                Catch ex As Exception
                End Try
            End If
        End If


    End Sub

    Public Function InUse(ByVal sFile As String) As Boolean

        If System.IO.File.Exists(sFile) Then
            Try
                Dim F As Short = FreeFile()
                FileOpen(F, sFile, OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.LockReadWrite)
                FileClose(F)
            Catch


                Return True
            End Try
        End If
    End Function

    Public Function FileExists(ByVal FileFullPath As String) _
As Boolean
        Dim f As New IO.FileInfo(FileFullPath)
        Return f.Exists

    End Function

 

---------------------------



(defun botsbuildbots() (botsbuildbots))
Contributor
Amrit.shr
Posts: 13
Registered: ‎03-14-2011
Message 7 of 8 (2,434 Views)

Re: how to access AutoCAD 2012 from Vb.net Standard Exe

03-09-2012 08:26 AM in reply to: Amrit.shr

it come error

 

Unable to cast COM object of type 'System.__ComObject' to interface type 'Autodesk.AutoCAD.Interop.Common.IAcadModelSpace'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{C60BC8AF-58DA-4866-859D-22A7F61411DE}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

 

 

in line

 doc.ModelSpace.AddCircle(pt, 10)

 

 

Contributor
Amrit.shr
Posts: 13
Registered: ‎03-14-2011
Message 8 of 8 (2,415 Views)

Re: how to access AutoCAD 2012 from Vb.net Standard Exe

03-11-2012 02:32 PM in reply to: Amrit.shr

hi Arcticad

your code work while i change compiler  to 3.5. and when i try to use 4 it give error on draw.

Thanks you

 

Could any one suggest me what need more in code to draw from exe to autocad while i set to compile option in .net framework 4.

 

Thanks

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

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