Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I need a lisp that can create center line of longer side of rectangle
Solved! Go to Solution.
I need a lisp that can create center line of longer side of rectangle
Solved! Go to 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)
)