Get AcadApp object from handle

Discussion in 'AutoCAD' started by grobsystems, Nov 5, 2004.

  1. grobsystems

    grobsystems Guest

    Hi, maybe someone can suggest a better way. I am trying to start AutoCAD with its vanilla profile. The way I achieve this is to start it with the Shell method and use the /p switch to start it. Works great, but how do I get the app object? I can use GetObject but I can possibly have two session of acad running and with different profiles. I can get the handle of the newly opened session, but I need the actual application object. Can anyone give me a clue how to do this differently or how to "grab" that object? Thank for any help.

    JRW
     
    grobsystems, Nov 5, 2004
    #1
  2. There is now way to go from a handle to an ActiveX object. Use GetObject
    or CreateObject.

    If you start your app from AutoCAD (an option too often overlooked), you
    can use VisualLISP to pass the current instance of AutoCAD to your
    application ensuring the right connection every time.
     
    Frank Oquendo, Nov 5, 2004
    #2
  3. grobsystems

    grobsystems Guest

    Frank, thanks for the reply. Very insightful. I appreciate the quick answer. Now that I know what I must work with.
     
    grobsystems, Nov 5, 2004
    #3
  4. grobsystems

    jdinardi Guest

    If you know or can get the filename of the current file in the instance of AutoCAD that you want to grab then you can use GetObject like so...

    Set obj = GetObject("d:\TheFileName.dwg").Application

    Obviously the file path and name need to be the file you are looking for. If you don't know the file name there are various windows API functions you can use to enumerate all running windows, get window captions, etc... which you can probably make use of depending on your situation.

    Regards,
    Jacob Dinardi
     
    jdinardi, Nov 8, 2004
    #4
  5. grobsystems

    grobsystems Guest

    Thanks for you reply also Jacob. What I ended up doing was sort of a cheat. I edited the registry default profile, started AutoCAD with CreateObject and then reset the registry to its previous setting. It works well. Thanks again.

    JRW
     
    grobsystems, Nov 9, 2004
    #5
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.