@ВeekeeCZ wrote:
....
....
(setq ....
....
ed (subst (cons 10 (polar p1 (angle p2 p1) 100.))
(assoc 10 ed)
ed)
ed (subst (cons 11 (polar p2 (angle p1 p2) 100.))
(assoc 11 ed)
ed))
(entmod ed)....
Here's an interesting factoid I picked up somewhere a while back: Instead of (subst)ituting 10- and 11-code entries into the entity data in place of the current ones, you can simply tack them onto the end, leaving the older ones in the list, and the later/newer ones will override the earlier/older ones! So the above-quoted parts, which revise the entity data list twice to make the two substitutions and then (entmod) the result, can be replaced by this:
(entmod
(append
ed
(list
(cons 10 (polar p1 (angle p2 p1) 100))
(cons 11 (polar p2 (angle p1 p2) 100))
); list
); append
); entmod
[By the way, the decimal points can be used on the 100's if you want, but are not needed -- they accomplish nothing in this situation.]
Another thing that can be done [made easier by (ssget)'s "_X" mode -- it's slightly more complicated if User selection is involved], is to convert the selection set to a list of entity names, and use (foreach) on that list, eliminating the need for an incrementing variable in a (repeat) function. And it also occurred to me to try doing it by SCALE-ing each Line about its midpoint, rather than changing endpoint locations, which can accomplish it with a little less code:
(defun C:LBE100 (/ ss edata p1 p2 len); = Lengthen Both Ends by 100 units
(if (setq ss (ssget "_X" '((0 . "LINE") (8 . "bolt_axis"))))
(foreach lin (mapcar 'cadr (ssnamex ss)); then
(setq
edata (entget lin)
p1 (cdr (assoc 10 edata))
p2 (cdr (assoc 11 edata))
len (distance p1 p2)
); setq
(command "_.scale" lin "" "_mtp" p1 p2 (/ (+ len 200) len)); by ratio of new length to old
); foreach
(prompt "\nNo lines on 'bolt_axis' layer in the drawing."); else
); if
(princ)
); defun
However, that won't work on any Lines that are not in the current space, so if multiple spaces are possible, the (entmod) approach should be used.
Those with old-enough versions that they don't have the MTP/M2P Osnap mode can replace this part:
"_mtp" p1 p2
with this to find the Line's midpoint:
"_none" (mapcar '/ (mapcar '+ p1 p2) '(2 2 2))
Kent Cooper, AIA