Loading correct version of AutoCAD

Discussion in 'AutoCAD' started by Zatopek, Sep 9, 2004.

  1. Zatopek

    Zatopek Guest

    I porting an old VB-app to AutoCAD 2004
    I know almost nothing about VB or VBA, so i have no idea of what i'm doing.

    This line
    ver = AutoCAD.Application.ActiveDocument.GetVariable("acadver")
    Loads AutoCAD 2002. How can i force it to use the autocad started, or at
    least use 2004?

    I Snatched this piece of code from another project
    Set acadObj = GetObject(, "AutoCAD.Application.16")
    ver = acadObj.ActiveDocument.GetVariable("acadver")

    But that does not run at all.

    Is there any quick solution, sort of "Aha. Just put an 'a' instead of a 'b'
    there"

    /M
     
    Zatopek, Sep 9, 2004
    #1
  2. Zatopek

    TomD Guest

    What do you meant by that line "loads AutoCad 2002"? That line is simply
    setting the version variable to the ver variable.

    I'm still fairly new to this all, but I used this recently, successfully,
    without specifying any version. It simply grabbed the open session
    (apparently).

    Dim oAcadApp As AcadApplication, oLddProj As AeccApplication
    Set oAcadApp = GetObject(, "AutoCAD.Application")
    Set oLddProj = oAcadApp.GetInterfaceObject("Aecc.Application")

    (Note the lack of the version number within the GetObject.)

    .....clarifications welcome, as always, from those in the know. ;)
     
    TomD, Sep 9, 2004
    #2
  3. Zatopek

    Zatopek Guest

    What do you meant by that line "loads AutoCad 2002"?
    That was what i would have exptected. But it fires a new AutoCAD 2002
    session.
    Guess something is registred to be 2002 somewhere
     
    Zatopek, Sep 9, 2004
    #3
  4. Zatopek

    TomD Guest

    Are you absolutely certain about that? If that's true, then I'm waaaaay
    confused...lol.

    C'mon, gurus................help us out, here.
     
    TomD, Sep 9, 2004
    #4
  5. Zatopek

    rwilkins Guest

    Set App = CreateObject("AutoCAD.Application") 'Loads last used version of AutoCAD
    Set App = CreateObject("AutoCAD.Application.15") ' Load AutoCAD 2002
    Set App = CreateObject("AutoCAD.Application.16") 'Loads AutoCAD 2004
    Set App = CreateObject("AutoCAD.Application.16.1") ' Loads AutoCAD 2005
     
    rwilkins, Sep 9, 2004
    #5
  6. Actually its the last version of AutoCAD the user ran. Don't use it if you
    could be in a multi-install environment and want control of which version
    you are firing. Below is the standard function I use - there are others but
    this suits my needs. Notice that I am using late binding so there is no
    reference to AutoCAD required - especially since I am not sure at trun time
    which one I'll find. To use early binding, remove the Object calls and
    replace with the AutoCAD specific refs commented out to the right of
    Object. Also, I am tracking whether I started AutoCAD or whether it was
    already running. I do this so I can shut it down if I started it.


    '==== GLOBAL VARS ====
    Private g_cadApp As Object 'AutoCAD AcadApplication
    Private g_cadDoc As Object 'AutoCAD AcadDocument
    Private g_bStartedAutoCAD As Boolean

    Public Sub DoIt()
    'connect to AutoCAD
    g_bStartedAutoCAD = StartAutoCAD(False)
    'test to see if its awake
    If IsAutoCADAwake = True Then
    'Do whatever.....
    End If
    End Sub

    Public Function StartAutoCAD(blnHide As Boolean) As Boolean
    '+--Fire up AutoCAD
    On Error Resume Next
    'Get the 2000i/2002 Application object
    Set g_cadApp = GetObject(, "AutoCAD.Application.15")
    'If error try connecting to 2004
    If Err Then
    Err.Clear
    Set g_cadApp = GetObject(, "AutoCAD.Application.16")
    'If error try connecting to 2005
    If Err Then
    Err.Clear
    Set g_cadApp = GetObject("AutoCAD.Application.16.1")
    'If error try starting 2000i/2002
    If Err Then
    Err.Clear
    Set g_cadApp = CreateObject("AutoCAD.Application.15")
    'If error try starting 2004
    If Err Then
    Err.Clear
    Set g_cadApp = CreateObject("AutoCAD.Application.16")
    'If error try starting 2005
    If Err Then
    Err.Clear
    Set g_cadApp = CreateObject("AutoCAD.Application.16.1")
    Do
    Err.Clear
    Resume
    Loop While Err.Number = 429
    'started AutoCAD
    StartAutoCAD = True
    End If
    End If
    Else
    'found AutoCAD already running
    StartACAD = False
    End If
    Else
    'found AutoCAD already running
    StartACAD = False
    End If
    Else
    'found AutoCAD already running
    StartACAD = False
    End If
    'Set the AutoCAD document object
    Set g_cadDoc = g_cadApp.ActiveDocument
    End Function

    Public Function IsAutoCADAwake() As Boolean
    '+-- This checks to see if AutoCAD is in a quiescent state
    On Error Resume Next
    Dim State As Object 'AcadState
    Dim sErrMsg As String
    Set State = g_cadApp.GetAcadState
    If Err Then
    Select Case Err.Number
    Case -2147417851
    Err.Clear
    IsAutoCADAwake = False
    Case -2147418111
    Err.Clear
    sErrMsg = "AutoCAD is busy...Please switch to it and" & vbCr & _
    "cancel whatever command it is attempting to do."
    MsgBox sErrMsg
    IsAutoCADAwake = False
    Case Else
    sErrMsg = "Something is preventing connecting" & vbCr & _
    "to AutoCAD. Please shut down and restart."
    MsgBox sErrMsg
    Err.Clear
    Exit Function
    End Select
    Else
    IsAutoCADAwake = IIf(State.IsQuiescent, True, False)
    End If
    End Function

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Sep 9, 2004
    #6
  7. Zatopek

    TomD Guest

    Thank you both for the clarification on that. That's something that doesn't
    seem to be documented well. It seems that most references to doing it
    assume that you're already familiar with the process.
     
    TomD, Sep 9, 2004
    #7
  8. Zatopek

    Zatopek Guest

    Is there a way to get the autocad that started my app?
    I do not need to start an new, if no one is running, just fail.
    The current autocad!

    I see that you try a lot of versions one at the time.
    I do not know if the user runs 2004 or 2005.
    But I do the assumption that the user only runs one at the time.

    (But if not; how can one figure out in what autocad a VB app runs if there
    are 10 different version running!!!!)

    /M
     
    Zatopek, Sep 10, 2004
    #8
  9. Zatopek, can you clarify what your code is/does? You have conflicting
    statements here:
    This states AutoCAD is starting your app, in which case just pass the
    instance of AutoCAD itself
    This states that your app is starting itself. In which case, just remove
    the conditional statements that CreateObject and leave only the GetObject
    conditions. Once you get the object, just read the AutoCAD Version varaible
    or add your own variable that tells you which one the function connected
    to.

    Which is it?
    So do I and so does the code I posted! The code only returns a single
    instance of AutoCAD based on which one it finds first. If all you want is
    2004 or 2005, revise the code to just check for 16 and 16.1. The order in
    which you check obviously determines which one is your preference.
    There may be 10 different versions INSTALLED, NOT RUNNING! After reading
    the previous comments in this post, you should have your answer to this. If
    not, re-post and I'll try explaining it differently.


    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Sep 10, 2004
    #9
  10. Zatopek

    Zatopek Guest

    Got me!
    I don't know what i'm doing.

    I got a VB6 app for 2002. For some reason it checks the version somewhere.
    I debudgged it when 2002 was running (starting VB6 and stepping) so i got a
    clue what i is doing.

    First attempt to port it was just to debug it when 2004 was running.
    The line mentioned just launched 2002. Suprised!!

    One thing that puzzles me with Acad and VB is the EXE.
    If the user starts my app from whitin acad, I wanted to know the acad
    version that launched it, and if the user clicked the exe (that i do not
    like) i wanted to trap that and just die.

    But this is history now.
    I decided to rewrite the app (small, i admit that) in VB.NET as a lab to see
    if i can grasp that. (see another thread)
    ..NET apps at least runs whitin one instance of autocad.

    Thanks a lot for the answers.

    /M
     
    Zatopek, Sep 10, 2004
    #10
  11. One thing that puzzles me with Acad and VB is the EXE.
    What can I say but it soundss poorly written. Running an EXE from within
    AutoCAD makes it outt of process which is slow and not very good. If it was
    to be accessed within AutoCAD, it should've been an ActiveX DLL. But, all
    that aside, you could have had the EXE pass something so it knew AutoCAD,
    and which version of it, had started it up.
    Only now because of 2005 - you'll get the same thing once 2006 is out =)
    You'll also notice in that thread that you're stilll limited to ActiveX
    even though you're in .NET :(

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Sep 10, 2004
    #11
  12. Zatopek

    Zatopek Guest

    "What can I say but it soundss poorly written"
    Second that!!!

    "Only now because of 2005 - you'll get the same thing once 2006 is out "
    But than you can control the "netload". No more clicking on exes

    Rats.
    But thanks.

    Case closed

    /M
     
    Zatopek, Sep 10, 2004
    #12
  13. ReOpened ;-) You can control the netload how? If your app will work in both
    2005 & 2006, you'll still need to determine which is which I think - unless
    you keep two - one for each version.

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Sep 11, 2004
    #13
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.