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

how to access AutoCAD 2012 from Vb.net Standard Exe

7 REPLIES 7
Reply
Message 1 of 8
Amrit.shr
4699 Views, 7 Replies

how to access AutoCAD 2012 from Vb.net Standard Exe

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

7 REPLIES 7
Message 2 of 8
arcticad
in reply to: Amrit.shr

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

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



(defun botsbuildbots() (botsbuildbots))
Message 3 of 8
Amrit.shr
in reply to: arcticad

i don't understand

 

Message 4 of 8
arcticad
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))
Message 5 of 8
Amrit.shr
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

 

 

 

Message 6 of 8
arcticad
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))
Message 7 of 8
Amrit.shr
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)

 

 

Message 8 of 8
Amrit.shr
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

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