Jump to content

entsel to ssget


pmxcad

Recommended Posts

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

 

Link to comment
Share on other sites

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 by dlanorh
Link to comment
Share on other sites

(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 by marko_ribar
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...