• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Contributor
    Amrit.shr
    Posts: 13
    Registered: ‎03-14-2011

    how to access AutoCAD 2012 from Vb.net Standard Exe

    1107 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

    Please use plain text.
    *Expert Elite*
    arcticad
    Posts: 1,250
    Registered: ‎06-21-2004

    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

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



    “We don’t have a snowball’s chance in a blast furnace of surviving this attack unless every one of our units gets into the fight right now!”
    Please use plain text.
    Contributor
    Amrit.shr
    Posts: 13
    Registered: ‎03-14-2011

    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

     

    Please use plain text.
    *Expert Elite*
    arcticad
    Posts: 1,250
    Registered: ‎06-21-2004

    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

     

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



    “We don’t have a snowball’s chance in a blast furnace of surviving this attack unless every one of our units gets into the fight right now!”
    Please use plain text.
    Contributor
    Amrit.shr
    Posts: 13
    Registered: ‎03-14-2011

    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

     

     

     

    Please use plain text.
    *Expert Elite*
    arcticad
    Posts: 1,250
    Registered: ‎06-21-2004

    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

     

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



    “We don’t have a snowball’s chance in a blast furnace of surviving this attack unless every one of our units gets into the fight right now!”
    Please use plain text.
    Contributor
    Amrit.shr
    Posts: 13
    Registered: ‎03-14-2011

    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)

     

     

    Please use plain text.
    Contributor
    Amrit.shr
    Posts: 13
    Registered: ‎03-14-2011

    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

    Please use plain text.