Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Support Path Placement

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
304 Views, 3 Replies

Support Path Placement

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
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: Anonymous

Maybe there's something to be gained from the following (credits are noted)...
Oops.. forgot to include Tony's (strlcat) which is needed.

;;Taking the best from Luis and Marc'Antonio, plus acknowledgments to Eric
;;Schneider, I now offer the following...
(defun @cv_str2list (str pat / i j n lst)
(cond
((/= (type str)(type pat) 'STR))
((= str pat)'(""))
(T
(setq i 0 n (strlen pat))
(while (setq j (vl-string-search pat str i))
(setq lst (cons (substr str (1+ i)(- j i)) lst)
i (+ j n)
)
)
(reverse (cons (substr str (1+ i)) lst))
)
)
)
;; Tony Tanzillo (01-25-02)
(defun remove-at (lst pos / head)
(repeat pos
(setq head (cons (car lst) head)
lst (cdr lst)
)
)
(append (reverse head) (cdr lst))
)
;;-----------------------------------------------------------------------
;; John's "New and Improved" nthadd (09-18-01) using Herman's approach of
;; repeat instead of horrendously slow append:
;; data = list being inflated
;; item = item (or list of items) to add to data
;; n = 'INT position in data list to add item (zero counter)
;; multiple = 1 = item is a list; add each element
;; = nil = add item as is
;; incorporated with multiple option (09-28-01)
(defun @nthadd (data item n multiple / len head)
(if (and (listp data)(setq len (vl-list-length data))(= (type n) 'INT)(>= n
0))
(progn
(setq n (min n len))
(repeat n
(setq head (cons (car data) head)
data (cdr data)
)
)
(if (and multiple (listp item)(vl-list-length item))
(foreach element (reverse item)(setq data (cons element data)))
(setq data (cons item data))
)
(repeat n
(setq data (cons (car head) data)
head (cdr head)
)
)
data
)
)
)
;;-------------------------------------
;; Created for Jason Piercey (07-09-02)
;;
(defun add_path (path pos / altpath prefs files spath plist caplist xpos)
(and
(= (type path) 'STR)
(setq path (vl-string-translate "/" "\\" path))
(setq altpath
(if (wcmatch path "*\\")
(substr path 1 (1- (strlen path)))
(strcat path "\\")
)
)
(or *acad* (setq *acad* (vlax-get-acad-object)))
(setq prefs (vla-get-preferences *acad*))
(setq files (vla-get-files prefs))
(setq spath (vla-get-SupportPath files))
(setq plist (@cv_str2list spath ";"))
(setq caplist
(mapcar
(function
(lambda (x)
(vl-string-translate "/" "\\" (strcase x))
)
)
plist
)
)
(or
(setq xpos (vl-position (strcase path) caplist))
(setq xpos (vl-position (strcase altpath) caplist))
T
)
(or
(= xpos pos)
(and xpos
(setq plist (@nthadd (remove-at plist xpos) path pos nil))
)
(setq plist (@nthadd plist path pos nil))
)
(not
(vla-put-SupportPath files
(strlcat ";" plist)
)
)
)
)

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"Jason Piercey" wrote in message
news:30A2CF599FE7D5924E791FAF7AA5B48E@in.WebX.maYIadrTaRb...
> 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?
Message 3 of 4
Anonymous
in reply to: Anonymous

Thanks John, seems to work well. I did notice that with (add_path) if 'pos'
is passed as nil the path is not added yet T is returned. If you wanted to
append a path then I suppose you just have to find out how many paths are
there first (no big deal). Now, back to the function I wrote, any ideas on
why the path gets moved up but not down (if it already exists)?

--
-Jason

Member of the Autodesk Discussion Forum Moderator Program


> Maybe there's something to be gained from the following (credits are
noted)...
Message 4 of 4
Anonymous
in reply to: Anonymous

Jason:

1. I forgot to add two tests within the big (and) ... (= (type pos) 'INT)(>=
pos 0)
2. Your approach doesn't delete the path if it exists, so you're probably
ending up with two of the same in your list and (vla-put-supportpath) is keeping
the first one it finds while ignoring the second. That's why I used Tony's
(remove-at).

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ


"Jason Piercey" wrote in message
news:C864803B812F8E54AE97ED973F9F2A24@in.WebX.maYIadrTaRb...
> Thanks John, seems to work well. I did notice that with (add_path) if 'pos'
> is passed as nil the path is not added yet T is returned. If you wanted to
> append a path then I suppose you just have to find out how many paths are
> there first (no big deal). Now, back to the function I wrote, any ideas on
> why the path gets moved up but not down (if it already exists)?
>
> --
> -Jason
>
> Member of the Autodesk Discussion Forum Moderator Program
>
>
> > Maybe there's something to be gained from the following (credits are
> noted)...
>
>
>

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost