pmxcad Posted March 15, 2019 Share Posted March 15, 2019 Hello, I have a lisp to get the corner coordinates of a rectangle. But with this lisp you have to select the object. How can I replace the entsel with (ssget "X" '((0. "LWPOLYLINE")) to directly select the object. (defun C:test () (if (and (setq ENT (car (entsel "\n Select Rectangle: "))) (if (and (setq ENT (car (ssname ss indx))) (eq (cdadr (setq ELST (entget ent))) "LWPOLYLINE")) (progn (foreach item ELST (if (eq (car item) 10) (setq pts (cons (cdr item) PTS)))) (setq RB (car PTS)) (setq LO (caddr PTS)) (setq RO (cadr PTS)) (setq LO (last PTS)) )) (princ) );defun thank you in advance Jaap Quote Link to comment Share on other sites More sharing options...
dlanorh Posted March 15, 2019 Share Posted March 15, 2019 (edited) I'm not sure exactly what you want but this snippet will return the four corners in a list. (defun C:test ( / ss c_lst) ;This allows a single selection (like entsel) of a lwpolyline (setq ss (ssget "_+.:E:S" '((0 . "LWPOLYLINE")))) ; this returns the coords in c_lst if a lwpolyline entity is selected (if ss (setq c_lst (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (ssname ss 0)))))) (princ) );defun Edited March 15, 2019 by dlanorh Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted March 15, 2019 Share Posted March 15, 2019 (edited) (defun c:test ( / ss rec pl d1 d2 d3 d4 ) (if (setq ss (ssget "_X" (list '(0 . "LWPOLYLINE") '(90 . 4) '(-4 . "&=") '(70 . 1) '(-4 . "<not") '(-4 . "<>") '(42 . 0.0) '(-4 . "not>") (cons 410 (getvar 'ctab))))) (setq rec (ssname ss 0)) ) (if rec (progn (setq pl (mapcar 'cdr (vl-remove-if '(lambda ( x ) (/= (car x) 10)) (entget rec)))) (setq d1 (distance (car pl) (cadr pl))) (setq d2 (distance (cadr pl) (caddr pl))) (setq d3 (distance (nth 2 pl) (nth 3 pl))) (setq d4 (distance (nth 3 pl) (car pl))) (if (and (equal d1 d3 1e-6) (equal d2 d4 1e-6) (equal (abs (rem (+ pi pi (- (angle (cadr pl) (caddr pl)) (angle (car pl) (cadr pl)))) (+ pi pi))) (* 0.5 pi) 1e-6)) (progn (prompt "\nSearched LWPOLYLINE is RECTANGLE with points : ") (princ pl) (sssetfirst nil (ssadd rec)) ) ) ) ) (princ) ) Edited March 16, 2019 by marko_ribar Quote Link to comment Share on other sites More sharing options...
pmxcad Posted March 15, 2019 Author Share Posted March 15, 2019 dlanorh, thanks for your feedback, i didn't want to select it manually. marko_ribar, thank you also for your feedback. Your lisp works perfectly the way I wanted it. Thank you both for your time, Jaap Quote Link to comment Share on other sites More sharing options...
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.