Lisp to create center line of longer side of rectangle

Lisp to create center line of longer side of rectangle

inaamazmi
Enthusiast Enthusiast
596 Views
2 Replies
Message 1 of 3

Lisp to create center line of longer side of rectangle

inaamazmi
Enthusiast
Enthusiast

I need a lisp that can create center line of longer side of rectangle

0 Likes
Accepted solutions (1)
597 Views
2 Replies
Replies (2)
Message 2 of 3

phanaem
Collaborator
Collaborator
Accepted solution

CENTERLINE command will do that, but you have to pick the sides of each rectangle, one by one.

 

This lisp will process multiple rectangles at once. It will not check for true rectangles, but it works only with 4 points, closed polylines.

(defun c:clrec ( / *error* ss i pts d1 d2)
  (vl-load-com)
  (setq acobj (vlax-get-acad-object)
        acdoc (vla-get-activedocument acobj))

  
  (if
    (= 8 (logand (getvar 'undoctl) 8))
    (vla-endundomark acdoc)
  )
  (vla-startundomark acdoc)

  (defun *error* (msg)
    (and msg
      (not (wcmatch (strcase msg) "*CANCEL*,*QUIT*,*BREAK*,*EXIT*"))
      (princ (strcat "\nError: " msg))
    )
    (if
      (= 8 (logand (getvar 'undoctl) 8))
      (vla-endundomark acdoc)
    )
    (princ)
  )
  
  (if
    (setq ss (ssget '((0 . "LWPOLYLINE") (90 . 4) (-4 . "&") (70 . 1))))
    (repeat (setq i (sslength ss))
      (setq e (ssname ss (setq i (1- i)))
            pts (mapcar '(lambda (x) (vlax-curve-getpointatparam e x)) '(0.5 2.5 1.5 3.5))
            d1 (distance (car pts) (cadr pts))
            d2 (distance (caddr pts) (cadddr pts))
      )
      (entmakex
        (list
          '(0 . "LINE")
          (cons 10 (if (< d1 d2) (caddr pts) (car pts)))
          (cons 11 (if (< d1 d2) (cadddr pts) (cadr pts)))
        )
      )
    )
  )
  (*error* nil)
  (princ)
)

 

0 Likes
Message 3 of 3

inaamazmi
Enthusiast
Enthusiast

wow...thank you ..its working

0 Likes