I am finally working on setting up some "Add support paths" routines. I
have seen some other threads here recently that use (setenv) and (getenv)
rather than the vla approach, is there a specific reason for that?
Simplicity?
Anyway, I thought I'd try out the vla way just for the practice of using vla
functions and have ran across this weird little thing....it seems that
(JRP:PutSupportPath) will add a support path if it doesn't exist (fine and
dandy) but if it does exist and the specified position to insert the path is
GREATER than the current position it doesn't do anything however, if the
specified position is LESS than the current position then the path is moved
to the new location. Why?
(setq *JRP:Acad* (vlax-get-acad-object))
;By Cliff Middleton
;TXT:BREAK-AT-DELIM
;Converts string to list of string phrases
;Arguments 1) Delimeter string 2) Text string
;Returns: List of strings
;Note: Test for instances of delimeter is case sensitive
(defun Txt:Break-At-Delim (delimeter string / dlen start-pos del-pos phrase
return)
(setq dlen (strlen delimeter)
start-pos 0
)
(while (setq del-pos (vl-string-search delimeter string start-pos))
(setq phrase (substr string (1+ start-pos) (- del-pos start-pos))
return (cons phrase return)
start-pos (+ del-pos dlen)
)
)
(if (/= "" (setq phrase (substr string (1+ start-pos))))
(reverse (cons phrase return))
(reverse return)
)
)
; Return: list of strings
(defun JRP:GetSupportPaths ()
(Txt:Break-at-delim
";"
(vla-get-supportpath
(vla-get-files
(vla-get-preferences
*JRP:Acad*
)
)
)
)
)
; Tony Tanzillo
; strcat a list of strings seperated by a delimiter
; delim: string to be used as a delimiter
; lst: list of string to strcat
; Notes by me, not Tony.
(defun strlcat (delim lst)
(apply
'strcat
(cons
(car lst)
(mapcar
'(lambda (x)
(strcat delim x)
)
(cdr lst)
)
)
)
)
; Modified from Puckett's RemoveNth
; Probably not the best approach but it works, suggestions?
; e = add what
; lst = add to what list
; n = position to add (zero based!)
(defun JRP:AddNth ( e Lst n / Len i Rtn )
(setq Len (length Lst))
(cond ((>= n Len) (append Lst (list e)))
((and (not (minusp n)) (< n Len))
(reverse
(progn
(setq i -1)
(foreach x Lst
(if (= n (setq i (1+ i)))
(setq Rtn (cons e Rtn)
Rtn (cons x Rtn)
)
(setq Rtn (cons x Rtn))
)
)
Rtn
)
)
)
)
)
; Path: string, path to add
; Pos : integer, placement of 'path' (0 based)
(defun JRP:PutSupportPath (Path Pos / Paths)
(setq Paths (JRP:GetSupportPaths))
(if (not Pos) (setq Pos (length Paths)))
(setq Paths (JRP:AddNth Path Paths Pos)
Paths (strlcat ";" Paths)
)
(vla-put-supportpath
(vla-get-files
(vla-get-preferences *JRP:Acad*)
)
Paths
)
)
--
-Jason
Member of the Autodesk Discussion Forum Moderator Program