How can I insert the "S:\\" (the USB path) to the SFSP as the 2nd item in the list?
For your request that can be added to your startup method of choice (ex. acaddoc.lsp)
Look at the last function call. That is the one that needs to be changed to suite your needs.
(putsupportpath "S:\\" 1)
It says position 1, but it is an index position, like an array. So index 1 is actually 2, where index 0 is 1, etc.
(vl-load-com)
;;function to accept a deliminated string <str> and the deliminator <delim>, and return a list of strings
(defun vl:string->list (str delim / lst loc)
(while (setq loc (vl-string-search delim str))
(setq lst (append lst (list (substr str 1 loc)))
str (substr str (1+ (+ loc (strlen delim)))))
)
(append lst (list str))
)
;;function to accept a list of strings <ls> and return a string deliminated by a deliminator <delim>
(defun vl:list->string (delim ls / out)
(setq out (apply 'strcat (mapcar (function (lambda (x) (strcat x delim))) ls)))
(if out (vl-string-right-trim delim out))
)
;;function to add a list item <newitem> to an existing list <alist> at <position>
(defun vl:nth-add (newitem alist position / i p)
(setq i -1 p -1)
(append (vl-remove-if (function (lambda (x) (<= position (setq p (1+ p))))) alist)
(list newitem)
(vl-remove-if (function (lambda (x) (> position (setq i (1+ i))))) alist)
)
)
;;function to return support paths as a list of strings
(defun getSupportPaths (/ )
(vl:string->list (vla-get-supportpath (vla-get-files (vla-get-preferences (vlax-get-acad-object)))) ";")
)
;;function to accept a list of support path strings, and apply them to the search path preferences
(defun setSupportPaths (pathlst /)
(vla-put-supportpath
(vla-get-files (vla-get-preferences (vlax-get-acad-object)))
(vl:list->string ";" pathlst)
)
)
;;main wrapper function to accept a path and desired hierachal location in the search path list.
;;if pathing already exists, then it will be relocated to new location.
(defun putSupportpath (newPath loc / paths)
;remove if found, so we can place in location where it needs to be
(setq paths (vl-remove (strcase newPath) (mapcar 'strcase (getsupportpaths))))
(setSupportPaths (vl:nth-add newPath paths loc))
)
;;call the main wrapper with required vars
;;function: putsupportpath <pathing> <index location>
(putsupportpath "S:\\" 1)
(princ)