TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: mkweaver on February 13, 2024, 05:01:21 PM

Title: create-object with windows explorer
Post by: mkweaver on February 13, 2024, 05:01:21 PM
I can open an explorer window to a path with this:  (startapp "Explorer"(strcat "/N, " pathname))
But if there is a window already open to that path, then I just want to activate it, not open a duplicate window.

Suggestions appreciated.
Title: Re: create-object with windows explorer
Post by: MickD on February 13, 2024, 08:56:25 PM
I'm not sure it can be done, I just had a look and a play with powershell with no luck.
https://superuser.com/questions/1787789/command-line-to-have-windows-explorer-open-folder-in-existing-instance-of-explor

anyway, I'd look up the command flags for explorer and try to get it working in cmd or powershell then you're all but done (if it can be done...) :)

Title: Re: create-object with windows explorer
Post by: Lee Mac on February 14, 2024, 04:32:41 AM
You might try the AppActivate method of the WSH -
https://learn.microsoft.com/en-us/previous-versions//wzcddbek(v=vs.85)
Title: Re: create-object with windows explorer
Post by: mkweaver on February 14, 2024, 12:37:23 PM
Lee Mac and MickD,
Thanks for the suggestions.  I found something that may help, though it is a bit dated (refers to IE): https://learn.microsoft.com/en-us/windows/win32/shell/developing-with-windows-explorer

Quote
Open explorer windows can be discovered and programmed by using IShellWindows (CLSID_ShellWindows)...

I think using WSH to access this I'll be able to do what I want.

I'll post back what I find.
Title: Re: create-object with windows explorer
Post by: PKENEWELL on February 14, 2024, 01:08:05 PM
I've been using this for years:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:EXPLORE ()
  2.    (if (= (getvar "dwgtitled") 1)
  3.       (startapp (strcat "explorer.exe /e,/select,\"" (getvar "dwgprefix") (getvar "dwgname") "\""))
  4.       (startapp (strcat "explorer.exe /e,\"" (getvar "dwgprefix") "\""))
  5.    )
  6.    (princ)
  7. )
  8.  
Title: Re: create-object with windows explorer
Post by: ronjonp on February 14, 2024, 03:48:23 PM
Lee Mac and MickD,
Thanks for the suggestions.  I found something that may help, though it is a bit dated (refers to IE): https://learn.microsoft.com/en-us/windows/win32/shell/developing-with-windows-explorer

Quote
Open explorer windows can be discovered and programmed by using IShellWindows (CLSID_ShellWindows)...

I think using WSH to access this I'll be able to do what I want.

I'll post back what I find.
This has been bugging me for years as well! I may have found the solution today ( works on my computer Win 11, Version 10.0.22631 Build 22631) A simple mod from 'explore to 'open.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:cd (/ _opendirectory)
  2.   (defun _opendirectory (path / sa)
  3.     (cond ((and (eq 'str (type path))
  4.                 (findfile (vl-string-right-trim "\\" path))
  5.                 (setq sa (vlax-create-object "Shell.Application"))
  6.            )
  7.            ;; ;; RJP » 2024-02-14
  8.            ;; Using 'open vs 'explore will not open multiple windows with the same path
  9.            (vlax-invoke sa 'open path)
  10.            (vlax-release-object sa)
  11.           )
  12.     )
  13.     (princ)
  14.   )
  15.   (_opendirectory (getvar 'dwgprefix))
  16. )
Title: Re: create-object with windows explorer
Post by: mkweaver on February 14, 2024, 05:17:10 PM
Quote
This has been bugging me for years as well! I may have found the solution today ( works on my computer Win 11, Version 10.0.22631 Build 22631) A simple mod from 'explore to 'open.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:cd (/ _opendirectory)
  2.   (defun _opendirectory (path / sa)
  3.     (cond ((and (eq 'str (type path))
  4.                 (findfile (vl-string-right-trim "\\" path))
  5.                 (setq sa (vlax-create-object "Shell.Application"))
  6.            )
  7.            ;; ;; RJP » 2024-02-14
  8.            ;; Using 'open vs 'explore will not open multiple windows with the same path
  9.            (vlax-invoke sa 'open path)
  10.            (vlax-release-object sa)
  11.           )
  12.     )
  13.     (princ)
  14.   )
  15.   (_opendirectory (getvar 'dwgprefix))
  16. )

That is exactly the behavior I wanted!  Thanks!  Now I need to dig through some of my older code and switch to this.
Title: Re: create-object with windows explorer
Post by: ronjonp on February 14, 2024, 05:20:02 PM
Quote
This has been bugging me for years as well! I may have found the solution today ( works on my computer Win 11, Version 10.0.22631 Build 22631) A simple mod from 'explore to 'open.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:cd (/ _opendirectory)
  2.   (defun _opendirectory (path / sa)
  3.     (cond ((and (eq 'str (type path))
  4.                 (findfile (vl-string-right-trim "\\" path))
  5.                 (setq sa (vlax-create-object "Shell.Application"))
  6.            )
  7.            ;; ;; RJP » 2024-02-14
  8.            ;; Using 'open vs 'explore will not open multiple windows with the same path
  9.            (vlax-invoke sa 'open path)
  10.            (vlax-release-object sa)
  11.           )
  12.     )
  13.     (princ)
  14.   )
  15.   (_opendirectory (getvar 'dwgprefix))
  16. )

That is exactly the behavior I wanted!  Thanks!  Now I need to dig through some of my older code and switch to this.
Cheers!