@Anonymous wrote:
.... I need to cut like this but the current line will be changed to different layer name (my layer name is color1) and the 2 shorter lines that have been cut will be remained (5mm or any value input) with different layer name (color2).
....
Assuming the Layers already exist:
(vl-load-com)
(defun C:ENDS (/ ss n ent len)
(initget (if *endslen* 6 7)); no zero, no negative, no Enter on first use
(setq *endslen* ; global variable
(cond
( (getdist ; User input
(strcat
"\nLength of end portions to retain"
(if *endslen* (strcat " <" (rtos *endslen*) ">") "")
": "
); strcat
); getdist
); User input condition
(*endslen*); on Enter [when allowed]: previous value
); cond
); setq
(if (setq ss (ssget '((0 . "*LINE,ARC,CIRCLE,ELLIPSE"))))
(repeat (setq n (sslength ss))
(setq ent (ssname ss (setq n (1- n))))
(if
(and
(not (wcmatch (cdr (assoc 0 (entget ent))) "XLINE,MLINE"))
;; [inapplicable types accepted by *LINE in (ssget)]
(>= ; long enough
(setq len (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent)))
(* *endslen* 2)
); >=
); and
(command
"_.copy" ent "" "0,0" "0,0" ; in place
"_.chprop" "_last" "" "_layer" "color1" ""
"_.chprop" ent "" "_layer" "color2" ""
"_.break" ent ; giving only entity name goes into First mode
"_none" (vlax-curve-getPointAtDist ent *endslen*)
"_none" (vlax-curve-getPointAtDist ent (- len *endslen*))
); command
); if
); repeat
); if
(princ)
); defun
Kent Cooper, AIA