Switch focus to another program

Switch focus to another program

carlos_m_gil_p
Advocate Advocate
3,348 Views
39 Replies
Message 1 of 40

Switch focus to another program

carlos_m_gil_p
Advocate
Advocate

Hello guys, how are you?

 

Today I'm writing to see if you can help me with this question I have.

 

Is there a way to change focus using AutoLISP or Visual LISP to change the program currently being used?

For example:

I need to select some lines in AutoCAD. Once they're selected, you don't have to do anything else. Then you switch to another program that's already open, because this program works on the lines selected in AutoCAD.

I know how to select the lines; what I don't know is how to switch to the other open program.
If anyone could help me with this, I'd appreciate it.

 

Regards.
Excuse my English, I only speak Spanish.


AutoCAD 2026.1.1
Visual Studio Code 1.105.1
AutoCAD AutoLISP Extension 1.6.3
Windows 10 - 22H2 (64 bits)

0 Likes
3,349 Views
39 Replies
Replies (39)
Message 2 of 40

pendean
Community Legend
Community Legend

@carlos_m_gil_p  is using Window's own ALT+TAB function not a viable option?

Or the Windows taskbar tabs?

Message 3 of 40

paullimapa
Mentor
Mentor

If app is started using lisp you can try these minimize and then maximize functions on that app to bring that app on top as mentioned here

https://www.cadtutor.net/forum/topic/86226-returning-focus-to-excel-after-lisp-ends/

 

 

(vla-put-windowstate (vlax-get-acad-object) acMin)
(vla-put-windowstate excelApp acMax)

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 4 of 40

carlos_m_gil_p
Advocate
Advocate

Hi @pendean how are you? Thanks for responding.
I'm currently doing that, but I wanted to see if it could be done directly from Lisp.


AutoCAD 2026.1.1
Visual Studio Code 1.105.1
AutoCAD AutoLISP Extension 1.6.3
Windows 10 - 22H2 (64 bits)

0 Likes
Message 5 of 40

carlos_m_gil_p
Advocate
Advocate

Hi @paullimapa how are you? Thanks for responding too.
In this case, I wouldn't need to minimize the window because the other program's window is small.
I had seen that post, but since it refers to Excel, I didn't find much sense in what I'm trying to do.


AutoCAD 2026.1.1
Visual Studio Code 1.105.1
AutoCAD AutoLISP Extension 1.6.3
Windows 10 - 22H2 (64 bits)

0 Likes
Message 6 of 40

ec-cad
Collaborator
Collaborator

Perhaps, Diminish Acad's window, and the other open program, so they are side-by-side.

In Acad, select / copyclip, in other program, paste ?

 

ECCAD

Message 7 of 40

autoid374ceb4990
Collaborator
Collaborator

I do not know if this will work the newer versions of AutoCAD, but here is how I did it in R14.

Lets say you want to run a program named "Blender.exe".

Create a batch file named bl.bat with two lines of code.

1st line:     "cd\path name\"                   path name is the path to the blender.exe program. Don't type the quotes

2nd line:    "blender"                                blender is the name of the .exe program you want to run. Don't type the quotes

So the batch file will look something like this:

 

cd\program files\blender

blender

 

Save the bl.bat file in the folder which is the default folder when AutoCAD is running.

 

On the command line type  (command  "._shell" "bl")  and see if the program runs.  If so, add this line to your LSP code when you want it to run the other program.

Message 8 of 40

carlos_m_gil_p
Advocate
Advocate

Hi @ec-cad thanks for responding.
Of course, I can have them nearby, but I usually use several programs at the same time, which is why I use Alt + Tab.
In Acad, I only select the entities. When I go to the other program, it has commands. When you activate one, it modifies the entities previously selected in Acad.
The interesting thing about this is seeing how it can also be used for other programs. Many people work with Excel or other types of programs, and this can also be very helpful.


AutoCAD 2026.1.1
Visual Studio Code 1.105.1
AutoCAD AutoLISP Extension 1.6.3
Windows 10 - 22H2 (64 bits)

0 Likes
Message 9 of 40

carlos_m_gil_p
Advocate
Advocate

Hi @autoid374ceb4990 thanks for your help.
I tried it, but it doesn't switch focus between programs.
Because it sends it to open and only flashes on the taskbar.


AutoCAD 2026.1.1
Visual Studio Code 1.105.1
AutoCAD AutoLISP Extension 1.6.3
Windows 10 - 22H2 (64 bits)

0 Likes
Message 10 of 40

autoid374ceb4990
Collaborator
Collaborator

You might try it manually.  Use the SHELL command and see if you get a stable command window, then navigate to the program folder and enter the program name.

Message 11 of 40

Moshe-A
Mentor
Mentor

@carlos_m_gil_p hi,

 

I need to select some lines in AutoCAD. Once they're selected, you don't have to do anything else. Then you switch to another program that's already open, because this program works on the lines selected in AutoCAD.

 

Can you elaborate more on that?

what is the other program you are switching to?

how exactly the selected objects are recognized by the other program?

 

As far as i know there is 2 options an external program can recognize objects:

1. clip borad

2. write out the handles of the selected objects.

 

are you using the above?

 

Moshe

 

Message 12 of 40

ec-cad
Collaborator
Collaborator

Maybe in Acad, you can set a Function Key - say F4 to simulate a Alt-Tab sequence.

I know in R14 you could redefine those Keys, except F1. Maybe Google it.

