LISP2LEARN Posted May 2, 2012 Posted May 2, 2012 I got this code from Lee a while back it works perfectly but I need to make a little adjustment and I don't know how to. I can understand the code but modifying it is quite a task for me. All I need is: if block is named "Block1" put the line on layer on "Layer1", "Block2" to layer "Layer2". Thanks again. ;;;by lee-mac ;;nearest point on a line (defun c:test ( / d1 d2 el en in l1 l2 p2 p3 ss ) (if (setq ss (ssget '((0 . "INSERT,LINE")))) (progn (repeat (setq in (sslength ss)) (setq en (ssname ss (setq in (1- in))) el (entget en) ) (if (eq "LINE" (cdr (assoc 0 el))) (setq l1 (cons en l1)) (setq l2 (cons (trans (cdr (assoc 10 el)) en 0) l2)) ) ) (foreach p1 l2 (setq p2 (vlax-curve-getclosestpointto (car l1) p1) d1 (distance p1 p2) ) (foreach en (cdr l1) (setq p3 (vlax-curve-getclosestpointto en p1) d2 (distance p1 p3) ) (if (< d2 d1) (setq d1 d2 p2 p3)) ) (entmake (list '(0 . "LINE") (cons 10 p1) (cons 11 p2))) ) ) ) (princ) ) (vl-load-com) (princ) Quote
BIGAL Posted May 2, 2012 Posted May 2, 2012 Not exact but gives the idea you need a "if a block" and use assoc 2 = block name (if (eq "LINE" (cdr (assoc 0 el))) (setq l1 (cons en l1)) (if (eq "INSERT" (cdr (assoc 0 el))) (setq blockname (cdr (assoc 2 el))) then you need to find out block "2" so can do a (setvar "clayer" "layer2") ) You need a end of text as numbers 01 etc lisp do it as a defun in main code I need this also Lee I think has a routine for this. Quote
Lee Mac Posted May 2, 2012 Posted May 2, 2012 A little tweak: ;; Nearest point on a line - Lee Mac (defun c:test ( / d1 d2 el en in l1 l2 la p2 p3 ss ) (if (setq ss (ssget '((0 . "INSERT,LINE")))) (progn (repeat (setq in (sslength ss)) (setq en (ssname ss (setq in (1- in))) el (entget en) ) (if (eq "LINE" (cdr (assoc 0 el))) (setq l1 (cons en l1)) (setq l2 (cons (list (trans (cdr (assoc 10 el)) en 0) (cdr (assoc 2 el))) l2)) ) ) (foreach p1 l2 (setq la (cadr p1) p1 (car p1) p2 (vlax-curve-getclosestpointto (car l1) p1) d1 (distance p1 p2) ) (foreach en (cdr l1) (setq p3 (vlax-curve-getclosestpointto en p1) d2 (distance p1 p3) ) (if (< d2 d1) (setq d1 d2 p2 p3)) ) (entmake (list '(0 . "LINE") (cons 8 (vl-string-subst "Layer" "Block" la)) (cons 10 p1) (cons 11 p2) ) ) ) ) ) (princ) ) (vl-load-com) (princ) Quote
LISP2LEARN Posted May 2, 2012 Author Posted May 2, 2012 Great! Works perfectly. Thanks again Bigal & Lee. A little tweak: ;; Nearest point on a line - Lee Mac (defun c:test ( / d1 d2 el en in l1 l2 la p2 p3 ss ) (if (setq ss (ssget '((0 . "INSERT,LINE")))) (progn (repeat (setq in (sslength ss)) (setq en (ssname ss (setq in (1- in))) el (entget en) ) (if (eq "LINE" (cdr (assoc 0 el))) (setq l1 (cons en l1)) (setq l2 (cons (list (trans (cdr (assoc 10 el)) en 0) (cdr (assoc 2 el))) l2)) ) ) (foreach p1 l2 (setq la (cadr p1) p1 (car p1) p2 (vlax-curve-getclosestpointto (car l1) p1) d1 (distance p1 p2) ) (foreach en (cdr l1) (setq p3 (vlax-curve-getclosestpointto en p1) d2 (distance p1 p3) ) (if (< d2 d1) (setq d1 d2 p2 p3)) ) (entmake (list '(0 . "LINE") (cons 8 (vl-string-subst "Layer" "Block" la)) (cons 10 p1) (cons 11 p2) ) ) ) ) ) (princ) ) (vl-load-com) (princ) Quote
Lee Mac Posted May 2, 2012 Posted May 2, 2012 You're very welcome LISP2LEARN, I hope my modifications are clear Quote
LISP2LEARN Posted May 2, 2012 Author Posted May 2, 2012 Yes, it's clear. I can understand your code but I think that I can't code something like that in the near future or probably never. Dissecting your codes for me is the best way to learn lisp. Thanks Lee. You're very welcome LISP2LEARN, I hope my modifications are clear Quote
Lee Mac Posted May 2, 2012 Posted May 2, 2012 but I think that I can't code something like that in the near future or probably never Never say never! You never know what you are capable of! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.