Author Topic: Best way to open pdf in browser in autocad macro  (Read 18552 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Best way to open pdf in browser in autocad macro
« Reply #15 on: June 13, 2013, 10:42:43 AM »
I only have IE on  my machine.

Wow, sometimes it seems like I just don't know you anymore.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Best way to open pdf in browser in autocad macro
« Reply #16 on: June 13, 2013, 10:44:41 AM »
This works great Lee.  Thanks.

Good stuff.  :-)

I only have IE on  my machine.  I am wondering how the order of the list will effect users that have ie, firefox, and chrome?

For each path in the list, the function will attempt to locate the executable file and, if found, will attempt to open the supplied URL. If either the executable cannot be located or the URL cannot be opened, the function will move on to the next path in the list. If the URL is successfully opened, the function will stop evaluating the list.

Hence, if the user has Firefox AND Chrome installed, the URL will be opened in Firefox since this appears first in the list.

ronjonp

  • Needs a day job
  • Posts: 7528
Re: Best way to open pdf in browser in autocad macro
« Reply #17 on: June 13, 2013, 11:15:16 AM »
I only have IE on  my machine.

Wow, sometimes it seems like I just don't know you anymore.


LOL :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Best way to open pdf in browser in autocad macro
« Reply #18 on: June 14, 2013, 04:56:41 AM »
Or using the default browser as per the registry.
Code - Auto/Visual Lisp: [Select]
  1. (defun browser (path / exe)
  2.   (if (and (setq exe (vl-registry-read "HKEY_CLASSES_ROOT\\.htm" ""))
  3.            (setq exe (vl-registry-read (strcat "HKEY_CLASSES_ROOT\\" exe "\\shell\\open\\command" "")))
  4.            (wcmatch exe "\"*\"*")
  5.            (setq exe (substr exe 2 (1- (vl-string-search "\"" exe 1))))
  6.            (setq exe (findfile exe)))
  7.     (startapp exe path)))
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Best way to open pdf in browser in autocad macro
« Reply #19 on: June 14, 2013, 06:52:31 AM »
Or using the default browser as per the registry.

Good idea Irné; though, I thought the default browser would be located using the following:
Code - Auto/Visual Lisp: [Select]
  1. (defun defaultbrowser ( url / exe )
  2.     (if (setq exe (vl-registry-read "HKEY_CURRENT_USER\\Software\\Classes\\http\\shell\\open\\command"))
  3.         (startapp (vl-string-subst url "%1" exe))
  4.     )
  5. )

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Best way to open pdf in browser in autocad macro
« Reply #20 on: June 14, 2013, 06:56:48 AM »
To offer an alternative method using IE:
Code - Auto/Visual Lisp: [Select]
  1. (defun navigateto ( url / ie )
  2.     (if (setq ie (vlax-get-or-create-object "internetexplorer.application"))
  3.         (progn
  4.             (vl-catch-all-apply
  5.                 (function
  6.                     (lambda ( )
  7.                         (vlax-invoke-method ie 'navigate url)
  8.                         (vlax-put-property  ie 'visible :vlax-true)
  9.                     )
  10.                 )
  11.             )
  12.             (vlax-release-object ie)
  13.             url
  14.         )
  15.     )
  16. )

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Best way to open pdf in browser in autocad macro
« Reply #21 on: June 14, 2013, 07:32:44 AM »
Good idea Irné; though, I thought the default browser would be located using the following:
That's true, but there's actually a problem on Windows. There are 5 different places in registry where this is saved:
  • HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.htm\PersistentHandler
  • HKEY_CURRENT_USER\Software\Classes\http\shell\open\command
  • HKEY_CLASSES_ROOT\http\shell\open\command
  • HKEY_CLASSES_ROOT\.html
  • Under Vista+ also: HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice
Officially, HKEY_CLASSES_ROOT\.html is supposed to take whatever is the setting in Windows (per user / machine-wide). Don't know if same goes for HKEY_CLASSES_ROOT\http\shell\open\command. On Vista and above the last setting was also introduced (partly to try and fix this haphazard method).
http://newoldthing.wordpress.com/2007/03/23/how-does-your-browsers-know-that-its-not-the-default-browser/

Perhaps your code, simply using this, might do:
Code - Auto/Visual Lisp: [Select]
  1. (defun defaultbrowser ( url / exe )
  2.    (if (setq exe (vl-registry-read "HKEY_CLASSES_ROOT\\http\\shell\\open\\command"))
  3.       (startapp (vl-string-subst url "%1" exe))
  4.    )
  5. )
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

pBe

  • Bull Frog
  • Posts: 402
Re: Best way to open pdf in browser in autocad macro
« Reply #22 on: June 14, 2013, 09:32:13 AM »
IMO with using a path as argument, Shell.Application" method is a better option than startapp. There was this individual where the company he works for included a "=" chracter on the folder names [for some bizzare resons]
startapp function wont be able to find the correct path. [so it may seems...]
 
 

CADDOG

  • Newt
  • Posts: 82
  • wishbonesr
Re: Best way to open pdf in browser in autocad macro
« Reply #23 on: July 15, 2013, 04:19:09 PM »
... included a "=" chracter on the folder names [for some bizzare resons]
startapp function wont be able to find the correct path. [so it may seems...]

Just in case someone comes across this and wonders why startapp can fail on this unique folder naming ('=').
Actually, the problem comes from the called application's parameter parsing, and not startapp.

Surround the pathing in quotations.
Code: [Select]
(setq filename "c:\\temp\\folder=new\\readme.txt")
(strcat (chr 34) filename (chr 34))

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Best way to open pdf in browser in autocad macro
« Reply #24 on: July 16, 2013, 01:17:26 AM »
Surround the pathing in quotations.
Code: [Select]
(setq filename "c:\\temp\\folder=new\\readme.txt")
(strcat (chr 34) filename (chr 34))
Or just?
Code - Auto/Visual Lisp: [Select]
  1. (setq filename "\"c:\\temp\\folder=new\\readme.txt\"")
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

pBe

  • Bull Frog
  • Posts: 402
Re: Best way to open pdf in browser in autocad macro
« Reply #25 on: July 17, 2013, 10:55:44 AM »
.....
Actually, the problem comes from the called application's parameter parsing, and not startapp.
Egad! .. you are right.. [Ding..ding..ding] 10 points for the house of CADDOG  :)