Jump to content

Recommended Posts

Posted

Hi all, is there a way via Lisp to save a PDF that I opend in the browser? I know the vl-file-copy and startAPP commands. Via start-App I can also open the PDF directly, only I want to save it right away.

This only can be done via the browser... Network related.

Does anyone have an idea?


Thanks in advance.

 

(vl-file-copy "P:\\\\network\\data\\test.pdf"  "C:\\data\\test.pdf")

(startAPP "explorer.exe" "https://network/data/test.pdf" "save???")

 

Posted

Why not just save it to the location from the browser?

 

Seems you could download files with http with old IE but doesn't seem to work with new updates.

 

 

 

Posted

Seems to work with Firefox. I mean who uses IE anyway?  Added a little confirmation at the end.

 

(defun GetFileURL  (url path / utilObj tempPath newPath)
 ;; © RenderMan 2011, CADTutor.net
 ;; Example: (GETFILEURL "https://damassets.autodesk.net/content/dam/estore/customer-service/AutoCAD_Shortcuts_11x8.5_MECH-REV.pdf" (getvar 'dwgprefix))
 (vl-load-com)
 (setq utilObj (vla-get-utility (vla-get-activedocument (vlax-get-acad-object))))
 (if (= :vlax-true (vla-isurl utilObj url))
   (if (vl-catch-all-error-p
         (vl-catch-all-apply
           'vla-GetRemoteFile
           (list utilObj url 'tempPath :vlax-true))
        )
     (prompt "\n  <!>  Error Downloading File From URL  <!> ")
     (progn
       (if (findfile
             (setq newPath
                    (strcat path
                            (vl-filename-base url)
                            (vl-filename-extension url))))
         (vl-file-rename
           newPath
           (setq voidPath
                  (strcat
                    (vl-filename-directory newPath)
                    "\\void_"
                    (vl-filename-base newPath)
                    "_"
                    (menucmd
                      "M=$(edtime,$(getvar,date),YYYY-MO-DD-HH-MM-SS)")
                    (vl-filename-extension newPath)))))
       (vl-file-copy tempPath newPath)
       (vl-file-delete tempPath))
  )
   (prompt "\n  <!>  Invalid URL  <!> "))
 (vl-catch-all-apply 'vlax-release-object (list utilObj))
 (prompt (strcat "\n " newPath " Downloaded"))
 (princ)
)

 

Posted (edited)
On 8/22/2021 at 7:07 AM, mhupp said:

Seems to work with Firefox. I mean who uses IE anyway?  Added a little confirmation at the end.

 

Okay, thanks for the code. I think that's a bit too hard for me to get through.

Where do I set the source folder / destination folder?


AutoCAD returns me error messages: Too few arguments; Fatal error occurred *** Limit of internal stack reached (simulated); ActiveX server returned an error: Parameter not optional; no function definition: URL ...

Edited by Manuel_Kunde
Posted (edited)
4 hours ago, Manuel_Kunde said:

 

Okay, thanks for the code. I think that's a bit too hard for me to get through.

Where do I set the source folder / destination folder?

 

Their is no source folder your downloading the file directly off the internet.

 

4 hours ago, Manuel_Kunde said:

AutoCAD returns me error messages: Too few arguments; Fatal error occurred *** Limit of internal stack reached (simulated); ActiveX server returned an error: Parameter not optional; no function definition: URL ...

 

have the lisp loaded and type this.

(GETFILEURL "https://damassets.autodesk.net/content/dam/estore/customer-service/AutoCAD_Shortcuts_11x8.5_MECH-REV.pdf" (getvar 'dwgprefix))

It will save the "AutoCAD_Shortcuts_11x8.5_MECH-REV.pdf" in your current drawing folder

 

If you want to save it to another location

(GETFILEURL "https://damassets.autodesk.net/content/dam/estore/customer-service/AutoCAD_Shortcuts_11x8.5_MECH-REV.pdf" "C:\\data\\")

C:\data\AutoCAD_Shortcuts_11x8.5_MECH-REV.pdf Downloaded

 

 

But like i said before this seem like its taking 4 steps to save a file that you could do in one step with your browser.

Edited by mhupp
fixed some stuff
  • Like 1
Posted (edited)
14 minutes ago, mhupp said:

 

Their is no source folder your downloading the file directly off the internet.

 

 

have the lisp loaded and type this.

(GETFILEURL "https://damassets.autodesk.net/content/dam/estore/customer-service/AutoCAD_Shortcuts_11x8.5_MECH-REV.pdf" (getvar 'dwgprefix))

It will save the "AutoCAD_Shortcuts_11x8.5_MECH-REV.pdf" in your current drawing folder

 

If you want to save it to another location

(GETFILEURL "https://damassets.autodesk.net/content/dam/estore/customer-service/AutoCAD_Shortcuts_11x8.5_MECH-REV.pdf" "C:\data\"))

C:\data\AutoCAD_Shortcuts_11x8.5_MECH-REV.pdf Downloaded

 

 

But like i said before this seem like its taking 4 steps to save a file that you could do in one step with your browser.

 

Okay, now I'm one step closer.

 

If I write this:
(GETFILEURL "https://damassets.autodesk.net/content/dam/estore/customer-service/AutoCAD_Shortcuts_11x8.5_MECH-REV.pdf" (getvar 'dwgprefix))

Comes this message:
<!> Error Downloading File From URL <!> ; Error: Incorrect argument type: stringp nil.

 

When I write this:
(GETFILEURL "https://damassets.autodesk.net/content/dam/estore/customer-service/AutoCAD_Shortcuts_11x8.5_MECH-REV.pdf" "C:\data\"))

I am prompted for user input:
"(_> *abort*

Edited by Manuel_Kunde
Posted

You cant use this in an unsaved file.

(GETFILEURL "https://damassets.autodesk.net/content/dam/estore/customer-service/AutoCAD_Shortcuts_11x8.5_MECH-REV.pdf" (getvar 'dwgprefix))

 

if your using this C:\data hast to be there.  Also needs \\ in the path I had only single mybad.

(GETFILEURL "https://damassets.autodesk.net/content/dam/estore/customer-service/AutoCAD_Shortcuts_11x8.5_MECH-REV.pdf" "C:\\data\\")

Posted
On 8/23/2021 at 4:03 PM, mhupp said:

(GETFILEURL "https://damassets.autodesk.net/content/dam/estore/customer-service/AutoCAD_Shortcuts_11x8.5_MECH-REV.pdf" (getvar 'dwgprefix))

 

Is it possible to run the download as a command?
I still get the error message:  <!>  Error Downloading File From URL  <!> ; Fehler: Fehlerhafter Argumenttyp: stringp nil

No idea how to fix this..

 

(defun c:browser_pdf ()
  
  (load "GetFileUrl.lsp")

  (vl-load-com)
  (GETFILEURL  "https://damassets.autodesk.net/content/dam/estore/customer-service/AutoCAD_Shortcuts_11x8.5_MECH-REV.pdf" (getvar "DWGPREFIX")) 
  
)

 

Posted

I don't know how to pull urls from the browser. when you say open in the browser is it online or on your hard drive ?

Posted
6 minutes ago, mhupp said:

I don't know how to pull urls from the browser. when you say open in the browser is it online or on your hard drive ?

There should be an address line in the top of your browser. An address (or Universal Resource Locator [URL]) starts with http:// and goes on from there. You can select that string and copy it to your clipboard, then paste it somewhere else.

 

In many cases you can save a PDF directly from the browser. It seems like you're making this much more complicated than it needs to be. Unless you're using some ancient technology.

Posted (edited)
2 hours ago, mhupp said:

I don't know how to pull urls from the browser. when you say open in the browser is it online or on your hard drive ?

 

Online. No matter which browser I use.

When I enter the link like this in my browser, I get to the PDF. But AutoCAD gives me this error message.

 

image.png.18760ae033e695c69de9158ade213243.png

Edited by Manuel_Kunde
Posted (edited)

This lisp will insert the clipboard text as the url. first it will prompt you to pick a folder to save to defaults to the current drawing folder. then it will display a message like this. if the clipboard isn't a valid url it will display a message like this.

"clipboard text" IS NOT A VALID URL

 

then ask you to input one. once a valid url is inputted. it will display the link and ask if you want to download.

"Download? https://www.sportscarmarket.com/guides/SpringSupplement2016_digital.pdf [Yes/No]:"

 

 If you hit yes it will download the file to the folder you selected. defaults to yes.

 

(defun C:Download (/ url path)
  (setq fp (getfiled "Save Location: " (strcat (getvar 'DWGPREFIX) "\\Hit Save to Pick Current folder") "" 33))
  (setq path (strcat (vl-filename-directory fp) "//"))
  (setq url (GetClipText))
  (while (not (vl-string-search "http" url))
    (prompt (strcat "\n\"" url "\" IS NOT A VALID URL"))
    (setq url (getstring "\nPaste URL: "))
  )
  (initget "Yes No")
  (setq a
    (cond
      ((getkword (strcat "\nDownload? \"" url "\" [Yes/No]: "))) ("Yes")
    )
  )
  (if (= "Yes" a)
    (GetFileURL url Path)
  )
)
(defun GetClipText(/ html result)
  (setq html (vlax-create-object "htmlfile")
	  result (vlax-invoke (vlax-get (vlax-get html 'ParentWindow) 'ClipBoardData) 'GetData "Text")
  )
  (vlax-release-object html)
  result
)
(defun GetFileURL  (url path / utilObj tempPath newPath)
 ;; © RenderMan 2011, CADTutor.net
 ;; Example: (GETFILEURL "https://damassets.autodesk.net/content/dam/estore/customer-service/AutoCAD_Shortcuts_11x8.5_MECH-REV.pdf" (getvar 'dwgprefix))
 (vl-load-com)
 (setq utilObj (vla-get-utility (vla-get-activedocument (vlax-get-acad-object))))
 (if (= :vlax-true (vla-isurl utilObj url))
   (if (vl-catch-all-error-p
         (vl-catch-all-apply
           'vla-GetRemoteFile
           (list utilObj url 'tempPath :vlax-true))
        )
     (prompt "\n  <!>  Error Downloading File From URL  <!> ")
     (progn
       (if (findfile
             (setq newPath
                    (strcat path
                            (vl-filename-base url)
                            (vl-filename-extension url))))
         (vl-file-rename
           newPath
           (setq voidPath
                  (strcat
                    (vl-filename-directory newPath)
                    "\\void_"
                    (vl-filename-base newPath)
                    "_"
                    (menucmd
                      "M=$(edtime,$(getvar,date),YYYY-MO-DD-HH-MM-SS)")
                    (vl-filename-extension newPath)))))
       (vl-file-copy tempPath newPath)
       (vl-file-delete tempPath))
  )
   (prompt "\n  <!>  Invalid URL  <!> "))
 (vl-catch-all-apply 'vlax-release-object (list utilObj))
 (princ)
)

 

 

 

Edited by mhupp
added url error handling

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...