K Baden Posted November 14, 2019 Posted November 14, 2019 Good morning all, I currently have the below LISP routine which successfully adds the file path i want to add, the only problem is, it deletes the default C drive path that exists. Is there an easy way to just add this path on top of the original default path? I am deploying some palettes to my team but want to ensure that if they already have their own elsewhere, it doesn't delete that path. Any ideas? i just want it to be in addition to any existing paths, rather than overwriting what someone may have there. (defun C:TPPATH () (setq pFiles (vla-get-files (vla-get-preferences (vlax-get-acad-object)))) ;;get file preferences (setq tpPath "-insert new file path here-") ;;set your path here (vla-put-toolPalettePath pFiles tpPath) ;;set tool palette path (princ) ) Quote
dlanorh Posted November 14, 2019 Posted November 14, 2019 28 minutes ago, K Baden said: Good morning all, I currently have the below LISP routine which successfully adds the file path i want to add, the only problem is, it deletes the default C drive path that exists. Is there an easy way to just add this path on top of the original default path? I am deploying some palettes to my team but want to ensure that if they already have their own elsewhere, it doesn't delete that path. Any ideas? i just want it to be in addition to any existing paths, rather than overwriting what someone may have there. (defun C:TPPATH () (setq pFiles (vla-get-files (vla-get-preferences (vlax-get-acad-object)))) ;;get file preferences (setq tpPath "-insert new file path here-") ;;set your path here (vla-put-toolPalettePath pFiles tpPath) ;;set tool palette path (princ) ) You are replacing the existing with the new. You needed to go a bit deeper. Try this (defun C:TPPATH (/ pFiles tpPaths tpPath) (setq pFiles (vla-get-files (vla-get-preferences (vlax-get-acad-object)))) ;;get file preferences (setq tpPaths (vlax-get-property pFiles 'toolpalettepath)); Get the current path(s) (setq tpPath "-insert full new file path here-") ;;set your path here eg "C:\\Users\\....." (vla-put-toolPalettePath pFiles (strcat tpPaths ";" tpPath)) ;;add your new path to the string dividing paths with a ";" (princ) ) 1 Quote
BIGAL Posted November 15, 2019 Posted November 15, 2019 Like dlanorh there are a number of paths that can be multiples in the preferences so the strcat is the way around it. If you want a bit more bullet proof would check if that path exists 1st else will add every time you run. Quote
Sportyyyy Posted February 23, 2020 Posted February 23, 2020 On 11/14/2019 at 10:08 AM, dlanorh said: You are replacing the existing with the new. You needed to go a bit deeper. Try this (defun C:TPPATH (/ pFiles tpPaths tpPath) (setq pFiles (vla-get-files (vla-get-preferences (vlax-get-acad-object)))) ;;get file preferences (setq tpPaths (vlax-get-property pFiles 'toolpalettepath)); Get the current path(s) (setq tpPath "-insert full new file path here-") ;;set your path here eg "C:\\Users\\....." (vla-put-toolPalettePath pFiles (strcat tpPaths ";" tpPath)) ;;add your new path to the string dividing paths with a ";" (princ) ) Hi First, thanks to you guys for posting an incredibly helpful lisp. I'm sort of a newb at this and I'm having a bit of trouble getting it working. Could you tell me what I'm doing wrong? (defun TPPATH (/ pFiles tpPaths tpPath) (setq pFiles (vla-get-files (vla-get-preferences (vlax-get-acad-object)))) ;;get file preferences (setq tpPaths (vlax-get-property pFiles 'toolpalettepath)); Get the current path(s) (setq tpPath "I:\\_CAD STANDARDS\\100 - CAD SUPPORT FILES\\200 - SUPPLEMENTARY FILES\\TOOL PALETTES") ;;set your path here eg "C:\\Users\\....." (vla-put-toolPalettePath pFiles (strcat tpPaths ";" tpPath)) ;;add your new path to the string dividing paths with a ";" (princ) ) I'm just trying to add our network Tool Palette to the bottom of the Tool Palettes Path setting in options (i.e. preserving the default/user palettes. Thanks, M Quote
dlanorh Posted February 23, 2020 Posted February 23, 2020 It works OK for me (AutoCAD 2012), the new path is added. What problems are you having? If you are having problems running it, it is a function and you should type (TPPATH) on the command line. If you want it to act like a normal command you need to change the defun name to (defun C:TPPATH.... Quote
Sportyyyy Posted February 24, 2020 Posted February 24, 2020 (edited) I don't want to be a command. I want it to run automatically at startup (I'd like to add it to my acad.lsp). When I manually load it, it says it loaded successfully but the new path isn't added in the Options window, only the default/OOTB path shows. Am I supposed to remove the ";" from (vla-put-toolPalettePath pFiles (strcat tpPaths ";" tpPath)) ;;add your new path to the string dividing paths with a ";" does the instructions to "add your new path to the string diving paths with a ";" " mean that if I wanted to add additional paths, I'd define a new variable name (setq), and add to the list up top (i.e. after the tpPath in: (defun C:TPPATH (/ pFiles tpPaths tpPath) Asking because I'm curious/want to make sure I understand. I don't actually need a third TP path. Appreciate your help! Edited February 24, 2020 by Sportyyyy Quote
Sportyyyy Posted February 24, 2020 Posted February 24, 2020 FYI, in case I'm unclear, here's what I ultimately want: Quote
Sportyyyy Posted February 24, 2020 Posted February 24, 2020 (edited) Tried both of these but they don't seem to work either. Any tips on what I"m doing wrong? Trying not to get frustrated (managed to get all other pathing lisps to work with the exception of this one - our IT company gave me 48 hours notice they were moving our server so I've spent the last few days cobbling together a bunch of lisps). Appreciate it. (defun TPPATH (/ pFiles tpPaths tpPath) (setq pFiles (vla-get-files (vla-get-preferences (vlax-get-acad-object)))) ;;get file preferences (setq tpPaths (vlax-get-property pFiles 'toolpalettepath)) ;;Get the current path(s) (setq tpPath "%InstallFolder%\\UserDataCache\\Support\\ToolPalette;I:\\_CAD STANDARDS\\100 - CAD SUPPORT FILES\\200 - SUPPLEMENTARY FILES\\TOOL PALETTES") ;;set your path here eg "C:\\Users\\....." (vla-put-toolPalettePath pFiles (strcat tpPaths ";" tpPath)) ;;add your new path to the string dividing paths with a ";" (princ) ) (setq pFiles (vla-get-files (vla-get-preferences (vlax-get-acad-object)))) ;; get file preferences (setq tpPath (vla-get-toolPalettePath pFiles)) ;; get current tool palette path (setq tpPath "%InstallFolder%\\UserDataCache\\Support\\ToolPalette;I:\\_CAD STANDARDS\\100 - CAD SUPPORT FILES\\200 - SUPPLEMENTARY FILES\\TOOL PALETTES") ;; set your path here (vla-put-toolPalettePath pFiles tpPath) ;; set tool palette path (princ) ) Edited February 24, 2020 by Sportyyyy more info Quote
rlx Posted February 24, 2020 Posted February 24, 2020 does the folder you try to add actually exist at his time? (vl-file-directory-p "I:\\_CAD STANDARDS\\100 - CAD SUPPORT FILES\\200 - SUPPLEMENTARY FILES\\TOOL PALETTES") maybe it won't add because it does not exist yet? Also , if this is a network folder can you guarantee everybody uses the same drive letter? Quote
Sportyyyy Posted February 24, 2020 Posted February 24, 2020 I finally found this one that worked but after running it all the Tool Palette groups were lost (including the default C3D ones): (setvar "*_toolpalettepath" (strcat "C:\\Users\\MSmith\\AppData\\Roaming\\Autodesk\\C3D 2018\\enu\\Support\\ToolPalette\\" (chr 59) "I:\\_CAD STANDARDS\\100 - CAD SUPPORT FILES\\200 - SUPPLEMENTARY FILES\\TOOL PALETTES")) Is one way better than the other (i.e. setvar vs. vla)? Is there a way to preserve/restore the default Tool Palette Groups? Quote
Sportyyyy Posted February 24, 2020 Posted February 24, 2020 9 minutes ago, rlx said: does the folder you try to add actually exist at his time? (vl-file-directory-p "I:\\_CAD STANDARDS\\100 - CAD SUPPORT FILES\\200 - SUPPLEMENTARY FILES\\TOOL PALETTES") maybe it won't add because it does not exist yet? Also , if this is a network folder can you guarantee everybody uses the same drive letter? Yes, can guarantee everyone will have same Drive letter. Folder definitely exists. Why would setenv work but the vla one does not? Should also specify that I tried adding this above the VLA code: (vl-load-com) (vl-mkdir "c:\\AcadTEMP") (setq *files* (vla-get-files (vla-get-preferences (vlax-get-Acad-object)))) AND this below the VLA code: (vlax-release-object *files*) ;;; Release the object (princ "All Done") After the code but both of them still failed. Am considering a little day drinking as I don't understand what I'm doing wrong. Quote
ronjonp Posted February 24, 2020 Posted February 24, 2020 (edited) Try something like this: (defun _addtoolpalettepaths (paths / a b) (setq b (getvar (setq a "*_toolpalettepath"))) (setvar a (strcat b (apply 'strcat (mapcar '(lambda (x) (if (vl-string-search (strcase x) (strcase b)) "" (strcat ";" x) ) ) paths ) ) ) ) ) ;; usage (_addtoolpalettepaths '("c:\\path1" "d:\\path2")) *EDIT .. needed to check if path exists or it keeps duplicating. Edited February 24, 2020 by ronjonp 1 Quote
Sportyyyy Posted February 24, 2020 Posted February 24, 2020 (defun _addtoolpalettepaths (paths) (setvar (strcat (getvar "*_toolpalettepath") (apply 'strcat (mapcar '(lambda (x) (strcat ";" x)) paths)) ) ) ) ;; usage (_addtoolpalettepaths "C:\\Users\\" (getenv"Username") "\\AppData\\Roaming\\Autodesk\\C3D 2018\\enu\\Support\\ToolPalette\\" "I:\\_CAD STANDARDS\\100 - CAD SUPPORT FILES\\200 - SUPPLEMENTARY FILES\\TOOL PALETTE") Returns an error: Too many arguments. Quote
ronjonp Posted February 24, 2020 Posted February 24, 2020 (edited) 1 hour ago, Sportyyyy said: (defun _addtoolpalettepaths (paths) (setvar (strcat (getvar "*_toolpalettepath") (apply 'strcat (mapcar '(lambda (x) (strcat ";" x)) paths)) ) ) ) ;; usage (_addtoolpalettepaths "C:\\Users\\" (getenv"Username") "\\AppData\\Roaming\\Autodesk\\C3D 2018\\enu\\Support\\ToolPalette\\" "I:\\_CAD STANDARDS\\100 - CAD SUPPORT FILES\\200 - SUPPLEMENTARY FILES\\TOOL PALETTE") Returns an error: Too many arguments. I updated the code since then. EXAMPLE: (_addtoolpalettepaths '(;; Don't need to set the default path unless you already removed it :) ;; (strcat (getenv "appdata") "\\Autodesk\\C3D 2018\\enu\\Support\\ToolPalette") "I:\\_CAD STANDARDS\\100 - CAD SUPPORT FILES\\200 - SUPPLEMENTARY FILES\\TOOL PALETTE" ) ) Edited February 24, 2020 by ronjonp 1 Quote
Sportyyyy Posted February 24, 2020 Posted February 24, 2020 3 minutes ago, ronjonp said: I updated the code since then. (defun _addtoolpalettepaths (paths / a b) (setq b (getvar (setq a "*_toolpalettepath"))) (setvar a (strcat b (apply 'strcat (mapcar '(lambda (x) (if (vl-string-search (strcase x) (strcase b)) "" (strcat ";" x) ) ) paths ) ) ) ) ) ;; usage (_addtoolpalettepaths "C:\\Users\\" (getenv"Username") "\\AppData\\Roaming\\Autodesk\\C3D 2018\\enu\\Support\\ToolPalette\\" "I:\\_CAD STANDARDS\\100 - CAD SUPPORT FILES\\200 - SUPPLEMENTARY FILES\\TOOL PALETTE")) Returns an error: Too many arguments. Is there a reason to use this over VLA? Does it preserve OOTB Tool Palette Groups? This appears to be the nearly same as the one I have above?: (setvar "*_toolpalettepath" (strcat "C:\\Users\\" (getenv"Username") "\\AppData\\Roaming\\Autodesk\\C3D 2018\\enu\\Support\\ToolPalette\\" (chr 59) "I:\\_CAD STANDARDS\\100 - CAD SUPPORT FILES\\200 - SUPPLEMENTARY FILES\\TOOL PALETTES")) Quote
rlx Posted February 24, 2020 Posted February 24, 2020 (defun _addtoolpalettepaths (paths) (setvar "*_toolpalettepath" (strcat (getvar "*_toolpalettepath") (apply 'strcat (mapcar '(lambda (x) (strcat ";" x)) paths))))) ;; usage (_addtoolpalettepaths (list "c:\\path1" "d:\\path2")) Quote
Sportyyyy Posted February 24, 2020 Posted February 24, 2020 (edited) 13 minutes ago, rlx said: (defun _addtoolpalettepaths (paths) (setvar "*_toolpalettepath" (strcat (getvar "*_toolpalettepath") (apply 'strcat (mapcar '(lambda (x) (strcat ";" x)) paths))))) ;; usage (_addtoolpalettepaths (list "c:\\path1" "d:\\path2")) That added a bunch of things that don't need to be there (see screenshot, I think the list parameter messed it up because of the (getusername)?). Why would I want to run the code above over this: (setvar "*_toolpalettepath" (strcat "C:\\Users\\" (getenv"Username") "\\AppData\\Roaming\\Autodesk\\C3D 2018\\enu\\Support\\ToolPalette\\" (chr 59) "I:\\_CAD STANDARDS\\100 - CAD SUPPORT FILES\\200 - SUPPLEMENTARY FILES\\TOOL PALETTES")) Edited February 24, 2020 by Sportyyyy wrong pic Quote
rlx Posted February 24, 2020 Posted February 24, 2020 the code ronjonp made is just an example on how to append multiple paths to the existing one. If you run it multiple times it will append multiple times. In this case indeed you would need to check if the path was already added or not. The last code you posted creates a new one (resets) that's made up from 2 paths only C:\Users... + I:\_CAD... , so this you can run as much a you like. Don't know why the vla-code doesn't work for you because on my computer nos problemos?? 1 Quote
ronjonp Posted February 24, 2020 Posted February 24, 2020 (edited) 1 hour ago, Sportyyyy said: Does it preserve OOTB Tool Palette Groups? The last code I posted does. Don't use that short snippet. Use the example HERE as a base. Edited February 24, 2020 by ronjonp 1 Quote
dlanorh Posted February 24, 2020 Posted February 24, 2020 17 hours ago, Sportyyyy said: I don't want to be a command. I want it to run automatically at startup (I'd like to add it to my acad.lsp). When I manually load it, it says it loaded successfully but the new path isn't added in the Options window, only the default/OOTB path shows. Am I supposed to remove the ";" from (vla-put-toolPalettePath pFiles (strcat tpPaths ";" tpPath)) ;;add your new path to the string dividing paths with a ";" does the instructions to "add your new path to the string diving paths with a ";" " mean that if I wanted to add additional paths, I'd define a new variable name (setq), and add to the list up top (i.e. after the tpPath in: (defun C:TPPATH (/ pFiles tpPaths tpPath) Asking because I'm curious/want to make sure I understand. I don't actually need a third TP path. Appreciate your help! You only need to run this once as the file paths are stored in the registry. If you add it to your acad.lsp file it will add another duplicate line to the setting every time your acad.lsp runs. (vla-put-toolPalettePath pFiles (strcat tpPaths ";" tpPath)) ;;add your new path to the string dividing paths with a ";" The comment to this line means that you must separate individual paths using a semi-colon. The function does this automatically for a single path but if you want to feed it a string of more than one path the individual paths within the string must be separated using a semi-colon 1 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.