BIGAL Posted May 2 Posted May 2 (edited) I don't understand, if you set support paths, then the CAD can find your files. When you say filter out right one. Then as you made them you should know their name. It sounds like what you want is a proper way to run them, Pop Menu, ToolBar, Ribbon, orTool Palette. This POP menu has around 130 lisps behind it and they are loaded only when you click on an option. Yes they are individual lisps not one great big one. Just a final comment we had a Word DOC called "How to" and it had an explanation on how to use our lisps, in the doc was pictures to help explain. Edited May 2 by BIGAL Quote
Steven P Posted May 3 Posted May 3 I think there are a few solutions that will work for you. Basis would be to set up a shared folder all the CAD users can access into which you can save your LISP files. Considering how often this folder will be moved or renamed, hard coding the shared folder path is no big deal. In that folder you can have a 'run on demand' LSP file and add that LISP to the startup suit (example below) In that folder you can have a 'Load All' LSP and add that LISP to the startup suit (examples in thread above) You can send your users a small LISP file to add trusted locations to their CAD setup, your sharedfile can be a trusted location as BIGAL suggested (example below) Once they are in that location you can talk nice to BigAl and he might share his menu to give a nice user interface Run on demand example. Copy and modify for every LISP: A bit for work to do if lots of LISPS (defun c:0,0 ( / ) ;; duplicate of a LISP name (load "C:\\Users\\SP\\OneDrive\\Desktop\\AutoCAD\\AutoCAD LISPS\\SIMPLELISP.lsp") ;; Load file that the 'real' c:0,0 is saved in (c:0,0) ;; Run 0,0 (princ) ;; exit quietly ) Load All LISP examples: See SWL 'LoadLisp' SP 'Appreload' Trusted Locations LISP example: (defun AddTrustedLocation ( / oldtrust newtrust) (setq oldtrust (getvar 'trustedpaths)) ;; get existing trusted locations (setq newtrust (strcat oldtrust ";" "NewTrustedLocation")) ;; Append new trusted location: Remember full file path plus double \s (setvar 'trustedpaths newtrust) ;; set new trusted locations ) (AddTrustedLocation) Which you can e-mail to the CAD team, they can drag and drop the file into the command line to install and run the LISP (last line run the LISP) Quote
Fidelojo Posted May 5 Author Posted May 5 On 5/3/2025 at 1:41 AM, BIGAL said: When you say filter out right one. Then as you made them you should know their name. Yes, when I was writing the post I had the idea to filter based on "something" but that something in every case seems to be the script name, so yeah, my bad, sorry. I did a bit of researching and trying during a weekend but on every try/idea it boiled down to needing a script name on which script can be identified, I even tried capturing terminal output after the script is drag'n'droped, it worked, but it didn't cover the case when the script it's just added to the startup suite, in that case the script is added and will be loaded when next drawing is opened but there's no info about the path or anything because the script isn't loaded even once, for that case it requires to hard code the name into the code and search for the name in the registry. So I guess its not possible to achieve for a script to get info about its path and name using only AutoLISP. On 5/3/2025 at 11:23 PM, Steven P said: Basis would be to set up a shared folder all the CAD users can access into which you can save your LISP files. Considering how often this folder will be moved or renamed, hard coding the shared folder path is no big deal. For now I probably go with this solution, thanks. I'll continue searching for a solution and I'll post it here if I find one. Thanks all for help! 1 Quote
rlx Posted May 5 Posted May 5 maybe look into LOGFILEON command. You can inspect this file that saves a drawing's command history and Sherlock Holmes your way from there , looking for all script commands and if no path is specified it means findfile must be able to find it and then you can look if another script is called from this scriptfile etc. Not sure why you need this though. 1 Quote
Steven P Posted May 5 Posted May 5 rlx, does logfileon record LISPs from the startup suit (May Day holiday here, so not checking, CAD is off till tomorrow) Quote
rlx Posted May 5 Posted May 5 If I remember correctly it records all command prompts. I used it once to get a list of all setvars and compare it between drawings. Have some snippits on my laptop , maybe more on my work computer ;;; make assoc list for all setvar names '(("name" . 1)...("name" . 0)) where 1 means read-only (setq lst (getsetvar)) (defun getsetvar ( / oqa fn fp s l ro) (setq fn (getvar 'logfilename) oqa (getvar 'qaflags))(setvar 'qaflags 2) (vl-catch-all-apply 'vl-cmdf (list "logfileon" "setvar" "?" "*" "logfileoff"))(gc)(gc) (if (and (findfile fn) (setq fp (open fn "r"))(setq s (read-line fp))) (progn (while (/= (last (vl-remove 32 (vl-string->list s))) 42)(setq s (read-line fp)))(setq s (read-line fp)) (while (and (setq s (read-line fp)) (/= s ""))(if (wcmatch s "*(read only)") (setq ro 1) (setq ro 0)) (setq l (cons (cons (car (SplitStr s " ")) ro) l)))) ) (if fp (close fp))(setvar 'qaflags oqa) (reverse l) ) ; (SplitStr "a,b" ",") -> ("a" "b") (defun SplitStr (s d / p) (if (setq p (vl-string-search d s))(cons (substr s 1 p)(SplitStr (substr s (+ p 1 (strlen d))) d))(list s))) (defun t1 ( / logfile-fn logfile-fp inp lst vlist result) ;;; (startapp "notepad" (getvar 'logfilename)) (setq logfile-fn (getvar 'logfilename)) (setvar 'qaflags 2) (vl-catch-all-apply 'vl-cmdf (list "logfileon" "setvar" "?" "*" "logfileoff")) ;(vl-catch-all-apply 'vl-cmdf (list "setvar" "?" "*")) ;(vl-catch-all-apply 'vl-cmdf (list "logfileoff")) (gc)(gc) ;;; (startapp "notepad" logfile-fn) (if (and (findfile logfile-fn) (setq logfile-fp (open logfile-fn "r"))) (progn (setq inp (read-line logfile-fp)) ;;; read until input ends with "*" (code 42) "Enter variable(s) to list <*>: *" (while (/= (last (vl-string->list inp)) 42) (setq inp (read-line logfile-fp))) ;;; skip next empty line (setq inp (read-line logfile-fp)) ;;; read until end of file (while (and (setq inp (read-line logfile-fp)) (/= inp "")) (if (wcmatch inp "*(read only)") (setq read-only 1) (setq read-only 0)) (setq lst (cons (cons (car (SplitStr inp " ")) read-only) lst)) ) ) ) (if logfile-fp (progn (close logfile-fp) (gc))) (setq vlist (reverse lst)) ;;; test if assoc works (jip) (setq result (assoc "ACADVER" vlist)) (princ) ) 1 Quote
BIGAL Posted May 6 Posted May 6 (edited) Use Logfileoff to stop log recording. Else you will end up with a massive file. Its saved in your temp directory Options File Temporary Prefix. I reset mine. This shows all commands current. (atoms-family 0) have logfile on. Its a big list. Edited May 6 by BIGAL 1 Quote
Fidelojo Posted May 6 Author Posted May 6 (edited) 13 hours ago, Steven P said: rlx, does logfileon record LISPs from the startup suit (May Day holiday here, so not checking, CAD is off till tomorrow) Just tried and since loading a file via Startup Suite doesn't have any output into the terminal, unfortunately it also doesn't write anything into the log file, unlucky (vl-catch-all-apply 'vl-cmdf (list "logfileon" "setvar" "?" "*" "logfileoff")) Just a question, I suppose that this code opens and closes drawings log file, can the same be achieved using (setvar 'logfilemode 1) and (setvar 'logfilemode 0)? I mean I tried, and it works, but is there maybe some difference when using one or another? Edited May 6 by Fidelojo Quote
rlx Posted May 6 Posted May 6 That's right. I just wrote it that wasy so it fits in one line , one size fits all... it starts recording the prompts , list all setvars and then stops the recording because just like Bigal said , if you dont , file can go Godzilla. Its only meant for temp use. Before you begin mission impossible The Final Reckoning condersider starting clean by using (if (setq fn (findfile (getvar 'logfilename))) (vl-filename-delete fn)) 1 Quote
Steven P Posted May 6 Posted May 6 I guess also the logfile lisp is good... if it loads first and runs before anything else is loaded. If LISPs are loaded before it runs it will miss then... so save the file name as say '0_ALogFile' it might load it first Quote
Fidelojo Posted May 6 Author Posted May 6 (edited) I will probably go with some kind of "loader lisp" which will be made for drag-and-drop, then the user will be prompted to pick main lisp file using 'getfiled' and then the file will be added to Trusted paths and Startup suite with something like this, and also loader script will make some kind of info file for the main script to help it self-identify in the future. The loader would find itself with something like this: (vl-load-com) (defun LM:sendkeys ( keys / wsh ) (setq wsh (vlax-create-object "wscript.shell")) (vl-catch-all-apply 'vlax-invoke (list wsh 'sendkeys keys)) (vlax-release-object wsh) (princ) ) (defun _GetClipBoardText ( / htmlfile result ) ;; Attribution: Reformatted version of ;; post by Patrick_35 at theswamp.org. ;; ;; See http://tinyurl.com/2ngf4r. (setq result (vlax-invoke (vlax-get (vlax-get (setq htmlfile (vlax-create-object "htmlfile")) 'ParentWindow ) 'ClipBoardData ) 'GetData "Text" ) ) (vlax-release-object htmlfile) result ) (LM:sendkeys "{UP}") (setvar 'cmdecho 0) (command "delay" 100) (setvar 'cmdecho 1) (LM:sendkeys "^+{HOME}^{X}") (setq lastCommand (_GetClipBoardText)) (setq lispPath (substr lastCommand (vl-string-search "\"" lastCommand)) lispPath (substr lispPath 1 (length (member 34 (reverse (vl-string->list lispPath))))) lispPath (vl-string-trim "\" " lispPath)) (princ lispPath) (princ (vl-filename-base lispPath)) (princ (vl-filename-directory lispPath)) (princ "Loaded!") (princ) And all of that would be packed into a single folder with other lisps, so any user can just drag and drop loader, pick main script (or maybe even not since they are in the same folder, still thinking about it) and then all of script will be loaded via the main script in the future. I have still most of the code to write but that's the basic idea. Imo feels like little to much and still prone to some errors (or some uncovered outcomes), but for some end user who know nothing about AutoLISP etc. it might be just the right thing. Edited May 6 by Fidelojo Quote
rlx Posted May 6 Posted May 6 If I understand correctly , you wish all users fishing in the same pond? If so , that would be like a standard (network) profile. Just make a shortcut with acad.exe /P <your profile>. Of course easy to bypass for not so green anymore users , but good enough for starters. Quote
Fidelojo Posted May 6 Author Posted May 6 2 hours ago, rlx said: If I understand correctly , you wish all users fishing in the same pond? If so , that would be like a standard (network) profile. Just make a shortcut with acad.exe /P <your profile>. Of course easy to bypass for not so green anymore users , but good enough for starters. That could work but the problem is we don't all use same CAD software (from same vendor) so the loader would be more universal solution, but thanks for the idea Quote
BIGAL Posted May 7 Posted May 7 I still think your miss understanding using custom menu's, where I worked we had LT, Autocad and CIV3D so a CIV3d menu is no good to a LT user. You can do an install lisp and check what version of software is being used Includes Bricscad, Intellicad Zwcad etc. Then install the correct menu's. You can use a usb, an email or on a network even easier to run the install. Then the menu will have the commands/lisps named the way you want. Quote
Fidelojo Posted May 7 Author Posted May 7 5 hours ago, BIGAL said: I still think your miss understanding using custom menu's, where I worked we had LT, Autocad and CIV3D so a CIV3d menu is no good to a LT user. You can do an install lisp and check what version of software is being used Includes Bricscad, Intellicad Zwcad etc. Then install the correct menu's. You can use a usb, an email or on a network even easier to run the install. Then the menu will have the commands/lisps named the way you want. Sorry, I don't really understand what you mean on "custom menus", are you referring to this previous post of yours: On 5/3/2025 at 1:41 AM, BIGAL said: This POP menu has around 130 lisps behind it and they are loaded only when you click on an option. Yes they are individual lisps not one great big one. In my case I planned on just loading multiple scripts via main script which would contain some Info/Help command that would display a popup containing description about all scripts loaded from it, at least that's an idea, do you think popup menu would be better or easier solution? Quote
Steven P Posted May 7 Posted May 7 (edited) Had some time just then, not sure if this is really what you want. E-mail this to the users, they can drag and drop the file into the command line. It should autorun. First part grabs that users support path, searching for support path folders with 'support' and not 'ENU' in the path (you can adjust this to suit), taking the first path it finds. Asks user to select a folder for their LISPs, this can be removed and for example hard coded to your company LISP library Creates and saves a LISP file "Appreload" into the support path which will load all the LISP files in the above Lisp Folder when it runs. You can adjust this to run on demand or a (BigAl) menu system. Dinner time now... only thing to add is function to autorun the LISP 'appreload' (defun Installer ( / f s n SP SupportLisp LP) ;; Sub functions (defun LM:str->lst ( str del / pos ) ;;Lee Mac (if (setq pos (vl-string-search del str)) (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del)) (list str) ) ) (defun LM:lst->str ( lst del ) (if (cdr lst) (strcat (car lst) del (LM:lst->str (cdr lst) del)) (car lst) ) ) (defun LM:browseforfolder ( msg dir bit / err fld pth shl slf ) (setq err (vl-catch-all-apply (function (lambda ( / app hwd ) (if (setq app (vlax-get-acad-object) shl (vla-getinterfaceobject app "shell.application") hwd (vl-catch-all-apply 'vla-get-hwnd (list app)) fld (vlax-invoke-method shl 'browseforfolder (if (vl-catch-all-error-p hwd) 0 hwd) msg bit dir) ) (setq slf (vlax-get-property fld 'self) pth (vlax-get-property slf 'path) pth (vl-string-right-trim "\\" (vl-string-translate "/" "\\" pth)) ) ) ) ) ) ) (if slf (vlax-release-object slf)) (if fld (vlax-release-object fld)) (if shl (vlax-release-object shl)) (if (vl-catch-all-error-p err) (prompt (vl-catch-all-error-message err)) pth ) ) (defun GetDesktop ( / script spFolders desktop) (cond ( (setq script (vlax-create-object "WScript.Shell")) (setq spFolders (vlax-get-property script "SpecialFolders") desktop (vlax-invoke-method spFolders 'Item "Desktop") ) (vlax-release-object spFolders) (vlax-release-object script) ) ) desktop ) ;; End subfunctions (setq f (vla-get-files (vla-get-preferences (vlax-get-acad-object))) ) ; Files (setq s (vla-get-supportpath f)) ; Support Path (setq s (LM:str->lst s ";")) ; First in list since it will always be in the list (foreach n s (if (and (wcmatch n "*\\support") ; find support path folder with 'support' in the path (not (wcmatch n "*\\enu\\*") ) ; add exceptions as you find them ) (setq SP (cons n SP)) ;; SP: Support Path eg ...\\Program files\\autodesk\\autocad 2022\\support ) ; end if ) ; end foreach (setq SP (car (reverse SP))) ;; return the first folder with 'support' in its name, excluding exceptions above ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;LP: Asks users to select 'Lisp Path' folder location. Hard code this if required, remember double '\\' (setq LP (LM:browseforfolder "Select LISP directory" (getdesktop) 0)) ;;adjust '(getdesktop)' filepath as required. Hard code a file path here if you want for the LISP library. (setq LP (LM:str->lst LP "\\")) (setq LP (LM:lst->str LP "\\\\")) ;; doubles '\\' in the selected file path. Not needed if LP hard coded instead of (browseforfolder.... ) ;;;;;;;;;;;;;;;;;;;;;;;; ;; For testing, support path is Desktop. ;; (setq SP (getdesktop)) ;; Delete this to add to support path identified ;;;;;;;;;;;;;;;;;;;;;;;; ;; Create a LISP file in Support Path (setq SupportLisp (strcat SP "\\\\LISPFilePaths.lsp")) (if (setq SL (open SupportLisp "w")) (progn (write-line "(vl-load-com)" SL) (write-line ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;" SL) (write-line "(defun c:appreload ( / lspname myfiles acount mylistlength Failedtoload)" SL) (write-line (strcat "(setq myfiles (vl-directory-files \"" LP "\" \"*.lsp\" nil))") SL) (write-line "(setq mylistlength (length myfiles))" SL) (write-line "(setq acount -1)" SL) (write-line "(repeat mylistlength" SL) (write-line "(setq acount (1+ acount))" SL) (write-line "(setq FailedtoLoad (strcat (nth acount myfiles) \" failed to load\"))" SL) (write-line "(load (strcat mylispfolder (nth acount myfiles)) FailedtoLoad)" SL) (write-line ")" SL) (write-line "(princ \"\\n\")" SL) (write-line "(princ mylistlength)" SL) (write-line "(princ \" lsp files loaded from \")" SL) (write-line "(princ mylispfolder)" SL) (write-line "(princ)" SL) (write-line ")" SL) (write-line ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;" SL) (close SL) ;; Close file descriptor ) ;; end PROGN (princ "\nUnable to create Support LISP file.") ;; Else the text file could not be created ) ;; end IF (princ) ) (Installer); Autorun Edited May 7 by Steven P 1 Quote
BIGAL Posted May 8 Posted May 8 (edited) Making a "pop" menu is easy you can make them using notepad. here is some sample code. You have a header section which names the menu, followed by menu options, you can have sub menus and image menus, also toolbar menu's. If you provide a list of lisp program names and the command name I can attempt to make you a mnu file. eg lispname = MYDOCIRC.lsp command DOCIRC ***MENUGROUP=STDS ***POP20 **CADLIB [->LISP1 A-B] [1/4 POINTS]^C^C(LOAD "1-4 POINTS") [Add 2 Level]^C^C(LOAD "add-to-levels") [Add-pits-drain]^C^C(LOAD"Add-pits-drain") [Allbylayer]^C^C(LOAD "Allbylayer") [Apndtext]^C^C^p(LOAD "apndtext") [Apparent int]^C^C^p(LOAD "apparent int") [Area-label]^C^C^p(LOAD "area-label") Edited May 8 by BIGAL 1 Quote
Fidelojo Posted May 8 Author Posted May 8 20 hours ago, Steven P said: Had some time just then, not sure if this is really what you want. E-mail this to the users, they can drag and drop the file into the command line. It should autorun. Looks very well, thanks for the time! Currently I don't have much time for coding but I look more detailed into it in the next few days, on the first look it looks very similar to what I need (if not exactly the thing I need), only extra thing I plan to implement is to detect the path from where the loader Lisp is dragged since when the script is dragged the load command is called in terminal (I have that one ready to throw in), only thing that's left is to figure a proper way to add main script to Startup suite via the registry so it works for any cad software (probably not possible, but I'll try to figure that one on my own). One more thing, is it okay to remove function wrap from loader script code since it's must autorun, or that's not a smart thing to do? 10 hours ago, BIGAL said: Making a "pop" menu is easy you can make them using notepad. I make all my Lisp scripts in notepad so no problem 10 hours ago, BIGAL said: If you provide a list of lisp program names and the command name I can attempt to make you a mnu file. eg lispname = MYDOCIRC.lsp command DOCIRC Code sample is more than enough, I don't want to waste anyone's time, I'm here for ideas, rest is on me to figure out. But if I found myself stuck I might ask for some help. Probably wont include popup in this script, but may come handy in the future. Thank you very much for your time and advices! Quote
BIGAL Posted May 9 Posted May 9 (edited) Just another like Steven P I have an install lisp it takes advantage of using a zip file containing all the lisps etc if they need to be saved on individual pc's, using a server is much easier. It makes correct directory, unzips the files, adds support & trusted paths, loads menu's, saves a workspace. I will look at adding the edit registry to add autoload paths, In my install I have a check is it Bricscad or Autocad, so the registry paths will be different but similar. Will post when I have something. This is for Bricscad so if you check first what CAD software is running. (if (> (vl-string-search "BricsCAD" (getvar 'acadver)) 0) (dobricscaddefun) (doAcaddefun) ) Working on this still (setq ver (vl-registry-read "HKEY_CURRENT_USER\\Software\\Bricsys\\BricsCAD" "CURVER")) (setq val (strcat "HKEY_CURRENT_USER\\Software\\Bricsys\\BricsCAD\\" ver "\\en_US\\Profiles\\Default\\Config")) (setq suppath (vl-registry-read val "SRCHPATH")) ; input check and or add new support path newsupath (vl-registry-write val newsupath) Could some please post the equivalent paths for Autocad etc. Edited May 9 by BIGAL 1 Quote
Steven P Posted May 10 Posted May 10 (edited) On 5/9/2025 at 1:09 AM, BIGAL said: Just another like Steven P I have an install lisp it takes advantage of using a zip file containing all the lisps etc if they need to be saved on individual pc's, using a server is much easier. It makes correct directory, unzips the files, adds support & trusted paths, loads menu's, saves a workspace. I will look at adding the edit registry to add autoload paths, In my install I have a check is it Bricscad or Autocad, so the registry paths will be different but similar. Will post when I have something. Could some please post the equivalent paths for Autocad etc. I was having a look at this last night, got the registery key for the startup suite though not sure which of the numbers in the link are user identifiers and which arn't: (vl-registry-read "HKEY_USERS\\---Is this part a user identifier---\\SOFTWARE\\APPDATALOW\\Software\\AutoDesk\\AutoCAD\\R24.1\\CoreUser\\---Is this part a user identifier---\\Profiles\\<<Unnamed Profile>>\\Dialogs\\Appload\\Startup" "NumStartUp") R24.1 is for the AutoCAD version of course Must be doing something wrong though, my registry-read attempts weren't working -EDIT- Read working, forgot to end "" and start "" for the key name (edited above). NumStartUp is the number of files in the startup suite, so add the next key, eg "15Startup" My key values are: %USERPROFILE%\onedrive\desktop\LISPs\MyLisp.lsp Just need to check what are unique identifiers and which arn't Edited May 10 by Steven P Quote
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.