Jump to content

Hyperlink to run script


pmxcad

Recommended Posts

Hello,

 

Is it possible to run a script or lisp by a Hyperlink. The idea is to place a rectangle or a text with a hyperlink that runs a script to turn layer groups on or off.

 

Thanks

 

PmxCAD

Link to comment
Share on other sites

I could be wrong, but I believe that adding a hyperlink of a valid file path to either a script, or lisp file will only open the linked file as if double clicked from Windows Explorer.

 

I suspect that you'll need to employ a custom lisp command that will prompt you to select a linked entity, and provided the hyperlink is valid (read the file exists), the code will conditionally load the script, or lisp file respectively.

Link to comment
Share on other sites

Why not use toolbars instead. but thats a good question though. how would you invoke a lisp besides typing/toolbar/menus?

 

You can however hyperlink a *.lnk file with this line as Target:

 "C:\Program Files\AutoCAD 2009\acad.exe" "Trial.dwg" /b "c:\run"

where run isthe script name. but link will open a new session of cad, I guess you may need the proper switch i.e. /t /c etc.. to launch the script on an open drawing.

 

a DIESEL expression perhaps?

Link to comment
Share on other sites

Select an entity, check for URL, then check that URL (filepath) is for a valid file. Upon those checks all returning T Non-Nil, CONDitionally filter for, and *LOAD the applicable file extention.

 

Pseudo code:

(defun c:URLLOAD  (/ e url flag ext)
 ;; © RenderMan, 2011
 (princ "\rURLLOAD ")
 (vl-load-com)
 (if (and (setq e (car (entsel "\nSelect entity to load URL: ")))
          (setq url (geturl e))
          (setq flag (/= "" url))
          (findfile url))
   (cond
     ((= ".LSP" (setq ext (strcase (vl-filename-extension url))))
      (load url))
     ((= ".SCR" ext)
      (command "._script" url))
     ((prompt "\n** Invalid file extention ** ")))
   (cond
     (flag (prompt (strcat "\n** \"" url "\" cannot be found ** ")))
     (e (prompt "\n** Invalid url ** "))
     ((prompt "\n** Nothing selected ** "))))
 (princ))

** Note - Code written from memory, on smartphone. I may have some mistakes/ typos. :oops: LoL

 

Edit: Code revised

 

HTH

Edited by BlackBox
Link to comment
Share on other sites

Hello,

 

Autocad returns: ; error: too few arguments

Iàm not into LISP can you help? I put the pad to the file between the "" marks, is this ok?

 

thanks,

 

pmxcad

Link to comment
Share on other sites

Try:

(defun c:UrlLoad (/ e url flag ext)
 (vl-load-com)
 (if (and (setq e (car (entsel "\nSelect entity to load URL: ")))
   (setq flag (/= "" (setq url (geturl e))))
   (findfile url)
     )
   (cond ((= ".LSP" (setq ext (strcase (vl-filename-extension url))))
   (load url)
  )
  ((= ".SCR" ext) (command "_.SCRIPT" url))
  ((prompt "\n** Invalid file extention ** "))
   )
   (cond (url
   (prompt (strcat "\n** \"" url "\" cannot be found ** "))
  )
  (flag (prompt "\n** Invalid url ** "))
  ((prompt "\n** Nothing selected ** "))
   )
 )
 (princ)
)

 

HofCAD CSI.

Edited by HofCAD
Link to comment
Share on other sites

In the HYPERLINK dialog box you see:

'Text to Display'

and

'Type the File or Web Page Name'.

 

In 'Text to Display' you put: LAYER INST OFF

In 'Type the File or Web Page Name' you put: D:\Mijn documenten\lsp\LAYER INST OFF.SCR

 

HofCAD CSI.

Link to comment
Share on other sites

Select an entity, check for URL, then check that URL (filepath) is for a valid file. Upon those checks all returning T, CONDitionally filter for, and *LOAD the applicable file extention.

 

Pseudo code:

(defun c:URLLOAD ( \ e url flag ext)
 (vl-load-com)....
 

 

 

Nice idea Renderman, I havent thought of that. my line of thinking was run a script from an outside source so to speak.

 

Cool beans

Link to comment
Share on other sites

Nice idea Renderman, I havent thought of that. my line of thinking was run a script from an outside source so to speak.

 

Cool beans

 

Thanks pBe :); I did notice some errors (now that I'm on my work laptop instead of smartphone *doh*), and have revised the code. It works like a charm now! :wink:

 

I've tested both *.LSP, and *.SCR successfully.

 

Example:

 

Command: (seturl (car (entsel)) (findfile "acaddoc.lsp"))


Select object: nil

Command: urlload
URLLOAD
Select entity to load URL:
Loading ACADDOC.lsp...


Command:

Link to comment
Share on other sites

OK,

Works perfect. Came something else on my mind.

Lets take a block with multiline attributes. Name one attribute SCRIPT. And when inserting that block, fill in a script data to that attribute, and run that script with a lisp bij selecting it. Reason, always keep the script in the drawing.

 

Pmxcad

Link to comment
Share on other sites

  • 8 years later...
On 9/20/2011 at 8:32 PM, pmxcad said:

OK,

Works perfect. Came something else on my mind.

Lets take a block with multiline attributes. Name one attribute SCRIPT. And when inserting that block, fill in a script data to that attribute, and run that script with a lisp bij selecting it. Reason, always keep the script in the drawing.

 

Pmxcad

HI

ITS PASSED SO LONG BUT I CURIOUS,  ITS EXAMINED WITH FAVOR RESULT 🤔

IS THAT POSSIBLE TO DO?

Link to comment
Share on other sites

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...