Results 1 to 4 of 4

Thread: how to prevent losing focus on acadApp.Documents.Open() when acadApp is running in background

  1. #1
    Member
    Join Date
    2015-01
    Posts
    27
    Login to Give a bone
    0

    Default how to prevent losing focus on acadApp.Documents.Open() when acadApp is running in background

    Hi all,
    I have a macro in excel that populates dwg blocks using informations from the spreadsheet.
    Since sometimes I have to process a long list of dwgs at once, I would like to be able to use another application while the macro runs, but everytime the macro opens a new document with
    Code:
     Set acadDocCurr = acadApp.Documents.Open(filenameToOpen)
    I lose focus of the current window.

    Here's the declaration:
    Code:
    Dim acadDocCurr As AcadDocument
    Dim acadApp As AutoCAD.AcadApplication
    Set acadApp = CreateObject("AutoCAD.Application")
    On the excel side I disable the screen updating, the events and set the calculation to manual:
    Code:
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    prevCalculationState = Application.Calculation
    Application.Calculation = xlManual
    and I also hide my acad application object with
    Code:
    acadApp.Visible = False
    But it doesn't help.

    I tested by commenting out all the code except the open method, so I'm 100% that the problem is that instruction.

    How can I prevent this behaviour?
    I tried to search in the forum and on the entire Internet but I could not find anything about this case.
    I'm on windows 7, autocad 2010, excel 2013.
    Thanks for the attention!

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,420
    Login to Give a bone
    0

    Default Re: how to prevent losing focus on acadApp.Documents.Open() when acadApp is running in background

    Its standard Windows functionality to make an app active when you open a document in the app. You can activate the application you want to have focus. If you want acad to have focus, use "acadApp.Activate". If you want excel to be active use "Application.ActivateMicrosoftApp myXlVar".
    C:> ED WORKING....


    LinkedIn

  3. #3
    Member
    Join Date
    2015-01
    Posts
    27
    Login to Give a bone
    0

    Default Re: how to prevent losing focus on acadApp.Documents.Open() when acadApp is running in background

    Quote Originally Posted by Ed Jobe View Post
    Its standard Windows functionality to make an app active when you open a document in the app. You can activate the application you want to have focus. If you want acad to have focus, use "acadApp.Activate". If you want excel to be active use "Application.ActivateMicrosoftApp myXlVar".
    Thanks Ed,
    I realized the title of the thread could be misleading: I don't want to focus on excel or autocad, but keep runing them in background end keep the focus on another application (ie explorer, firefox, resophnotes, etc).
    I understand that windows tries to activate the app, but since the app is not visible I simply lose focus and no other application gains it.
    I also found that with windows 7 I can no longer change the ForegroundLockTimeout registry value to prevent windows stealing focus(in fact, it's already set to 200000 milliseconds).
    In the autodesk forum there's a discussion about Autocad 2010/2011 Stealing focus while doing a background publish (which I also experience in the last step of the macro). It seems I'll have to wait the macro to complete without doing any active work... Bummer.

  4. #4
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,420
    Login to Give a bone
    0

    Default Re: how to prevent losing focus on acadApp.Documents.Open() when acadApp is running in background

    I understand now. Depending on what you want to do, .NET gives you some other options. If plotting is one of the tasks, I'm afraid that you are always going to need the graphical editor running in order to generate the plot. Adesk has autocad core running in the cloud. You could use that service to process your dwgs. You can also script the core. See this article. I haven't tried it, so I don't know if it would solve your problem, but you might find it useful.
    C:> ED WORKING....


    LinkedIn

Similar Threads

  1. 2012: Windows losing Focus running on Parallels
    By beibert400585 in forum AutoCAD General
    Replies: 0
    Last Post: 2012-03-21, 02:05 PM
  2. 2011: Properties palette losing focus
    By ordengate in forum AMEP General
    Replies: 0
    Last Post: 2010-10-05, 03:55 PM
  3. 2011: Focus Change when Background Plotting...
    By Ogre in forum AutoCAD General
    Replies: 1
    Last Post: 2010-04-21, 11:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •