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

    Visual Basic Customization

    Reply
    Member
    Posts: 3
    Registered: ‎06-01-2010

    run VB6 application with different Autocad Version

    1070 Views, 3 Replies
    06-01-2010 04:39 AM
    Hello,
    I have a Visual Basic 6.0 Project , to manage CAD Data
    I want to open a file in Autocad
    1) in VB6 , I add Project / Reference / Autocad 2006 Type Library
    2) I use following code (see below) , to select application , start Autocad if not already started , open File
    3) I compile Mycode : MyCADProject.exe
    => start MyCADProject.exe , I select a DWG file and I can open the file in Autocad 2006 : OK

    Problem , I have new PC one with Autocad 2010, one with Autocad 2009 (all other PC are with Autocad 2006)
    in My VB6 Project
    1) I can not sellect both library "Autocad 2006 Type Library" and "Autocad 2007 Type Library"
    => I get a Windows error Message "Librairie déja utilisée"
    2) If I select only one Library , this run well for one version of Autocad , but not fot the other version !
    I want to manage only one version of MyCADProject.exe

    I do not find any solution on this forum

    Is is possible to run a VB6 project with different version of Autocad ?





    Dim Acadapp As AcadApplication

    On Error Resume Next
    Set Acadapp = GetObject(, "AutoCAD.Application")


    If Err.Number <> 0 Then
    On Error GoTo 0
    Set Acadapp = CreateObject("AutoCAD.Application")
    End If

    Acadapp.Documents.Open (Myfile)
    Acadapp.Visible = True
    Please use plain text.
    New Member
    zzippo
    Posts: 1
    Registered: ‎06-06-2010

    Re: run VB6 application with different Autocad Version

    06-06-2010 06:11 AM in reply to: staubli

    you have to use late binding instead of setting a refference to an AutocadType Library.

     

    Dim Acadapp As Object
    Set Acadapp = CreateObject("AutoCAD.Application")

    Acadapp.Documents.Open (Myfile)
    Acadapp.Visible = True

     

     

    This will work with all versions. You can later check with Acadapp.Version if you run on 2006 or later.

     

     

    Please use plain text.
    Member
    Posts: 3
    Registered: ‎06-01-2010

    Re: run VB6 application with different Autocad Version

    06-09-2010 01:13 AM in reply to: staubli

    Hello,

     

    I have test you solution this run well ! 

     

    1) do not select "Autocad 2006 Library type"  nor "Autocad 2007 Library type"   in Project / References

     

    2) Dim Acadapp As Object   '  instead of AcadApplication , because Autocad is not select (cf 1)

     

     

     thanks a lot

     


    staubli wrote:
    Hello,
    I have a Visual Basic 6.0 Project , to manage CAD Data
    I want to open a file in Autocad
    1) in VB6 , I add Project / Reference / Autocad 2006 Type Library
    2) I use following code (see below) , to select application , start Autocad if not already started , open File
    3) I compile Mycode : MyCADProject.exe
    => start MyCADProject.exe , I select a DWG file and I can open the file in Autocad 2006 : OK

    Problem , I have new PC one with Autocad 2010, one with Autocad 2009 (all other PC are with Autocad 2006)
    in My VB6 Project
    1) I can not sellect both library "Autocad 2006 Type Library" and "Autocad 2007 Type Library"
    => I get a Windows error Message "Librairie déja utilisée"
    2) If I select only one Library , this run well for one version of Autocad , but not fot the other version !
    I want to manage only one version of MyCADProject.exe

    I do not find any solution on this forum

    Is is possible to run a VB6 project with different version of Autocad ?





    Dim Acadapp As AcadApplication

    On Error Resume Next
    Set Acadapp = GetObject(, "AutoCAD.Application")


    If Err.Number <> 0 Then
    On Error GoTo 0
    Set Acadapp = CreateObject("AutoCAD.Application")
    End If

    Acadapp.Documents.Open (Myfile)
    Acadapp.Visible = True

     

    Please use plain text.
    Member
    Posts: 3
    Registered: ‎05-09-2012

    Re: run VB6 application with different Autocad Version

    09-27-2012 02:08 AM in reply to: staubli
    Public Function Koppeling_AutoCAD(Optional ByRef Fout As Boolean, Optional Quiet As Boolean)
    Dim OK As Boolean
    Dim acV As String
    Dim v()
    Dim vv As String
    Dim Index As Integer
    Const ObjectString = "AutoCad.Application"
    
       Fout = False
       
       On Error Resume Next
       Index = CheckGetObject(ObjectString & ".")
       OK = IIf(Index <= 0, False, True)
       
       If OK Then
         v = LijstVersies
         'Set AcadColor = AcadApp.GetInterfaceObject("AutoCAD.AcCmColor." & v(i))
         If InStr(1, v(Index), ".") Then
           vv = Mid(v(Index), 1, InStr(1, v(Index), ".") - 1)
          Else
           vv = v(Index)
         End If
         Set AcadColor = AcadApp.GetInterfaceObject("AutoCAD.AcCmColor." & vv)
       End If
       
       If Not OK Then
         If Not Quiet Then Call MsgBox("No connection with AutoCAD", vbCritical)
         Fout = True
       End If
       
       If Not Fout Then
         Set AcadDoc = AcadApp.ActiveDocument
         Set AcadMod = AcadDoc.ModelSpace
         Set paSpace = AcadDoc.PaperSpace
         Set Util = AcadApp.ActiveDocument.Utility
         Set acTekeningen = AcadApp.Documents
         
         AcadApp.Visible = True
         AcadApp.ActiveDocument.Activate
         AchtergrondKleur = AcadApp.Preferences.Display.GraphicsWinModelBackgrndColor
      '   Call GetVersies(Index, acV, acadVersie)
       End If
       
       If acTekeningen.Count = 0 Then Fout = True
       If Fout Then acV = ""
       Koppeling_AutoCAD = acV
    End Function 'koppeling_AutoCAD

    Private Function LijstVersies()
    Dim v(1 To 27) As Variant, vv As String
       v(1) = "1.0"
       v(2) = "1.2"
       v(3) = "1.3"
       v(4) = "1.4"
       v(5) = "2.0"
       v(6) = "2.1"
       v(7) = "2.5"
       v(8) = "2.6"
       v(9) = "9"
       v(10) = "10"
       v(11) = "11"
       v(12) = "12"
       v(13) = "13"
       v(14) = "14"
       v(15) = "15"
       v(16) = "15.1"
       v(17) = "15.2"
       v(18) = "16"
       v(19) = "16.1"
       v(20) = "16.2"
       v(21) = "17"
       v(22) = "17.1"
       v(23) = "17.2"
       v(24) = "18"
       v(25) = "18.1"
       v(26) = "18.2"
       v(27) = "19"
      LijstVersies = v
    End Function

    Private Sub GetVersies(Index, acV As String, acadVersie As String)
      acV = "": acadVersie = ""
      Select Case Index
        Case 27
          acV = "AutoCAD 2013"
          acadVersie = "2013"
        Case 26
          acV = "AutoCAD 2012"
          acadVersie = "2012"
        Case 25
          acV = "AutoCAD 2011"
          acadVersie = "2011"
        Case 24
          acV = "AutoCAD 2010"
          acadVersie = "2010"
        Case 23
          acV = "AutoCAD 2009"
          acadVersie = "2009"
        Case 22
          acV = "AutoCAD 2008"
        Case 21
          acV = "AutoCAD 2007"
        Case 20
          acV = "AutoCAD 2006"
        Case 19
          acV = "AutoCAD 2005"
        Case 18
          acV = "AutoCAD 2004"
        Case 17
          acV = "AutoCAD 2002"
        Case 16
          acV = "AutoCAD 2000i"
        Case 15
          acV = "AutoCAD 2000"
        Case 14
          acV = "AutoCAD R14"
        Case 13
          acV = "AutoCAD R13"
        Case Else
          acV = "AutoCAD ??"
      End Select
    End Sub



     Dispite the Dutch words, I think it's readable enough to work with. Although the reply is late (couple of years), the problem remains for many users. In our Office we run AutoCAD2000-2009 + Civil2008-2013. Every year I have to add an extra number for the application.

     

    Peter

     

    Please use plain text.