pmxcad Posted September 17, 2011 Share Posted September 17, 2011 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 Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 18, 2011 Share Posted September 18, 2011 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. Quote Link to comment Share on other sites More sharing options...
pBe Posted September 18, 2011 Share Posted September 18, 2011 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? Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 18, 2011 Share Posted September 18, 2011 (edited) 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. LoL Edit: Code revised HTH Edited September 19, 2011 by BlackBox Quote Link to comment Share on other sites More sharing options...
pmxcad Posted September 18, 2011 Author Share Posted September 18, 2011 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 Quote Link to comment Share on other sites More sharing options...
HofCAD Posted September 18, 2011 Share Posted September 18, 2011 (edited) 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 September 18, 2011 by HofCAD Quote Link to comment Share on other sites More sharing options...
pmxcad Posted September 18, 2011 Author Share Posted September 18, 2011 Ooookay........., But where to put the pad? Like: D:\Mijn documenten\lsp\LAYER INST OFF.SCR THANKS Quote Link to comment Share on other sites More sharing options...
HofCAD Posted September 18, 2011 Share Posted September 18, 2011 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. Quote Link to comment Share on other sites More sharing options...
pBe Posted September 19, 2011 Share Posted September 19, 2011 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 Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 19, 2011 Share Posted September 19, 2011 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: Quote Link to comment Share on other sites More sharing options...
pmxcad Posted September 20, 2011 Author Share Posted September 20, 2011 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 Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 20, 2011 Share Posted September 20, 2011 Interesting idea, I can't wait to see it... Quote Link to comment Share on other sites More sharing options...
hosyn Posted July 11, 2020 Share Posted July 11, 2020 HI ITS PASSED SO LONG BUT I CURIOUS, ITS EXAMINED WITH FAVOR RESULT Quote Link to comment Share on other sites More sharing options...
hosyn Posted July 11, 2020 Share Posted July 11, 2020 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.