ECCAD

Message 13 of 40

Sea-Haven
Mentor
Mentor

I read write Excel all the time and went around in circles trying to figure out how to jump to Excel from CAD, I used a Alert to stop the CAD which asked go to the Excel, do something then go back to CAD and press Ok on the alert to keep going. I tried Powershell options but  could not find anything that could be called from CAD, I say CAD as I use Bricscad for testing.

 

@paullimapa the acmax just sets the Excel to maximum size not make it the current window. When used the Excel just maximises but it is not at front I still have other windows over the top of it. I found some help AutoCAD LT 2024 Help | About Controlling the Application Window (ActiveX) | Autodesk the widowtop I think is what I want but does not work with my Bricscad. Returns windowtop not available. Acmax works.

(vla-put-WindowTop myxl 0)

A bit more testing it looks like problem is in call windowtop as a function of Excel as Acmax works fine, widow top when calling acadobj works.

Message 14 of 40

autoid374ceb4990
Collaborator
Collaborator

@carlos_m_gil_p wrote:

"I tried it, but it doesn't switch focus between programs.
Because it sends it to open and only flashes on the taskbar.


 You might also try putting a PAUSE command in the BAT file just to see if the BAT file is working correctly, like this:

 

PAUSE

cd\program files\blender

PAUSE

blender

PAUSE

Message 15 of 40

pendean
Community Legend
Community Legend

@carlos_m_gil_p wrote:

...I'm currently doing that, but I wanted to see if it could be done directly from Lisp.


BUT... you'll have the exact same challenge/problem in all the other programs too, will you not?

 

Or do you only ever want to jump once in a while to another program in AutoCAD but never go back?

 

AKA you need a quicker OS solution, not a "lisp only in AutoCAD to use one way" solution. Or third party like this and a dozen others

https://github.com/sigoden/window-switcher

or

https://www.microcenter.com/site/mc-news/article/win-11-switch-apps.aspx#:~:text=Virtual%20Desktops%...

 

Happy Cadding!

Message 16 of 40

carlos_m_gil_p
Advocate
Advocate

Hello, how are you?
Thanks everyone for your comments.
So far, I haven't found a direct solution.
In this case, the program you want to focus on isn't relevant.
Well, I don't need to go back, just go to a specific one.

Because I don't need to copy and paste, just go to the program.
I tried the option autoid374ceb4990 gave me, but it tends to open the program and not focus on it.
I also found this other option in a batch file, but I don't understand why you have to pause it; otherwise, it won't work.
And it doesn't make sense to keep clicking OK on the Shell window to do it.
So far, using Alt+Tab is still the best option.
I don't know if you can add the batch text directly to the Shell command to see how it works, but I don't know how to do it; I'm not that experienced.
In this case, I'm testing it with Notepad, but it's worked for me with different programs.

 

Powershell -command "$wshell = New-Object -ComObject wscript.shell ; $wshell.AppActivate('notepad')"

pause

 


AutoCAD 2026.1.1
Visual Studio Code 1.105.1
AutoCAD AutoLISP Extension 1.6.3
Windows 10 - 22H2 (64 bits)

0 Likes
Message 17 of 40

autoid374ceb4990
Collaborator
Collaborator

I suggested adding the The PAUSE commands just to see the  if the commands in the batch file were being executed properly.  If the batch file worked correctly with the PAUSE commands, just remove the PAUSE commands.

You can add to the SHELL command, for example:  ( command "Shell" "notepad") will run the Windows NOTEPAD program.

What is the full name of the program you are trying to run, including the extension, like EXE, COM, BAT?

What is the full path to the program you are trying to run into which you are transferring the AutoCAD data?

Please post the BAT file that you created.

Message 18 of 40

Sea-Haven
Mentor
Mentor

@autoid374ceb4990 I think your missing the request its not open an existing application its jump to that already open application to do something. I did my testing with Excel and had no problems talking to Excel like maximize it, but I could not jump to it and make it the current on top window, but I could make Cad current and on top. I spent a fair amount of time looking into powershell which had stuff like make current window but I could not get a bat or shell function to work when called from CAD.

Message 19 of 40

autoid374ceb4990
Collaborator
Collaborator

I understand what you are saying, but with my old R14 version working in 64 bit Windows 7, the batch file approach that I suggested works just fine with the Blender program.  It jumps right to the top whether it is open not. Also works with Wordpad, Notepad, Word, Excel.  Did you try the batch file approach with Excel?

I would still be interested in knowing what program the OP is using to utilize the AutoCAD data and how the data is transferred.

Message 20 of 40

carlos_m_gil_p
Advocate
Advocate

Hi, how have you been?

 

@autoid374ceb4990 The program I use is Cadisi, which is for tensile structures, but it's very old and no longer available, which is why I didn't emphasize the name.
When I try your option, it always opens a new Blender and doesn't jump to the one already open.

I don't know the Excel batch method.

And the bat that I put, only the name of the program is changed, instead of being notepad, the one that is needed is put.
I use Windows 10 64-bit and AutoCAD 2025.


Hi @Sea-Haven Thank you so much for taking the time to look at this.

I've tried this too, but it's not easy.
So far, Alt+Tab is still the best option.


AutoCAD 2026.1.1
Visual Studio Code 1.105.1
AutoCAD AutoLISP Extension 1.6.3
Windows 10 - 22H2 (64 bits)

0 Likes