I like that.
most do, most won't admit it tho
I want to swap endpoints for a line, ent1:
(subst (cons 10 (cdr (assoc 11 ent1))) ent1)
and
(subst (cons 11 (cdr (assoc 10 ent1))) ent1)
but thought I would use a dummy variable to store the first while I overwrite it with the second.
boy, that was as clear as mud.
what I guess I ought to do is bite the bullet and (entdel (car (assoc -1 ent1))) and then
(entmake (list ( '(0 . "LINE")......(cons 10 (cdr (assoc 11 ent1))) (cons 11 (cdr (assoc 10 ent1)))...)
If I understand your need, a simplistic solution:
(defun _SwapEndpoints ( line_ename )
(entmod
(mapcar
(function
(lambda ( pair / key val )
(cond
((eq 10 (setq val (cdr pair) key (car pair))) (cons 11 val))
((eq 11 key) (cons 10 val))
(pair)
)
)
)
(entget line_ename)
)
)
)
I use this to 'permute' the values of two variables:
(defun _permute ( *a *b / c )
(setq c (eval *a))
(set *a (eval *b))
(set *b c)
)
Requires quoted symbols, for example:
_$ (setq a 10 b 15)
_$ (_permute 'a 'b)
_$ a
15
_$ b
10
Why the asterisks? Because the quoted symbols cannot match the symbols used as arguments for the subfunction and using asterisks decreases this risk.
Good stuff Lee but it requires the caller knows about
_permute's implementation, i.e. the caller cannot pass a var named
c, lest he not get what he expects. Probably better to name the local something like
local_temp_variable to reduce the chance of a name collision. Having said that I'm still not an advocate of the use of set in this context as it can lead to woes for anyone trouble shooting the code down the road, particularity for those that didn't author the code originally.
This operation always reminds me of indirect addressing - a mind-boggling concept in itself.
My HP-41CX relied heavily on indirect addressing for its programming, loved that thing.