SELFCAD Posted February 6, 2012 Posted February 6, 2012 Hi Guys, I try to make a lisp to draw lines from a start point, pstart, to the closest point, and so on.... till the last poit of selection - but is not working. Maybe somebody will help me to debug my code? Thanks! (defun c:pol (/ Pdata Pordata) (setq pstart (getpoint "\nPunct start:")) (setq ss (ssget '((0 . "point")))) (repeat (- (sslength ss) 1) (repeat (setq i (sslength ss)) (setq e (entget (ssname ss (setq i (1- i)))) Pdata (cons (list (setq p (cdr (assoc 10 e))) (setq dist (distance pstart (cdr (assoc 10 e)) ) ) ) Pdata ) ) ) (setq Pordata (cdr (vl-sort Pdata (function (lambda (e1 e2) (< (cadr e1) (cadr e2)) ) ) ) ) ) (command "_.line" pstart (car (car pordata)) "") (setq Pordata (cdr Pordata)) (setq pstart (car (car pordata))) (ssdel (ssname ss 0) ss) ) ) Quote
SELFCAD Posted February 6, 2012 Author Posted February 6, 2012 How can i remove a point from a selection set, if i know coordinates of this point? Quote
Stefan BMR Posted February 6, 2012 Posted February 6, 2012 You can create a list of points and work on that list, not in the selection set each time. This is my try: (defun C:TEST ( / ss_first ss_rest e1 i lst p1) (if (and (princ "\nSelect first point") (setq ss_first (ssget ":E:S" '((0 . "POINT")))) (princ "\nSelect the others points") (setq ss_rest (ssget '((0 . "POINT")))) ) (progn (ssdel (setq e1 (ssname ss_first 0)) ss_rest) (setq p1 (cdr (assoc 10 (entget e1)))) (repeat (setq i (sslength ss_rest)) (setq lst (cons (cdr (assoc 10 (entget (ssname ss_rest (setq i (1- i)))))) lst)) ) (while lst (entmake (list '(0 . "LINE") (cons 10 p1) (cons 11 (setq p1 (car (setq lst (vl-sort lst '(lambda (x y) (< (distance x p1) (distance y p1)))))))) ) ) (setq lst (cdr lst)) ) ) ) (princ) ) Quote
SELFCAD Posted February 6, 2012 Author Posted February 6, 2012 Thanks Stefan, you are my angel! Quote
marko_ribar Posted February 6, 2012 Posted February 6, 2012 (edited) Here is my try : (defun pointsarray ( ptst ptl / dptpt dptptlst mindptpt pten ptl ) (foreach pt ptl (setq dptpt (distance ptst pt)) (setq dptptlst (cons dptpt dptptlst)) ) (setq dptptlst (vl-remove 0.0 dptptlst)) (setq mindptpt (eval (cons 'min dptptlst))) (mapcar '(lambda (pt) (if (= (distance ptst pt) mindptpt) (setq pten pt))) ptl) (setq ptlst (cons ptst ptlst)) (setq ptl (vl-remove ptst ptl)) (if (not (null ptl)) (pointsarray pten ptl) ) ptlst ) (defun c:pts2lines ( / ss ssn pt ptl ptst ptlst ) (prompt "\nSelect points that you want to connect them with lines") (setq ss (ssget '((0 . "POINT") (210 0.0 0.0 1.0)) )) (setq ssn (sslength ss) i ssn) (repeat ssn (setq pt (cdr (assoc 10 (entget (ssname ss (setq i (1- i))))))) (setq ptl (cons pt ptl)) ) (setq ptl (reverse ptl)) (vl-cmdf "_.OSNAP" "node") (setq ptst (getpoint "\nPick start point from witch to create continous array of lines obtained from rest of selected points")) (setq ptlst (pointsarray ptst ptl)) (vl-cmdf "_.LINE") (foreach pt ptlst (vl-cmdf pt) ) (vl-cmdf "") (princ) ) M.R. P.S. Stefan's code is better, my is limited on 256 points... Edited February 6, 2012 by marko_ribar P.S. Quote
SELFCAD Posted February 8, 2012 Author Posted February 8, 2012 How can i define these points p1, p2 ... pn, in this way: (setq p1 (polar (nth 0 Pdata) (nth 0 Udata) (nth 0 Ddata))) (setq p2 (polar p1 (nth 1 Udata) (nth 1 Ddata))) (setq p3 (polar p2 (nth 2 Udata) (nth 2 Ddata))) ... ... (setq pn (polar p(n-1) (nth (- n 1) Udata) (nth (- n 1) Ddata))) Pdata, Udata, Ddata - lists Quote
Stefan BMR Posted February 8, 2012 Posted February 8, 2012 So you have a variable number of points.. It is better to store your points in a list, like this: (mapcar '(lambda (u d) (setq p (polar (if p p (car Pdata)) u d))) Udata Ddata) Quote
Stefan BMR Posted February 8, 2012 Posted February 8, 2012 Take care of p variable. If it is not nil before calling (mapcar... then you may get an error. Maybe: (defun test (Pdata Udata Ddata / p) (setq p (car Pdata)) (mapcar '(lambda (u d) (setq p (polar p u d))) Udata Ddata) ) (setq lst (test Pdata Udata Ddata)) Quote
Stefan BMR Posted February 8, 2012 Posted February 8, 2012 Or this ((lambda (p u d) (mapcar '(lambda (u d) (setq p (polar p u d))) u d)) (car Pdata) Udata Ddata) 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.