Correct the old lisp for new one (Cut lines)

Correct the old lisp for new one (Cut lines)

Anonymous
Not applicable
803 Views
5 Replies
Message 1 of 6

Correct the old lisp for new one (Cut lines)

Anonymous
Not applicable

Dear all,

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/a-lisp-to-trim-a-line-into-2-shorter...


I found the link above for cut a line into 2 shorter lines. 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). 

The attached file is my sample test. It would be great if anybody can helped me to solve this problem.

Thank you,
Mozart

0 Likes
Accepted solutions (1)
804 Views
5 Replies
Replies (5)
Message 2 of 6

devitg
Advisor
Advisor

@Anonymous  as per your DWG blue line are over the yellow lines . , yellow line keep it size 

 

Please clear it.

 

0 Likes
Message 3 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

@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
Message 4 of 6

Anonymous
Not applicable

Thank you so much for your support! It solved my problem!

0 Likes
Message 5 of 6

Anonymous
Not applicable
Thank you so much for your support! It solved my problem!
0 Likes
Message 6 of 6

Anonymous
Not applicable

@devitg Thank you for yourhelp. @Kent1Cooper solved my problem!

0 Likes